Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 Still don't understand why the script tells me delete and newbidder are undefined when I am not submitting those forms?? Because even though you're not submitting that form the code is getting a point where it's using a variable that is not defined (obviously). Just make sure that before you use a variable from an outside source that might not be set you make sure that it is using isset. You must've edited that code because the errors you posted can't be happening on those lines in the code provided. Don't know what to tell ya bud, it is what it is. Just ain't working.... Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/page/2/#findComment-1105009 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 Nothing doesn't just not work for no reason. Look at this line: if ($_POST['deleteBidder']) Should be: if(isset($_POST['deleteBidder'])) Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/page/2/#findComment-1105013 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 Nothing doesn't just not work for no reason. Look at this line: if ($_POST['deleteBidder']) Should be: if(isset($_POST['deleteBidder'])) That part of the script is already working, so why mess with it? Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/page/2/#findComment-1105019 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 No it's not working. That along with this: if ($_POST['newBidder']) { Will cause problems when the $_POST['deleteBidder'] and $_POST['newBidder'] variables are not set, as you're seeing. Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/page/2/#findComment-1105020 Share on other sites More sharing options...
Modernvox Posted August 30, 2010 Author Share Posted August 30, 2010 No it's not working. That along with this: if ($_POST['newBidder']) { Will cause problems when the $_POST['deleteBidder'] and $_POST['newBidder'] variables are not set, as you're seeing. Alright, So I owe you a cheeseburger. When your in the U.S. come see me. The only remaining problem is in my SQL statement as it reads "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\process.php on line 91 I will look into this thoroughly t see if I can't find what i am doing wrong. Thanks again:-) Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/page/2/#findComment-1105026 Share on other sites More sharing options...
Alex Posted August 30, 2010 Share Posted August 30, 2010 That's happening because the previous mysql_query is returning false. Print out the query and see what the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/page/2/#findComment-1105027 Share on other sites More sharing options...
Modernvox Posted August 30, 2010 Author Share Posted August 30, 2010 That's happening because the previous mysql_query is returning false. Print out the query and see what the problem is. C'mon now, I can barely swallow what's in front of me...I don't know where to print out the query? This is a problem , no? mysql_Query("INSERT INTO bidders (biddersId) VALUES ('$winningBidder')"); echo $row['winningBidder']; mysql_query("INSERT INTO transactions (itemDescription, itemPrice, bidderId, itemQty , totalPrice) VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')") or die(mysql_error()); header("Location: index.php"); exit(); Because I ma using the same name mysql_Query? Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/page/2/#findComment-1105030 Share on other sites More sharing options...
Alex Posted August 30, 2010 Share Posted August 30, 2010 PHP function names are case-insensitive, so it doesn't matter. Find the line where the error is occurring, find the result that the call to mysql_num_rows on that line is using and print out the query that was used to create that result. Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/page/2/#findComment-1105032 Share on other sites More sharing options...
Modernvox Posted August 30, 2010 Author Share Posted August 30, 2010 PHP function names are case-insensitive, so it doesn't matter. Find the line where the error is occurring, find the result that the call to mysql_num_rows on that line is using and print out the query that was used to create that result. Just wanted to let you know where i goofed(we know all the other goofs, this is the my sql goof:-) highlighted in Orange. <?php error_reporting(E_ALL); ini_set("display_errors", 1); $host= "localhost"; $db_name= "bidders"; $db_user= "root"; $db_password= ""; ob_start(); if(isset($_POST['newBidder'])) { $newBidder= isset($_POST['newBidder']) ? $_POST['newBidder'] : ''; $bidderId= $newBidder; mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM bidders WHERE biddersId='$bidderId'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==0){ // Add $biddersId and redirect to anypage mysql_Query("INSERT INTO bidders (biddersId) VALUES ('$bidderId')"); header("Location: index.php"); exit(); } } if(isset($_POST['deleteBidder'])) { $deleteBidder= isset($_POST['deleteBidder']) ? $_POST['deleteBidder'] : ''; mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_query("DELETE FROM bidders WHERE biddersId='$deleteBidder'"); header("Location: index.php"); exit(); } if (isset($_POST['itemDescription'], $_POST['itemPrice'], $_POST['winningBidder'], $_POST['itemQty'])) { $itemDescription= isset($_POST['itemDescription']) ? $_POST['itemDescription'] : ''; $itemPrice= isset($_POST['itemPrice']) ? $_POST['itemPrice'] : ''; $winningBidder= isset($_POST['winningBidder']) ? $_POST['winningBidder'] : ''; $itemQty= isset($_POST['itemQty']) ? $_POST['itemQty'] : ''; mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM transactions WHERE bidderIds='$winningBidder'"; [color=red]//transactions uses bidderId NOT biddersId[/color] $result=mysql_query($sql); $count=mysql_num_rows($result); // If result matched, table row must be 1 row if($count==0){ echo "That Bidder Number is NOT logged in, "; echo "would you like to set this bidder as active?"; echo " Enter 1 for NO or 2 for YES"; echo "<form action= \"process.php\" method= \"POST\">"; echo "<input type =\"text\" name= \"logUser\"/>"; echo "<input type= \"submit\" value = \"Submit\"/>"; $logUser= isset($_POST['logUser']) ? $_POST['logUser'] : ''; exit(); } if ($logUser= 1) { header("Location: inprogress.php"); exit(); } else if ($logUser= 2){ // Add $biddersId and redirect to anypage mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_Query("INSERT INTO bidders (biddersId) VALUES ('$winningBidder')"); echo $row['winningBidder']; mysql_query("INSERT INTO transactions (itemDescription, itemPrice, bidderId, itemQty , totalPrice) VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')") or die(mysql_error()); header("Location: inprogress.php"); exit(); } } echo "<font color= \"red\" face=\"calibri\" size=\"4\">That bidder is already logged, Please press your browsers back button and try again.</font>"; ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/page/2/#findComment-1105038 Share on other sites More sharing options...
Modernvox Posted August 30, 2010 Author Share Posted August 30, 2010 Almost there, but i face one more obstacle. I receive no errors, but no input is added to the database. If anyone sees something out of whack, please respond? if (isset($_POST['itemDescription'], $_POST['itemPrice'], $_POST['winningBidder'], $_POST['itemQty'])) { $itemDescription= isset($_POST['itemDescription']) ? $_POST['itemDescription'] : ''; $itemPrice= isset($_POST['itemPrice']) ? $_POST['itemPrice'] : ''; $winningBidder= isset($_POST['winningBidder']) ? $_POST['winningBidder'] : ''; $itemQty= isset($_POST['itemQty']) ? $_POST['itemQty'] : ''; mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM bidders WHERE biddersId='$winningBidder'"; $result=mysql_query($sql); $count=mysql_num_rows($result); // If result matched, table row must be 1 row if($count==0){ echo "That Bidder Number is NOT logged in, "; echo "would you like to set this bidder as active?"; echo " Enter 1 for NO or 2 for YES"; echo "<form action= \"process.php\" method= \"POST\">"; echo "<input type =\"text\" name= \"logUser\"/>"; echo "<input type= \"submit\" value = \"Submit\"/>"; exit(); } } $logUser= isset($_POST['logUser']) ? $_POST['logUser'] : ''; if ($logUser= '1') { header("Location: inprogress.php"); exit(); } else if ($logUser= '2'){ // Add $biddersId and redirect to anypage mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_Query("INSERT INTO bidders (biddersId) VALUES ('$winningBidder')"); mysql_query("INSERT INTO transactions VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')") or die(mysql_error()); header("Location: inprogress.php"); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/page/2/#findComment-1105063 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.