Updating inserted data

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Updating inserted data

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

With an UPDATE query?
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Post 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>";
		}
		}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:?: why don't you build the insert statement to your needs instead of chaning the record afterwards?
Post Reply