Stalingrad Posted January 19, 2013 Share Posted January 19, 2013 Hi all. I've created this simple dynamic dropdown box in PHP and MySQL. I jus twant it to update a row in my database. It is doing something very weird, and I can't figure out why... what it is doing is it will only update the newest row IF I ENTER A NEW ROW. If I try to update another row and it doesn't update, than it won't update the newer row, I'll have to create a new row. Then I can ONL update the newest row... it may sound cofusing but this is what it is doing... I've looked over the code for over 2 hours now.. I don't understand the problem here... here is my code: $oracle = $_POST['iname']; $swat = $_POST['sub']; if(!$swat) { ?> Your Items: <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <select name="iname"> <?php $getiq = "SELECT * FROM uitems WHERE username='$showusername' AND location='1'"; $geti = mysql_query($getiq); while($row = mysql_fetch_array($geti)) { $thatid = $row['theitemid']; $theid = $row['uitemid']; $catiq = "SELECT * FROM items WHERE itemid='$thatid'"; $cati = mysql_query($catiq); while($dog = mysql_fetch_array($cati)) { $toyid = $dog['itemid']; $names = $dog['name']; echo "<option value=$names>$names</option>"; } } ?> </option> <input type="submit" name="sub" value="Submit"></form> <?php } if($swat) { $fishq = "SELECT * FROM items WHERE name='$oracle'"; $fish = mysql_query($fishq); while($run = mysql_fetch_array($fish)) { $turtle = $run['itemid']; } mysql_query("UPDATE uitems SET location='2' WHERE theitemid='$turtle' AND username='$showusername' LIMIT 1") or die(mysql_error()); echo "Item has been added to your shop."; } } ?> Please note: I HAVE NOT INCLUDED MY HEADERS, ETC.. SO PLEASE DON'T GO OFF SAYING THE PROBLEM IS BECAUSE MY DATABASE ISN'T CONNECTED... BECAUSE IT IS... I JUST DIDN'T WANT MY HEADER FILES SHOWING... THANK YOU in advance for the help. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 19, 2013 Share Posted January 19, 2013 Your query is outside of your while loop. What you should do is make $turtle an array And use IN() rather than trying to update each one separately. Quote Link to comment Share on other sites More sharing options...
Barand Posted January 20, 2013 Share Posted January 20, 2013 And <select name='iname'> should have a corresponding </select>, not a </option> Plus I won't mention your ridiculous, meaningless variable names Quote Link to comment Share on other sites More sharing options...
Stalingrad Posted January 26, 2013 Author Share Posted January 26, 2013 Variable NAMES have nothing to do with how well something runs Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2013 Share Posted January 26, 2013 They do when your names make it so hard to write your own code that you keep writing bugs into it. Quote Link to comment 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.