Modernvox Posted August 29, 2010 Share Posted August 29, 2010 My form <form action="process.php" method="post"> <font face= "calibri" size= "4"> <table border= "1"> <tr style= "background: #cccccc"> <td><b>Item Description:</b></td> <td><input type= "text" name= "itemDescription" size= "30" value=""/></td> </tr> <tr style= "background: #99ff00"> <td><b>Item Price:</b></td> <td><input type= "text" name= "itemPrice" size= "5" value=""/></td> </tr> </tr style= "background: #A8E5FF"> <td><b>Winning Bidders:</b></td> <td><input type="text" name= "winningBidder" size= "5" /> </td> </tr> <tr> <td><b>How many deals?:</b></td> <td><input type="text" name= "itemQty" size= "3" value= "1" /></td> </tr> </table> <br/> <input type="reset" value="Reset Form"><input type="submit" name="submit" value= "Save & Cont." " /> </form></font> My process script: <?php error_reporting(E_ALL); ini_set("display_errors", 1); $host= ""; $db_name= ""; $db_user= ""; $db_password= ""; $logUser= $_POST['logUser']; $deleteBidder = $_POST['deleteBidder']; $newBidder= $_POST['newBidder']; $itemDescription= $_POST['itemDescription']; $itemPrice= $_POST['itemPrice']; $winningBidder= $_POST['winningBidder']; $itemQty= $_POST['itemQty']; ob_start(); if ($_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 ($_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 ($_POST['itemDescription'] AND $_POST['itemPrice'] AND $_POST['winningBidder'] AND $_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 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\"/>"; $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')"); mysql_query("INSERT INTO transactions (itemDescription, itemPrice, bidderId, itemQty , totalPrice) VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')") or die(mysql_error()); $_SESSION['itemDescription']='$itemDescription'; header("Location: index.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(); ?> DeleteBidder and newBidder are the only variables working? Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/ Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 Is that the right form? There's no field named deleteBidder on that form. This isn't valid either: <input type="submit" name="submit" value= "Save & Cont." " /> Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104970 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 Is that the right form? There's no field named deleteBidder on that form. That's from another form on the another page Alex. I am using process.php to process all forms Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104971 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 Here's what my code id producing for an error Notice: Undefined index: deleteBidder in C:\xampp\htdocs\process.php on line 44 Notice: Undefined index: newBidder in C:\xampp\htdocs\process.php on line 45 Notice: Undefined index: itemDescription in C:\xampp\htdocs\process.php on line 46 Notice: Undefined index: itemPrice in C:\xampp\htdocs\process.php on line 47 Notice: Undefined index: winningBidder in C:\xampp\htdocs\process.php on line 48 Notice: Undefined index: itemQty in C:\xampp\htdocs\process.php on line 49 Notice: Undefined index: newBidder in C:\xampp\htdocs\process.php on line 56 Notice: Undefined index: deleteBidder in C:\xampp\htdocs\process.php on line 78 Notice: Undefined index: itemDescription in C:\xampp\htdocs\process.php on line 89 That bidder is already logged, Please press your browsers back button and try again. Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104972 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 Is that the right form? There's no field named deleteBidder on that form. This isn't valid either: <input type="submit" name="submit" value= "Save & Cont." " /> Yeah..Fixed the <input type="submit" name="submit" value= "Save & Cont." " /> crap, but still producing same errors Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104974 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 Did you fix that HTML error I pointed out? If you're using multiple forms and all of those variables won't always be set than you'll always get those errors with your current code. You should be doing something like this for all your variables: $logUser= isset($_POST['logUser']) ? $_POST['logUser'] : ''; This probably isn't related to your current problem, but it is an issue with your code: $_SESSION['itemDescription']='$itemDescription'; That will set $_SESSION['itemDescription'] to th literal string '$itemDescription' and not the value that the variable holds. Instead it should be: $_SESSION['itemDescription'] = $itemDescription; Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104975 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 These 2 forms work as expected: <tr> <td><font face= "calibri" size= "4"> Let's begin by adding bidders...</font></td> </tr> <Table border= "1"> <form action="process.php" method="post"> <tr style="background: #99cc33;"> <td><strong><font face= "calibri" style= "bold"> Bidders Id: </font></strong></td> <td><input type= "text" name= "newBidder"/></td> </tr> <tr> <td><input type="Submit" value="submit"></td> </tr> </table> <tr> <td><font face= "calibri" size= "4"> Here we can </font><font color= "red"> delete bidders.</font></td> </tr> <Table border= "1"> <form action="process.php" method="post"> <tr style="background: #ff6600;"> <td><strong><font face= "calibri" style= "bold"> Bidders Id: </font></strong></td> <td><input type= "text" name= "deleteBidder"/></td> </tr> <tr> <td><input type="Submit" value="submit"></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104976 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 Did you fix that HTML error I pointed out? If you're using multiple forms and all of those variables won't always be set than you'll always get those errors with your current code. You should be doing something like this for all your variables: $logUser= isset($_POST['logUser']) ? $_POST['logUser'] : ''; This probably isn't related to your current problem, but it is an issue with your code: $_SESSION['itemDescription']='$itemDescription'; That will set $_SESSION['itemDescription'] to th literal string '$itemDescription' and not the value that the variable holds. Instead it should be: $_SESSION['itemDescription'] = $itemDescription; So I should be using isset instead of just if $_POST['whatever'] ? Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104977 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 You need to check if the variable is set or not before you use it using isset. Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104978 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 You need to check if the variable is set or not before you use it using isset. Understood ALex, I thank you. How is that suppose to be written if (isset(firstvar) && (second var) or is it isset($_POST['firstvar'] && ?? Sorry, multiple conditions confuse my little brain.. Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104982 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 When using it to the set the value of variables like this: $logUser= isset($_POST['logUser']) ? $_POST['logUser'] : ''; You wouldn't use multiple conditions. The purpose of that is to set $logUser to $_POST['logUser'] if it's set, otherwise set it equal to an empty string, ''. For using isset in other contexts it does support multiple parameters and returns true if they're all set. if(isset($_POST['something'], $_POST['somethingelse'])) { // ... } Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104983 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 When using it to the set the value of variables like this: $logUser= isset($_POST['logUser']) ? $_POST['logUser'] : ''; You wouldn't use multiple conditions. The purpose of that is to set $logUser to $_POST['logUser'] if it's set, otherwise set it equal to an empty string, ''. For using isset in other contexts it does support multiple parameters and returns true if they're all set. if(isset($_POST['something'], $_POST['somethingelse'])) { // ... } Ok. So, i must do this for each of my variables I suppose> $logUser= isset($_POST['logUser']) ? $_POST['logUser'] : ''; ? Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104984 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 For all your variables coming from outsides sources that are not guaranteed to be set, yes. Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104985 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 Ok. SO, what would my if statements look like if my variables are being set as $logUser= isset($_POST['logUser']) ? $_POST['logUser'] : ''; if ($logUser) { Conditions here } ?? Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104988 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 You could still use isset on the $_POST variables. if ($_POST['itemDescription'] AND $_POST['itemPrice'] AND $_POST['winningBidder'] AND $_POST['itemQty']) Could be: if (isset($_POST['itemDescription'], $_POST['itemPrice'], $_POST['winningBidder'], $_POST['itemQty'])) Optimally you shouldn't define all the variables at the top if you're not going to be using them every time the script runs. You should have them defined within the if statements that determine if they're going to be needed or not. Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104990 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 You could still use isset on the $_POST variables. if ($_POST['itemDescription'] AND $_POST['itemPrice'] AND $_POST['winningBidder'] AND $_POST['itemQty']) Could be: if (isset($_POST['itemDescription'], $_POST['itemPrice'], $_POST['winningBidder'], $_POST['itemQty'])) Optimally you shouldn't define all the variables at the top if you're not going to be using them every time the script runs. You should have them defined within the if statements that determine if they're going to be needed or not. Even with all these fixes, I still get the same errors in that all my variables are undefined from that particular form.. I need a cheeseburger, i'm getting upset Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104991 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 If variables from the form that you're submitting are not set then it's most likely a problem with your HTML. Make sure that is all correct. I noticed that in the two forms you posted you weren't closing them off, but I figured that you probably closed it the line after what you posted. Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104993 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 After all fixes here's what we got for errors (smaller list:-) Notice: Undefined index: deleteBidder in C:\xampp\htdocs\process.php on line 43 Notice: Undefined index: newBidder in C:\xampp\htdocs\process.php on line 44 Notice: Undefined index: newBidder in C:\xampp\htdocs\process.php on line 52 Notice: Undefined index: deleteBidder in C:\xampp\htdocs\process.php on line 74 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\process.php on line 98 Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104994 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 If variables from the form that you're submitting are not set then it's most likely a problem with your HTML. Make sure that is all correct. I noticed that in the two forms you posted you weren't closing them off, but I figured that you probably closed it the line after what you posted. Yeah the two forms I didn't close off are the ONLY 2 working:-) Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104995 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 Well they should be closed off.. did you close them off now? Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104996 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 Well they should be closed off.. did you close them off now? Yes sir and here's what I have as of now for errors Notice: Undefined index: newBidder in C:\xampp\htdocs\process.php on line 52 Notice: Undefined index: deleteBidder in C:\xampp\htdocs\process.php on line 75 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\process.php on line 99 That Bidder Number is NOT logged in, would you like to set this bidder as active? Enter 1 for NO or 2 for YES Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1104999 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 Can you post your full code as it stands now? (Both HTML and PHP) Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1105000 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 Ok this is the form that adds item description, price, qty and biddersid number. <form action="process.php" method="post"> <font face= "calibri" size= "4"> <table border= "1"> <tr style= "background: #cccccc"> <td><b>Item Description:</b></td> <td><input type= "text" name= "itemDescription" size= "30" value=""/></td> </tr> <tr style= "background: #99ff00"> <td><b>Item Price:</b></td> <td><input type= "text" name= "itemPrice" size= "5" value=""/></td> </tr> </tr style= "background: #A8E5FF"> <td><b>Winning Bidders:</b></td> <td><input type="text" name= "winningBidder" size= "5" /></td> </tr> <tr> <td><b>How many deals?:</b></td> <td><input type="text" name= "itemQty" size= "3" value= "1" /></td> </tr> <br/> <input type="reset" value="Reset Form"><input type="submit" name="submit" value= "submit" /> </font> </table> </form> These are the foms that add or delete a bidders ID located on a different page other than the of the itemdescription , etc form. <tr> <td><font face= "calibri" size= "4"> Let's begin by adding bidders...</font></td> </tr> <Table border= "1"> <form action="process.php" method="post"> <tr style="background: #99cc33;"> <td><strong><font face= "calibri" style= "bold"> Bidders Id: </font></strong></td> <td><input type= "text" name= "newBidder"/></td> </tr> <tr> <td><input type="Submit" value="submit"></td> </tr> </table> </form> <tr> <td><font face= "calibri" size= "4"> Here we can </font><font color= "red"> delete bidders.</font></td> </tr> <Table border= "1"> <form action="process.php" method="post"> <tr style="background: #ff6600;"> <td><strong><font face= "calibri" style= "bold"> Bidders Id: </font></strong></td> <td><input type= "text" name= "deleteBidder"/></td> </tr> <tr> <td><input type="Submit" value="submit"></td> </tr> </table> </form> Still don't understand why the script tells me delete and newbidder are undefined when I am not submitting those forms?? Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1105004 Share on other sites More sharing options...
Modernvox Posted August 29, 2010 Author Share Posted August 29, 2010 Oops and here's the process.php page for all the forms. <?php error_reporting(E_ALL); ini_set("display_errors", 1); $host= ""; $db_name= ""; $db_user= ""; $db_password= ""; ob_start(); if ($_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 ($_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 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\"/>"; $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')"); 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(); } } 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/#findComment-1105005 Share on other sites More sharing options...
Alex Posted August 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212030-why-are-5-of-my-7-variables-reporting-as-undefined-im-lost/#findComment-1105008 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.