Jump to content

Update Mysql using result from drop down box <select>


andyjcurtis

Recommended Posts

I am trying to update a mysql table called AvItems with the value 'Torso' in the Equip "section?" I have been through the forums and cannot see anything to match.

I dont mind if the page looses the onsubmit() and has a button instead.

Though I would like to update the database and link back to the same page: There is a display that shows the item that is currently equiped, I have put this in to show it works, or doesn't as the case may be.

Hope I got the code /code right this time.

 

many thanks in advance

 

Andy Curtis

 

create table Items( 
ItemID integer unsigned auto_increment primary key,
ItemName varchar(20) not null,
Type varchar(10), 
UsedOn varchar(10),
);

create table AvItems(
AvItemID integer unsigned auto_increment primary key,
AvID integer unsigned,
ItemID integer unsigned,
Equip varchar();


<?php

$username="root";
$password="MyPassword";
$database="MyDataBase";
$AvName = "AndyJCurtis";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$AvAccR = mysql_query( " SELECT AvID FROM AvAcc WHERE AvName = '$AvName' " );	
$AvID = mysql_result($AvAccR, 0, 'AvID');
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$Torso = mysql_query(" select ItemName from AvItems, Items where AvItems.itemID = Items.itemID AND AvItems.AvID = '$AvID' AND UsedON = 'Body' ");
$TorsoE = mysql_query(" select ItemName from AvItems, Items where AvItems.itemID = Items.itemID AND AvItems.AvID = '$AvID' And UsedON = 'Body' AND Equip = 'Body' ");
if(mysql_num_rows($TorsoE) != 0)
{
$TorsoItem = mysql_result($TorsoE ,0,"ItemName");
//mysql_close();	
?>

<title></title>
<head></head>
<body>
<form action="http://localhost/CI/Equip2.php" method="post">

<table border=1>
<tbody>
	<tr>		
		<td>Torso<BR>
		<?PHP
			echo "$TorsoItem <BR>";
		?>
		<select name="Torso" onchange="submit();" value =" Update">
		<?PHP
			while($TorsoRow = mysql_fetch_array($Torso))
			{
				echo "<option value=\"".$TorsoRow['ItemName']."\">".$TorsoRow['ItemName']."\n </option>";
			}
		?>
		</select>
		</td>
	</tr>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		<?php
		if($_POST['Torso'] == 'Update')
		{
		mysql_query("update AvItems set Equip = '' where Equip='Torso'") or die("cant update unequip"); 
		mysql_query("update AvItems set Equip = 'Torso' where ItemID='{$_POST['ItemName']}'") or die("cant update equip"); 
		}
		?>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

</tbody>
</table>
</.form>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.