Page 1 of 1

Updating inserted data

Posted: Tue Jan 23, 2007 10:57 pm
by cturner
I am wondering how I could update data that is already inserted into a database? I want the data to be updated only when a text box has something in it and to replace a database cell for each text box that has something in it after some data has been inserted into the database. Thanks in advance.

Posted: Tue Jan 23, 2007 11:10 pm
by feyd
With an UPDATE query?

Posted: Tue Jan 23, 2007 11:34 pm
by cturner
I know I have to use a UPDATE query. I will post some code here that I have been working with but isn't working for me so maybe someone can have a look at the code below and tell me why it isn't working for me. Please ignore the variables I just wanted to focus on the code that is below.

Code: Select all

$insert = "INSERT INTO `clearingsales` (`selectDay`, `selectDate`, `selectMonth`, `selectYear`, `propertyname`, `time`, `ampm`, `accountname`, `comments`, `select1`, `txt1`, `select2`, `txt2`, `select3`, `txt3`, `select4`, `txt4`, `select5`, `txt5`, `select6`, `txt6`, `select7`, `txt7`, `select8`, `txt8`, `select9`, `txt9`, `select10`, `txt10`, `select11`, `txt11`) VALUES ('$selectDay', '$selectDate', '$selectMonth', '$selectYear', '$propertyname', '$time', '$ampm', '$accountname', '$comments', '$select1', '$txt1', '$select2', '$txt2', '$select3', '$txt3', '$select4', '$txt4', '$select5', '$txt5', '$select6', '$txt6', '$select7', '$txt7', '$select8', '$txt8', '$select9', '$txt9', '$select10', '$txt10', '$select11', '$txt11')";
	if (mysql_query ($insert)) {
		if (($select1 == 'other') && (!empty($other1))) {
			$update = "UPDATE clearingsales SET select1 = '$other1' WHERE propertyname = '$propertyname'";		
		if (mysql_query ($update)) {
			header ("Location: clearing_sale_added.php");
		} else {
			print "<p>Could not update the entry because: <b>" . mysql_error() . "</b>. The query was $update.</p>";
		}
		}

Posted: Tue Jan 23, 2007 11:42 pm
by volka
:?: why don't you build the insert statement to your needs instead of chaning the record afterwards?