Modernvox Posted September 2, 2010 Share Posted September 2, 2010 Hi Guys, 3 days later and i still can't figure this out... I have small script i created for a local auction house. The client will be entering details like [item Name] [item price] [item qty] and [bidders Id] All bidders are logged in as they arrive through the door. Everything is working fine, but when the client fills in the [item details] with a bidder Id that is NOT logged, I want to issue a warning that allows the opportunity to log the user at that time or NOT. I have created this form, but it does NOTHING at ALL. Please have a look, kick me in the ass and teach me a thing or two would ya , please? <?php ob_start(); $host= ""; $db_name= ""; $db_user= ""; $db_password= ""; 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'"; $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=NO or 2=YES"; echo "<form action= \"process_items.php\" method= \"POST\">"; echo "<input type =\"text\" name= \"logUser\"/>"; echo "<input type= \"submit\" value = \"Submit\"/>"; exit(); } if(isset($_POST['logUser'])) { $logUser= isset($_POST['logUser']) ? $_POST['logUser'] : ''; if ($logUser= 1) { header("Location: inprogress.php"); exit(); } /////end if logUser is set else if ($logUser= 2){ 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(); } /////////end loguser2 } } //////end if item decription,etc is set ob_flush(); echo "<font color= \"red\" face=\"calibri\" size=\"4\">That bidder is already logged, Please press your browsers back button and try again.</font>"; ?> The script is NOT acknowledging the $logUser variable at ALL, as if the script is not getting that far or reading it. I suspect I am echoing the form wrong? It does however echo "That Bidder Number is NOT logged in, "; "would you like to set this bidder as active?"; " Enter 1=NO or 2=YES"; Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/ Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 I'm getting this error, Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\process_items.php on line 39 The problem with this is i use the same queries from another page and it works from there? Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106280 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 This is my form <form action="process_items.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/> <tr> <td><input type="reset" value="Reset Form"></td> <td><input type="submit" name="submit" value= "submit" /></td> </tr></font> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106281 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 Here is my transactions TABLE id itemDescription itemPrice bidderId itemQty totalPrice Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106283 Share on other sites More sharing options...
Pikachu2000 Posted September 2, 2010 Share Posted September 2, 2010 Have you tried echoing the query to see if it holds the values you'd expect it to hold? Add the or die(mysql_error()) as well so you get any error messages returned. Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106284 Share on other sites More sharing options...
Pikachu2000 Posted September 2, 2010 Share Posted September 2, 2010 Your table has a field called `bidderId`, but your query string is trying to compare to a field called `bidderIds` . . . Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106285 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 Have you tried echoing the query to see if it holds the values you'd expect it to hold? Add the or die(mysql_error()) as well so you get any error messages returned. How do I echo a Query? Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106286 Share on other sites More sharing options...
trq Posted September 2, 2010 Share Posted September 2, 2010 How do I echo a Query? The same as any other string. echo $sql; Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106287 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 Your table has a field called `bidderId`, but your query string is trying to compare to a field called `bidderIds` . . . YES, I have 2 tables. One is bidders with the field called 'biddersId And transactions which has the field bidderId Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106288 Share on other sites More sharing options...
Pikachu2000 Posted September 2, 2010 Share Posted September 2, 2010 Your table has a field called `bidderId`, but your query string is trying to compare to a field called `bidderIds` . . . Just in case you missed this ^ ^ ^ ^ Double check that the field names are the correct ones, and not misspelled. It almost has to be something like that causing this problem. Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106289 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 How do I echo a Query? The same as any other string. echo $sql; I'm NOT using the variable/function $sql though? Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106292 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 Your table has a field called `bidderId`, but your query string is trying to compare to a field called `bidderIds` . . . Just in case you missed this ^ ^ ^ ^ Thanks. Fixed that. Now everything just equates to "That bidder is already logged, Please press your browsers back button and try again" Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106293 Share on other sites More sharing options...
Pikachu2000 Posted September 2, 2010 Share Posted September 2, 2010 How do I echo a Query? The same as any other string. echo $sql; I'm NOT using the variable/function $sql though? Of course you are. Right here: $sql="SELECT * FROM transactions WHERE bidderIds='$winningBidder'"; $result=mysql_query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106295 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 Your table has a field called `bidderId`, but your query string is trying to compare to a field called `bidderIds` . . . Just in case you missed this ^ ^ ^ ^ Thanks. Fixed that. Now everything just equates to "That bidder is already logged, Please press your browsers back button and try again" I shouldn't be getting this far down the code if I chose 2 which is to log the bidder and redirect Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106296 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 How do I echo a Query? The same as any other string. echo $sql; I'm NOT using the variable/function $sql though? Of course you are. Right here: $sql="SELECT * FROM transactions WHERE bidderIds='$winningBidder'"; $result=mysql_query($sql); HMMMMM... This is what it spit out SELECT * FROM transactions WHERE bidderId='32' Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106297 Share on other sites More sharing options...
Pikachu2000 Posted September 2, 2010 Share Posted September 2, 2010 Thanks. Fixed that. Now everything just equates to "That bidder is already logged, Please press your browsers back button and try again" I shouldn't be getting this far down the code if I chose 2 which is to log the bidder and redirect That echo statement doesn't appear to be in any kind of conditional. In other words, it will echo no matter what happens. Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106299 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 OK...echo $sql; Displays the Bidder number I enter INTO the form, but still doesn't add the bidder Id to the database NOR does the transactions fields get data? Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106300 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 Thanks. Fixed that. Now everything just equates to "That bidder is already logged, Please press your browsers back button and try again" I shouldn't be getting this far down the code if I chose 2 which is to log the bidder and redirect That echo statement doesn't appear to be in any kind of conditional. In other words, it will echo no matter what happens. But all Conditionals are redirect with exit() so how could the last echo still display? Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106301 Share on other sites More sharing options...
Modernvox Posted September 2, 2010 Author Share Posted September 2, 2010 Just noticed when I echo $results the same resource Id displays no matter what i input for data Resource id #3 ??? What's this mean? Quote Link to comment https://forums.phpfreaks.com/topic/212324-please-tell-me-whats-wrong-with-my-form-please/#findComment-1106306 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.