PHP - Undefined Variable: Pdo
Hi guys.
why is my function error: undefined varable pdo?
Thanks
function referralCount($uid,$reflvl) { $stmt= $pdo->query("SELECT * FROM scraffiliateusr WHERE usrinvby='$uid'"); $nusrref1 = $stmt->rowCount(); //$arrusrref1 = $stmt->fetch(PDO::FETCH_LAZY); $reflvl1=$nusrref1; $ttlreflvl2="0"; $ttlreflvl3="0"; for ($i=0; $i<$nusrref1; $i++) { $arrusrref1 = $stmt->fetch(PDO::FETCH_LAZY); $stmt= $pdo->query("SELECT * FROM scraffiliateusr WHERE usrinvby='$arrusrref1[0]'"); $nusrref2 = $stmt->rowCount(); //$arrusrref2 = $stmt->fetch(PDO::FETCH_LAZY); $ttlreflvl2=$ttlreflvl2+$nusrref2; for ($j=0; $j<$nusrref2; $j++) { $arrusrref2 = $stmt->fetch(PDO::FETCH_LAZY); $stmt= $pdo->query("SELECT * FROM scraffiliateusr WHERE usrinvby='$arrusrref2[0]'"); $nusrref3 = $stmt->rowCount(); //$arrusrref3 = $stmt->fetch(PDO::FETCH_LAZY); $ttlreflvl3=$ttlreflvl3+$nusrref3; } } $reflvl2=$ttlreflvl2; $reflvl3=$ttlreflvl3; if($reflvl=='1') { return($reflvl1); } elseif($reflvl=='2') { return($reflvl2); } elseif($reflvl=='3') { return($reflvl3); } } Similar TutorialsHello, I have just upgraded my wampserver and with it MySQL, PHP and PhpMyAdmin versions. And my scripts, which ran normally before, not burst hundreds of undefined variable and undefined index notices. I realize it's "notices", not "errors" but this is quite irritating. I believe it might be due to some upgrade in PHP scripting rules or something but I don't know what. I hope you can help me. The first type of notice is "undefined variable". This function will return the notice if I remove the bold red line, where I define the variable as empty before I use it in the loop. I didn't need to do this before. function statistics($array) { [color=red][b]$list = '';[/b][/color] if(is_array($array)) { foreach($array as $name => $value) { // Rip out the name of the client. $list .= "<li>".$name." - "; // set an integer so we know how many tier2 values we have read. $x = 0; foreach($value as $difference => $sum_total) { // if this is the more than the first tier2 values, use a '+' between the units. $list .= (++$x > 1) ? " + ".$sum_total." ".$difference : $sum_total." ".$difference; } // close the line out. $list .= "</li>"; } } return $list; } To avoid the 10+ like notices on the page I declare them empty before the variable's first occurrence. But this sounds stupid to me. Wasn't this one of PHP's benefits, not to have to declare the variable before using it? I also get about 30+ undefined index notices, e.g. Quote Notice: Undefined index: COMPANY XXX in F:\wamp\www\Project Management\main.php on line 37 Notice: Undefined index: USD in F:\wamp\www\Project Management\main.php on line 37 Notice: Undefined index: USD in F:\wamp\www\Project Management\main.php on line 41 Here are those lines: $income_total = calculate("income"); foreach($income_total as $row) { $clientID = $row['clientID']; $clientname = $row['clientname']; //$client = "<a href=\"index.php?page=Client&do=view&clientID=$clientID\">".$clientname."</a>"; $client = "<a href=\"index.php?page=Project&do=view&sortby=$clientID\">".$clientname."</a>"; $currency = $row['currency']; $client_sum = $row['client_sum']; $year_sum = ''; $year_sum += $client_sum; $income = ''; $income[$client][$currency] += $client_sum; $income_list = statistics($income); $income_all = ''; $income_all[$currency] += $client_sum; } Line 37 is: Quote $income[$client][$currency] = It's the values assigned to $client and to $currency that seem to cause the notice. How do I deal with this? I don't just want to turn error/notice display off, I want to resolve this issue. I am pretty sure I defined these, by making it something like $blah="blah" and `blah` = ' {$blah}' So why am I getting these errors = Notice: Use of undefined constant petid - assumed 'petid' in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 38 Notice: Use of undefined constant adopter - assumed 'adopter' in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 41 Notice: Undefined variable: fulldate in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 44 Fatal error: Call to undefined function showpet_forum() in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 45 $time = mysql_query("SELECT * FROM `pets_adopted`"); $date = mysql_fetch_array($time); $fulldate = "$date[fulldate]"; $halfdate = "$date[halfdate]"; function check(){ $pid = mysql_real_escape_string($_GET['id']); $result = mysql_query("SELECT * FROM `pets_adopted` WHERE `id` = '{$pid}'"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $results = mysql_query("SELECT * FROM `pets_list` WHERE `id` = '{$row[petid]}'"); $pet = mysql_fetch_array($results); $results2 = mysql_query("SELECT * FROM `users` WHERE `id` = '{$row[adopter]}'"); $usercc = mysql_fetch_array($results2); There's the snippet. Thank you for any help. I am just really lost. I have just re-installed Xampp and suddenly my sites are now displaying lots of: Notice: Use of undefined constant name - assumed 'name' in ... Notice: Use of undefined constant price - assumed 'price' in ... this is an example of the line its refering too: $defineProducts[1001] = array(name=>'This is a product', price=>123); hi, I need help really badly for my PHP-Postcard Script. Basically it sends the card out but the URL does not work, I get the following error message: The URL is not valid and cannot be loaded It also states that Notice: Undefined index: www.voluntary.awardspace.co.uk in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 25 Notice: Undefined index: Postcard.php in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 25 See Code below: <?php session_start(); //check error log ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); // CHANGE PARAMETERS HERE BEGIN $senderName = " Holidays From Home "; // Eg.: John's Postcards $senderEmail = "chris01@voluntary.awardspace.co.uk"; // Eg.: john@postcard.com // Change only if you have problems with urls $postcardURL = "http://".$_SERVER["www.voluntary.awardspace.co.uk"].$_SERVER["Postcard.php"]; // CHANGE PARAMETERS HERE END $result = 0; $msg = ""; $msg1 = ""; $pic = ""; function displayPhotos() { global $pic; $columns = 5; $act = 0; $act1 = 0; // Open the actual directory if($handle = opendir("thumbs")) { // Read all file from the actual directory while($file = readdir($handle)) { if(!is_dir($file)) { if(isset($pic[1])) { if($pic[1] == $act1){$sel = "checked";} else{$sel = "unchecked";} } if($act == 0){echo "<tr>";} echo "<td align='center'><img src='thumbs/$file' alt='postcard'/><br/><input type='radio' name='selimg' value='$file,$act1' $sel/></td>"; $act++; $act1++; if($act == $columns){$act = 0;echo "</tr>";} } } echo "</tr>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Micro Postcard</title> <link href= "style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div class="style1" id="caption"> <div align="left" class="style1"></div> </div> <?php //makes sure form is correctly filled in if(!empty($_POST["submit"])) { if(empty($_POST["selimg"])){$msg = "Please select an image from above!";$result = 3;} else{$pic = explode(",",$_POST["selimg"]);} if(empty($_POST["email"]) && empty($result)){$msg1 = "You must enter an email address!";$result = 3;} $secCode = empty($_POST["secCode"]) ? "" : strtolower($_POST["secCode"]); if($secCode == $_SESSION["securityCode"] && $result != 3) { $filename = date("YmdGis"); $f = fopen("messages/".$filename.".txt","w+"); fwrite($f,$pic[0]."\n"); fwrite($f,$_POST['email']."\n"); fwrite($f,stripslashes($_POST["message"])."\n"); fclose($f); // Compose the mail $from = "From: $senderName <$senderEmail>\r\n"; $replay = "Reply-To: $senderEmail\r\n"; $params = "MIME-Version: 1.0\r\n"; $params .= "Content-type: text/plain; charset=iso-8859-1\r\n"; $mailtext = "You have just received a Virtual Postcard!\r\n\r\n You can pick up your postcard at the following web address:\r\n $postcardURL?show=$filename\r\n\r\n We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n Regards,\r\n Holidays From Home\r\n $postcardURL"; // Send email @mail($_POST["email"],"You've received a postcard",$mailtext,$from.$replay.$params); echo "<center> Your postcard was sent successfully!<br /><br /> <img src='images/$pic[0]' alt='postcard' /><br /><br /><br />".stripslashes($_POST["message"]). "</center>"; $result = 1; } else{if($result != 3){$result = 2;}} } if(!empty($_GET["show"])) { $file = $_GET["show"]; $content = file("messages/$file.txt"); $pic = $content[0]; unset($content[0]); unset($content[1]); foreach($content as $value){$main .= $value;} echo "<center> Your postcard!<br /><br /> <img src='images/$pic' alt='postcard' /><br /><br /><br />$main </center>"; } if((empty($result) || $result == 2 || $result == 3) && empty($_GET["show"])) { echo "<form action='#' method='post'> <table align='center'>"; displayPhotos(); echo "</table> <div style='color:#f00;font-size:16px;'>$msg</div> <h2>Fill in the Form and then click on Send Card!!</h2> <table width='100%'> <tr><td>Send to (email address):</td><td><div style='color:#f00;font-size:16px;'>$msg1</div><input type='text' name='email' size='30' value='".$_POST["email"]."' /></td></tr> <tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>".stripslashes($_POST["message"])."</textarea></td></tr> <tr><td colspan='2'>".($result == 2 ? "<p style='color:#f00;font-size:16px;'>Sorry the security code is invalid! Please try it again!</span></p>" : " ")."</tr> <tr> <td>Security code: <input class='text' name='secCode' type='text' size='10' /> </td><td><img src='securityCode.php' alt='security code' border='1' /></td> </tr> <tr><td colspan='2'> </tr> <tr><td colspan='2' align='left'><input type='submit' value='Send card!' name='submit'/></td></tr> </table> </form>"; } ?> Absolutely any help would be much appreciated. I want ot know is there a way round this problem? Here is the http://voluntary.awardspace.co.uk/Postcard.php I am absolutely desperate to solve this burning issue I just moved my code from Appserv to EasyPHP and it gave me this error, it was working fine on Appserv...what's with easyPHP ?? When I run the MySQL queries in the code below in SQLyog, the $pokemon_pos in the "SELECT max(pokemon_pos)" part of the statement is always correct (i.e. alias "x" is correct). Yet when wrapped up in PHP, $newpos, which relies on "x" is always undefined. I'd greatly appreciate any help in troubleshooting this code - Code: [Select] $getdeclined="SELECT * FROM trade_offers WHERE pokemon_trade_id=$_GET[id]"; $declined=mysql_query($getdeclined); while ($row = mysql_fetch_array($declined)){ $getdecusername="SELECT MAX(pokemon_pos) FROM ( SELECT pokemon_pos FROM pokemon_trainer WHERE pokemon_trainer = '$row[pokemon_trainer]' UNION SELECT pokemon_pos FROM trade_offers WHERE pokemon_trainer = '$row[pokemon_trainer]' AND pokemon_trade_id = $_GET[id] ) AS x"; $decusername=mysql_query($getdecusername); while($row2 = mysql_fetch_array($decusername)){ $newpos = $row2['x'];} echo $newpos; $newpos +=1; } } I had some help righting this query and the extensive coding here and most of it I understand however when i run this it gives me an undefined variable charname error and I'm trying to understand why. Does the coding make sense to anyone? <?php $query = "SELECT ecm.name AS fighters, ecb.id AS showid, ecm.id AS matchid, ecb.bookingdate AS bookingdate, ecb.event_id AS event_id, els.name AS name, ecb.label AS label FROM `efed_content_appearances` AS eca INNER JOIN `efed_content_matchseg` AS ecm ON eca.content_id = ecm.id INNER JOIN `efed_content_booking` AS ecb ON ecm.booking_id = ecb.id INNER JOIN `efed_list_shownames` AS els ON ecb.event_id = els.id WHERE eca.bio_id = '$id' AND eca.type = 'match' ORDER BY ecb.bookingdate DESC, ecm.sortorder ASC"; $result = mysql_query($query); if(mysql_num_rows($result) == 0){ echo '<td colspan="3" class="noseg">This wrestler has never been in an event match.</td>' ; } else{ $count = 1; while($row = mysql_fetch_assoc($result)){ $fighter = explode(' vs. ', $row['fighters']); $opponents = ''; for($i = 0; $i < count($fighter); $i++){ if($fighter[$i] != $charname){ if($opponents != ''){ $opponents .= ', '; } $opponents .= $fighter[$i]; } } echo '<table cellspacing="0px" style="text-align: center;"><tr class="titlebar"><td>Date</td><td>Show</td><td>Opponent/s</td></tr>'; echo '<tr class="row' . $count . '"><td>' . convertdate($row['bookingdate']) . '</td><td><a href="content.php?p=results&show=' . $row['event_id'] . '&id=' . $row['showid'] . '#' . $row['matchid'] . '">' . $row['name'] . ' ' . $row['label'] . '</a></td><td>' . $opponents . '</td></tr>'; echo '</table>'; if($count == 1){ $count = 2; } else { $count = 1; } } } ?> Hi all, When i run the code below he gives the variable $naantal below he got the number i put in with ?undefined after it. Code: [Select] <?php $id = $_GET["id"]; $naantal = $_GET["aantal"]; $wijzig ="UPDATE care_medicijnen SET aantal=$naantal WHERE $id=id"; echo $wijzig; if(isset($_GET["id"])) { mysql_query($wijzig); } ?> When my input is the number 8 he gives this as output: Quote UPDATE care_medicijnen SET aantal=8?undefined WHERE 4160962=id How can i fix this that i only got the number 8 without ?undefined after it. already thanks Hi, Getting this error message but I know that it is defined just for some reason it won't pick it up. Taken the url out so the site can't be accessed. An error occurred in script 'example/register.php' on line 101: Undefined variable: message Date/Time: 7-Feb-2011 18:32:10 Code: [Select] <?php # Script 16.6 - register.php // This is the registration page for the site. require_once("includes/functions.php"); include("includes/header.php"); require_once("includes/connection.php"); require_once ('includes/config.inc.php'); $page_title = 'Register'; //include ('includes/header.html'); if (isset($_POST['submitted'])) { // Handle the form. require_once ('mysqli_connect.php'); // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p = FALSE; // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) { $fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']); } else { echo '<p class="error">Please enter your first name!</p>'; } // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Please enter your last name!</p>'; } // Check for an email address: if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email'])) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); } else { echo '<p class="error">Please enter a valid email address!</p>'; } // Check for a password and match against the confirmed password: if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { echo '<p class="error">Please enter a valid password!</p>'; } if ($fn && $ln && $e && $p) { // If everything's OK... // Make sure the email address is available: $q = "SELECT user_id FROM users WHERE email='$e'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 0) { // Available. // Create the activation code: $a = md5(uniqid(rand(), true)); // Add the user to the database: $q = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', '$a', NOW() )"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Send the email: $body = "Thank you for registering at. To activate your account, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'], 'Registration Confirmation', $body, 'From: '); // Finish the page: $message = '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>'; } else { // If it did not run OK. echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; } } else { // The email address is not available. echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>'; } } else { // If one of the data tests failed. echo '<p class="error">Please re-enter your passwords and try again.</p>'; } mysqli_close($dbc); } // End of the main Submit conditional. ?> <div id="content"> <div class="paddingContent"> <h3> Register </h3> <br /> <form action="register.php" method="post" class="contact"> <?php echo $message; ?> <div class="registerForm"> <label for="first_name" class="fixedwidth">First Name:</label> <input type="text" name="first_name" id="first_name" value="<?php if (isset($trimmed['first_name'])) echo $trimmed['first_name']; ?>"/> </div> <br /> <div class="registerForm"> <label for="last_name" class="fixedwidth">Last Name:</label> <input type="text" name="last_name" id="last_name" value="<?php if (isset($trimmed['last_name'])) echo $trimmed['last_name']; ?>"/> </div> <br /> <div class="registerForm"> <label for="email" class="fixedwidth">Email Address:</label> <input type="text" name="email" id="email"value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /> </div> <br /> <div class="registerForm"> <label for="password1" class="fixedwidth">Password</label> <input type="password" name="password1" id="password1" value="" /> <small>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small> </div> <br /> <div class="registerForm"> <label for="password2" class="fixedwidth">Confirm Password:</label> <input type="password" name="password2" id="password"/> </div> <br /> <div class="submtForm"><input type="submit" name="submit" value="Register" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> </div> </div> <?php include("includes/footer.php"); ?> <?php // Include the HTML footer. //include ('includes/footer.html'); ?> Hey Guys. I Have a quick questions. I keep getting an "undefined variable" when php parses the following code
echo "<div class='menu'>${$this->price}</div>"."<br>";However when I put a space after the dollar sign it works fine... echo "<div class='menu'>$ {$this->price}</div>"."<br>";Doesn't the curly braces tells php to seperate strings from variables? I'm a little bit confused. Thanks! Hello, I think there may be a simple answer but I have been staring at this code for the last couple for hours and cannot see the error. I am going cross eyed! I have written a form that works apart from a bit where I have radio buttons for yes or no. On the form I get the error: Notice: Undefined variable... on line 134 for both the yes and no responses. The rest of the code is fine and the functionality of uploading to the database works except for this part. Any help would be much appreciated Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Aliens Abducted Me - Report an Abduction</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>Aliens Abducted Me - Report an Abduction</h2> <?php require_once('connectvars3.php'); if (isset($_POST['submit'])) { // Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); // Grab the report data from the POST $first_name = mysqli_real_escape_string($dbc, trim($_POST['firstname'])); $last_name = mysqli_real_escape_string($dbc, trim($_POST['lastname'])); $email = mysqli_real_escape_string($dbc, trim($_POST['email'])); $when_it_happened = mysqli_real_escape_string($dbc, trim($_POST['whenithappened'])); $how_long = mysqli_real_escape_string($dbc, trim($_POST['howlong'])); $how_many = mysqli_real_escape_string($dbc, trim($_POST['howmany'])); $alien_description = mysqli_real_escape_string($dbc, trim($_POST['aliendescription'])); $what_they_did = mysqli_real_escape_string($dbc, trim($_POST['whattheydid'])); $fang_spotted = mysqli_real_escape_string($dbc, trim($_POST['fangspotted'])); $other = mysqli_real_escape_string($dbc, trim($_POST['other'])); if (!empty($first_name) && !empty($last_name) && !empty($when_it_happened) && !empty($how_long) && !empty($what_they_did)) { // Write the data to the database $query = "INSERT INTO aliens_abduction (first_name, last_name, email, when_it_happened, how_long, how_many, alien_description, what_they_did, fang_spotted, other) " . "VALUES ('$first_name', '$last_name', '$email', '$when_it_happened', '$how_long', '$how_many', '$alien_description', '$what_they_did', '$fang_spotted', '$other')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Thanks for adding your abduction.</p>'; echo '<p><a href="index4.php"><< Back to the home page</a></p>'; mysqli_close($dbc); exit(); } else { echo '<p class="error">Please enter your full name, date of abduction, how long you were abducted, and a brief description of the aliens.</p>'; } } ?> <p>Share your story of alien abduction:</p> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="firstname">First name:</label> <input type="text" id="firstname" name="firstname" value=" <?php if (!empty($first_name)) echo $first_name; ?>" /> <br /> <label for="lastname">Last name:</label> <input type="text" id="lastname" name="lastname" value=" <?php if (!empty($first_name)) echo $last_name; ?>" /><br /> <label for="email">What is your email address?</label> <input type="text" id="email" name="email" value=" <?php if (!empty($email)) echo $email; ?>" /> <br /> <label for="whenithappened">When did it happen?</label> <input type="text" id="whenithappened" name="whenithappened" value=" <?php if (!empty($when_it_happened)) echo $when_it_happened; else echo 'YYYY-MM-DD'; ?>" /><br /> <label for="howlong">How long were you gone? </label> <input type="text" id="howlong" name="howlong" value=" <?php if (!empty($how_long)) echo $how_long; ?>" /><br /> <label for="howmany">How many did you see?</label> <input type="text" id="howmany" name="howmany" value=" <?php if (!empty($how_many)) echo $how_many; ?>" /><br /> <label for="aliendescription">Describe them:</label> <input type="text" id="aliendescription" name="aliendescription" size="32" value="<?php if (!empty($alien_description)) echo $alien_description; ?>" /><br /> <label for="whattheydid">What did they do to you?</label> <input type="text" id="whattheydid" name="whattheydid" size="32" value="<?php if (!empty($what_they_did)) echo $what_they_did; ?>" /><br /> <label for="fang_spotted">Have you seen my dog Fang?</label> Yes <input id="fang_spotted" name="fang_spotted" type="radio" value="yes" <?php echo ($fang_spotted == 'yes' ? 'checked="checked"' : ''); ?> No <input id="fang_spotted" name="fang_spotted" type="radio" value="no" <?php echo ($fang_spotted == 'no' ? 'checked="checked"' : ''); ?> /><br /> <br /> <label for="other">Anything else you want to add?</label> <textarea id="other" name="other"><?php if (!empty($other)) echo $other; ?></textarea><br /> <input type="submit" value="Report Abduction" name="submit" /> </form> </body> </html>[u][/u] Notice: Undefined variable: quantity_row in C:\xampp\htdocs\cart\cart.php on line 12 Notice: Undefined index: cart_1 in C:\xampp\htdocs\cart\cart.php on line 12 Notice: Undefined index: cart_1 in C:\xampp\htdocs\cart\cart.php on line 30 Help me guys Code: [Select] <?php session_start(); $page = 'index.php'; mysql_connect('localhost','root','')or die(mysql_error()); mysql_select_db('cart') or die(mysql_error()); if (isset ($_GET['add'])){ $quantity = mysql_query('SELECT id, quantity FROM products WHERE id ='.mysql_real_escape_string( (int)$_GET['add'])); while($quantity_rows = mysql_fetch_assoc($quantity)) { if ($quantity_row['quantity'] != $_SESSION['cart_'.$_GET['add']]) { $_SESSION['cart_'.$_GET['add']] += '1'; } } } function products() { $get = mysql_query('SELECT id, name, description, price FROM products WHERE quantity > 0 ORDER BY id DESC') or die(mysql_error()); if (mysql_num_rows($get) == 0) { echo 'There are no products to display!'; } else { while ($get_row = mysql_fetch_assoc($get)) { echo '<p>'.$get_row['name']. '<br />' .$get_row['description']. '<br />'.number_format( $get_row['price'], 2) . '<a href="cart.php?add='. $get_row['id'].'">Add</a></p>'; } } } echo $_SESSION['cart_1']; ?> I'd appreciate any assistance with the following code. When I echo the output, all the variables are correct, except that pokemon_pos is always 1, whereas it should be something like 49, which is the highest value in either tables trade_offers or pokemon_trainer for a given pokemon_trade_id. Code: [Select] $getdeclined="SELECT * FROM trade_offers WHERE pokemon_trade_id=$_GET[id]"; $declined=mysql_query($getdeclined); while ($row = mysql_fetch_array($declined)){ $getdecusername="select max(pokemon_pos) from ( select max(pokemon_pos) as pokemon_pos from pokemon_trainer WHERE pokemon_trainer = '$row[pokemon_trainer]' union all select max(pokemon_pos) from trade_offers WHERE pokemon_trainer = '$row[pokemon_trainer]' AND pokemon_trade_id = $_GET[id] ) as x"; $decusername=mysql_query($getdecusername); while ($row2 = mysql_fetch_array($decusername)){ $newpos = $row2['pokemon_pos']; $newpos +=1; } $update="UPDATE trade_offers SET pokemon_pos = $newpos WHERE pokemon_id = $row[pokemon_id]"; $result=mysql_query($update); } I am following this tutorial here http://youtu.be/WrbaISEEihM. When i try to edit a product in my inventory i get an error "Undefined variable: product_list in /home/a7064593/public_html/storeadmin/inventory_edit.php on line 85" and i cant work out how to fix it. here is my code http://pastebin.com/k36tBjEL. Thanks can anyone help with this function. i keep getting undefined variable: link error. function simple_query($fields, $table, $clause, $order) { if (empty($config)) { require("./config/config.php"); } if(!empty($clause)) { $clause = "WHERE $clause"; } if(!class_exists('db_mysqli')) { include('./includes/db_mysqli.php'); $link = new db_mysqli; $link->connect($config['database']); } if(!empty($order)) { $direction = $order[0]; switch($direction) { case "0": $direction = "ASC"; break; case "1": $direction = "DESC"; break; } $order = substr($order, 1, strlen($order)); $order = "ORDER BY $order $direction"; } $query = $link->query("SELECT $fields //THIS LINE THROWS THE ERROR FROM ".TBL_PREFIX."$table $clause $order")or die(mysqli_error($link)); return $query; } database class: class db_mysqli { public $link; function connect($settings) { require_once(dirname(dirname(__FILE__)).'/config/config.php'); $link = new mysqli($settings['hostname'], $settings['username'], $settings['password'], $settings['database']); $this->link = $link; } } thanks. Hi there im left joining 3 tables and outputting the results.. Nothing is being out;putputted and Im getting an error: Notice: Undefined variable: row_Test in C:\wamp\www\SWB\ship.php on line 136 Call Stack # Time Memory Function Location 1 0.0014 408608 {main}( ) ..\ship.php:0 Ive tested the join in mysql and it works fine. Its just that on my webpage Nothing is outputted and only this one notice error appears. heres my join: Code: [Select] <?php $colname_Test = "-1"; if (isset($_GET['recordID'])) { $colname_Test = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Test = sprintf("SELECT s.ShipID, s.FleetName, f.FleetName, f.PlanetName, p.PlanetName, p.PlayerName FROM Ships s LEFT JOIN Fleet f ON (s.FleetName = f.FleetName) LEFT JOIN Planet p ON (f.PlanetName = p.PlanetName) WHERE s.ShipID = '$colname_Ship'"); $Test = mysql_query($query_Test, $swb) or die(mysql_error()); $totalRows_Test = mysql_num_rows($Test); ?> echo $row_Test['PlanetName']; ?> Heres how my tables connect: ShipID (FleetName) ---> FleetName (PlanetName) ---> PlanetName, so im trying to detemine the fleet and planet the ship is on. Any ideas why its not working?? Thanks Why does php show undefined variable? I researched and found out that if the variables aren't set then they will likely show undefined variable. However, I used the isset function to check if the variable is undefined and if it is then set it to $varaible ="" . That didn't work and then later i tried $variable = NULL. What should I do Can you please see the code and tell me what shall i do. Thanks a million
<?php require_once("includes/connection.php")?> <?php require_once("includes/function.php") ?> <?php require_once("includes/header.php") ?> <?php if(isset($_GET['subj'])){ $sel_subj = NULL; $sel_subj = $_GET['subj']; } elseif (isset($_GET['page'])){ $sel_page = NULL; $sel_page = $_GET['page'] ; } else { $sel_subj= NULL; $sel_page =NULL; } ?> <table id = "structure" > <tr> <td id = "navigation" > <ul class= "subjects" > <?php $subject_set = get_all_subjects(); while ($subject = mysql_fetch_array($subject_set)){ // <a href = "content.php?subj=1" > if ($sel_subj == $subject["id"]){ echo "<li class = \"selected\" "; }else{ echo "<li> "; } "<a href = \"content.php?subj=" . urlencode($subject["id"]) . "\">" . $subject["menu_name"]. "</a></li>" ; $page_set = get_pages_for_subjects( $subject["id"] ) ; echo " <ul class = \"pages\"> "; while ($page = mysql_fetch_array($page_set)){ echo "<li><a href = \"content.php?page=" . urlencode($page["id"]) . "\">" . $page["menu_name"] . "</a></li>" ; } echo "</ul>" ; } ?> </ul> </td> <td id= "page" > <h1> Main Area To Get Your Information </h1> <?php echo $sel_subj ; ?> <br/> <?php echo $sel_page ; ?> <br/> </td> </tr> </table> <?php include ("includes/footer.php") ?>The variable im refering to is $sel_subj and $sel_page at the top of the code. Here is an attachment of the error Attached Files Capture.PNG 275.47KB 0 downloads I'm getting: Quote PHP Notice: Undefined variable: carttotal ... for this: $idtotal = $sizestotal + $sizemtotal + $sizeltotal + $sizexltotal; $carttotal += $idtotal; Why? Hi guys, hope someone can help? I noticed an error in my logs & upon digging it seems this script is causing the issue:-
<?php error_reporting(E_ALL); //$IPaddress=$_SERVER['REMOTE_ADDR']; $IPaddress='45.152.180.38'; $two_letter_country_code=iptocountry($IPaddress); include("ip_files/countries.php"); $three_letter_country_code=$countries[ $two_letter_country_code][0]; $country_name=$countries[$two_letter_country_code][1]; print "Two letters code: $two_letter_country_code<br>"; print "Three letters code: $three_letter_country_code<br>"; print "Country name: $country_name<br>"; // To display flag $file_to_check="flags/$two_letter_country_code.gif"; if (file_exists($file_to_check)){ print "<img src=$file_to_check width=30 height=15><br>"; }else{ print "<img src=flags/noflag.gif width=30 height=15><br>"; } function iptocountry($ip) { $numbers = preg_split( "/\./", $ip); include("ip_files/".$numbers[0].".php"); $code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]); foreach($ranges as $key => $value){ if($key<=$code){ if($ranges[$key][0]>=$code){$two_letter_country_code=$ranges[$key][1];break;} } } if ($two_letter_country_code==""){$two_letter_country_code="UNKNOWN";} return $two_letter_country_code; } ?>
This script was originally from here http://phptutorial.info/iptocountry/the_script.html Very new to PHP. But I'm running through some tutorials here and there and I was working on this script to calculate test scores. Could someone please assist? This is also my first post so I'm hoping it's in the right place. Thanks in advance! It is also attached if anyone needs a reference. It is reporting: Quote Notice: Undefined variable: test_complete in C:\xampp\htdocs\lascelles\quizscriptV2.php on line 16 Code: [Select] <? $page_title = "Calculate Test Scores"; // This runs a script when the form is submitted. if(isset($_POST['submit'])){ $quest1 = $_POST['quest1']; $quest2 = $_POST['quest2']; $quest3 = $_POST['quest3']; $quest4 = $_POST['quest4']; $quest5 = $_POST['quest5']; // Lets make sure that everything has been submitted if($quest1 == NULL OR $quest2 == NULL OR $quest3 == NULL OR $quest4 == NULL OR $quest5 == NULL) { $test_complete .='Please complete the test! <a href="javascript:history.go(-1)">Go Back</a>'; }else{ // change the quest1 to the right answer if($quest1 == "3") { $test_complete .="Question one is <span class='green'>correct</span>, well done!<br/>"; }else{ $test_complete .="Question one is <span class='red'>incorrect</span>!<br/>"; } // change the quest2 to the right answer if($quest2 == "2") { $test_complete .="Question two is <span class='green'>correct</span>, well done!<br/>"; }else{ $test_complete .="Question two is <span class='red'>incorrect</span>!<br/>"; } // change the quest3 to the right answer if($quest3 == "1") { $test_complete .="Question three is <span class='green'>correct</span>, well done!<br/>"; }else{ $test_complete .="Question three is <span class='red'>incorrect</span>!<br/>"; } // change the quest4 to the right answer if($quest4 == "3") { $test_complete .="Question four is <span class='green'>correct</span>, well done!<br/>"; }else{ $test_complete .="Question four is <span class='red'>incorrect</span>!<br/>"; } // change the quest5 to the right answer if($quest5 == "2") { $test_complete .="Question five is <span class='green'>correct</span>, well done!<br/>"; }else{ $test_complete .="Question five is <span class='red'>incorrect</span>!<br/>"; } // Now lets see if all the questions are correct, this must match the above quest settings if($quest1 == "3" & $quest2 == "2" & $quest3 == "1" & $quest4 == "3" & $quest5 == "2"){ $test_complete .="<p>Congratulations, you got all the questions correct!</p>"; }else{ // If any of the questions are not correct lets tell them $test_complete .='<p>Try again next time! <a href="javascript:history.go(-1)">Try again</a></p>'; }}} ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Calculate Test Scores</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> <!-- body,td,th { color: #000000; } .green {color:#009933;} .red {color:#CC0000;} --> </style></head> <body> <? if(!isset($_POST['submit'])){ ?> <h2>Calculate Test Scores</h2> <p>Please answer the following questions.</p> <form method="post"> <p>1. Do you like tests?<br> <input type="radio" name="quest1" value="3"> Yes<br> <input type="radio" name="quest1" value="2"> Maybe<br> <input type="radio" name="quest1" value="1"> No</p> <p>2. Do you like multiple choice?<br> <input type="radio" name="quest2" value="1"> Some times<br> <input type="radio" name="quest2" value="3"> Never<br> <input type="radio" name="quest2" value="2"> Always</p> <p>3. Do you study hard?<br> <input type="radio" name="quest3" value="2"> No<br> <input type="radio" name="quest3" value="1"> Yes<br> <input type="radio" name="quest3" value="3"> Not sure</p> <p>4. Do you like PHP?<br> <input type="radio" name="quest4" value="3"> Yes <br> <input type="radio" name="quest4" value="2"> Never <br> <input type="radio" name="quest4" value="1"> Maybe </p> <p>5. Do you enjoy programming? <br> <input type="radio" name="quest5" value="3"> Nope <br> <input type="radio" name="quest5" value="2"> Always<br> <input type="radio" name="quest5" value="1"> Never </p> <p> <input type="submit" name="submit" value="Calculate Score"> </p> </form> <? }else{ echo "<h2>Quiz Results</h2> <p>".$test_complete ."</p>"; }?> </body> </html> |