Jump to content

UPDATE SET not working


khefner

Recommended Posts

My script is working 80%, its this last part (UPDATE the database) that is proving difficult

 

The overall idea is a form that fills data into the text boxes,(from the database) then, allows the user to UPDATE changes made in the input text boxes.

 

First I connect to the database that provides a dropdown list for the user.

The user selects a itemnumber from the drop down list, and after doing so, associated data from fields in the database populate the appropriate input boxes. That all works ok

 

The submit button when pressed should UPDATE the new contents of the input text boxes into the database.

The data is not updated into the database. I  do not get a SQL error though.

The data going in to the database should be associated with the variable itemnumber.

Thanks,

Kevin


mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);

echo "<h1 align='center'>SELECT PART</h1>";
$members_list = "<select name='name' onChange='this.form.submit();'>";
$members_list .= "<option selected></option>";
$query_members = "SELECT itemnumber,description FROM parts ORDER BY itemnumber";
$result_members = mysql_query($query_members) or die("QUERY MEMBERS FAILED: ".mysql_error());
while ($line = mysql_fetch_array($result_members)) {
$itemnumber = $line['itemnumber'];
$description = $line['description'];
$members_list .= "<option value='$itemnumber'>$itemnumber ".ucwords($description)."</option>";
}
$members_list .= "</select>";

if ($_REQUEST[name]) {

$query_member_info = "SELECT * FROM parts WHERE itemnumber='$_REQUEST[name]'";
$result_member_info = mysql_query($query_member_info) or die("QUERY MEMBER INFO FAILED: ".mysql_error());
if (mysql_num_rows($result_member_info) == 1) {
	$description = ucwords(mysql_result($result_member_info, 0, 'description'));
	$itemnumber = mysql_result($result_member_info, 0, 'itemnumber');
	$code = mysql_result($result_member_info, 0, 'code');
	$timesinbom = mysql_result($result_member_info, 0, 'timesinbom');
	$activepassive = mysql_result($result_member_info, 0, 'activepassive');
	}
	echo "<form method='post' action='part_edit_4.php'>";
	echo "<table border='0' width='100%' cellspacing='0' cellpadding='8'>";
	echo "	<tr>";
	echo "					<tr>";
	echo "						<td colspan='3'><table border='0' width='100%'>";
	echo "							<tr>";
	echo "								<td >Description</td>";
	echo "								<td > <input type = 'text' name= 'description' value ='$description'></td>";
	echo "							</tr>";
	echo "							<tr>";
	echo "								<td >Itemnumber</td>";
	echo "								<td > <input type = 'text' name= 'itemnumber' value ='$itemnumber'></td>";
	echo "							<tr>";
	echo "								<td >Code</td>";
	echo "								<td > <input type = 'text' name= 'code' value ='$code'></td>";
	echo "							</tr>";
	echo "							<tr>";
	echo "								<td >Times in BOM</td>";
	echo "								<td > <input type = 'text' name= 'timesinbom' value ='$timesinbom'></td>";
	echo "							</tr>";
	echo "							<tr>";
	echo "								<td >Active/Passive</td>";
	echo "								<td > <input type = 'text' name= 'activepassive' value ='$activepassive'></td>";
	echo "							</tr>";
	echo "							<tr>";
	echo "								<td > <input type = 'submit' name= 'submit' value ='Enter'></td>";
	echo "							</tr>";
	echo "				</table></td>";
	echo "</form>";
if('submit'){ 
$result = "UPDATE parts SET description='$description',code='$code',timesinbom='$timesinbom',activepassive='$activepassive' WHERE itemnumber='$itemnumber'";
$result_update_last_report = mysql_query($result) or die("QUERY UPDATE LAST REPORT FAILED: ".mysql_error());  


}
	}		
echo "<form method='post' action='part_edit_4.php'>";
echo "<table border='0' width='50%' cellspacing='0' cellpadding='8'>";
echo "	<tr>";
echo "		<td><table border='0' width='100%' cellspacing='0'>";
echo "			<tr>";
echo "				<td width='5%'> </td>";
echo "				<td width='95%'><b>Select Part Number</b></td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td width='5%'> </td>";
echo "				<td width='95%'> </td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td colspan='2'><table border='0' width='100%'>";
echo "					<tr>";
echo "						<td width='50%' align='right' >Part Number/Description: </td>";
echo "						<td width='50%' bgcolor='#338899'>$members_list</td>";
echo "					</tr>";
echo "				</table></td>";
echo "			</tr>";
echo "		</table></td>";
echo "	</tr>";
echo "</table>";
echo "</form>";

?>
</div>
</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.