Jump to content

PHP MySQL Dynamic Dropdown box not working right?...


Stalingrad

Recommended Posts

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. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.