PHP - Undefined Variable: Return
Undefined variable: return line 38
that line is : echo $return; Below is a look at my full code. Code: [Select] <?php class cms { var $host; var $username; var $password; var $db; function connect() { $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content($id = ''){ if($id !=""): $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; $return = '<a href="index.php">Go Back?</a>'; else: $sql = "SELECT * FROM cms_content ORDER BY id DESC"; endif; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0): while($row = mysql_fetch_assoc($res)) { echo '<h1><a href="index.php?id=' . $row['id'] .'">' . $row['title'] .'</a></h1>'; echo '<p>' . $row['body'] . '</p>'; } else: echo '<p> Sorry! This Page doesn\'t exist!</p>'; endif; echo $return; } }//Ends our class ?> 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 ?? Hey, In my script I am currenlty working on I have 2 classes one which calls the second in the hope it will return a value to it but doesnt send the variable back. The example code below give you and idea of what I am looking for as my script it too long to add. Code: [Select] class oneClass{ function bar(){ $var1 = "test" $two = twoClass(); $result = $two->foo($var1); echo $result; } } class twoClass{ function foo($var1){ $result = $var1 . ' is successful!'; $this->fooTwo($result); } function fooTwo($result){ $result = $result . ' Pass me back now?'; return($result); //Want to pass the variable back to "oneClass->bar();" } } // Starts script $testme = new oneClass(); $testme->bar(); This is a very simple example but states what i am wanting to. Any ideas would be much appreciated! Thanks This is object programming right? Is there a performance issue with this? for example: $notfications = ( blah blah ) ? : ''; then if ($notificatiosn != blabla){ echo 'hey'; }or.... $notifications = function(){ do my stuff here then return 'hey'; }Which way is faster or slower? Reason I Ask this is because I've been doing some object orientated programming in javascript, and didn't know you could do it in php. I'd rather do the objective way so I don't have to use so many freaking variables above the regular way, lol. Edited by Monkuar, 22 January 2015 - 12:22 PM. Hello All, I have two php files original.php and return.php retrun.php file returns a variable after I pass $channel_name to it Code: [Select] return $return_variable; I want to assign this return variable to a variable in original.php Something like this Code: [Select] $results = include ('return.php?channel='.$channel_name.'');I am not sure how to do the above code. When I call the return.php from a browser it works properly. Thanks for any help I'm not versed in PHP OOP and I have some code that I need to echo out onto a page. I don't know what the meaning of $ct->something is in this code. Is this an array of some type? How do I echo out the $ct->title onto another page? Use a function call? I just don't know what all of the $ct variables are and how to get to them. Any help is appreciated. Code: [Select] function current_theme_info() { $themes = get_themes(); $current_theme = get_current_theme(); if ( ! isset( $themes[$current_theme] ) ) { delete_option( 'current_theme' ); $current_theme = get_current_theme(); } $ct->name = $current_theme; $ct->title = $themes[$current_theme]['Title']; $ct->version = $themes[$current_theme]['Version']; $ct->parent_theme = $themes[$current_theme]['Parent Theme']; $ct->template_dir = $themes[$current_theme]['Template Dir']; $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir']; $ct->template = $themes[$current_theme]['Template']; $ct->stylesheet = $themes[$current_theme]['Stylesheet']; $ct->screenshot = $themes[$current_theme]['Screenshot']; $ct->description = $themes[$current_theme]['Description']; $ct->author = $themes[$current_theme]['Author']; $ct->tags = $themes[$current_theme]['Tags']; $ct->theme_root = $themes[$current_theme]['Theme Root']; $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI']; return $ct; } I think I might have already asked something similar, but... my code has: $ip = gethostbyaddr($_SERVER['REMOTE_ADDR']); $host = $_SERVER['HTTP_HOST']; my field header for "$host" is "VISITOR DOMAIN ADDRESS". I'm not sure what I was thinking. That's not possible to capture is it? Last I read, and I think someone here told me, it is only possible to capture the IP and server name of the requesting computer? the var $ip in my report, for instance, returns: 173-28-199-198.client.mchsi.com if I visit the page, and that is the name of the server assigned to my ISP. on PHP's doc page, there are the vars REMOTE_HOST and REMOTE_USER and I haven't tried those. Their example does not list any return value for those vars. what do they return? Edited November 23, 2019 by ajetrumpetHi 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 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'); ?> 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); } 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! Hey guys, I've been coding PHP for about two weeks now, so excuse the appalling code. Here is the error message Quote Notice: Undefined variable: dbusername in C:\wamp\www\twitbiscuit\process.php on line 25 Here is a pastie link to my code, thanks in advance. http://pastie.org/1076001 ( The fact my first post is asking for help, fail. ) 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 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 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> 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; } } 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. |