Re: overwriting new information in a table
| From: | Miles Thompson | Date: | Sun, 02 Dec 2001 22:04:26 +0000 |
| Subject: | Re: overwriting new information in a table | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-14746@lists.php.net to get a copy of this message | ||
Take out the extraneous bracket!
Should be: $sql = "update my_contacts set fname='$fname', name='$lname' where id=$id";
At 05:52 PM 12/2/2001 -0400, Miles Thompson wrote:
Kevin, There a couple of good tutorials on this sort of thing at http://www.thickbook.com. Well worth a visit. I've plucked your shorter example out and re-written it this way: $sql = "update my_contacts set fname='$fname', name='$lname' where id=$id"); Note the single quotes around the $fname and $lname fields. They are most likely char types and need the quotes. I didn't know what type id was, so I left it plain. This lets you see what your query looks like for debuggin by issuing this: echo $sql; You execute it this way: $result = mysql_query( $sql, $connection); (you can the or die with mysql_error() if you wish) On the INSERT, just use simple quotes around your char fields, echo the $sql to see what you are getting, and don't be surprised when it's something really trivial. I've often had a bad hour or t wo before supper, then come back downstairs and spotted the missing/extra comma, closing bracket or whatever. HTH - Miles Thompson REALLY RECOMMEND those Julie Meloni tutorials at thickbook. Succinct and to the point. /mt At 04:27 PM 12/2/2001 -0500, Kevin Ruiz wrote:I'm working on an application that will allow resellers to log into the site and see their potential buyers. When they log in they see their potential buyers and by clicking a link they will get more detailed information about their contacts. They will also have a link to update their clients listings. As of now I have this set up like this... A person logs in and sees their contacts. If they click the update link they are takent to a page that lists their contact information. I've put the respected variables in the "value" attributes of the input tags. I want to make this process as easy as possible. I dont' want them to have to update every field if they just want to change a contact's phone number. Here's the problem...when they click the button to send the changes they still see their old information. I know that this is because I've set the value to their old variables. Does anyone know a way to get their old input in as the variable value and to still be able to see their new information on the next page. I also want this information to overwrite any existing record based on the potential contact's id. The sql section of the code I have looks like this:-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net$sql = "INSERT INTO $table_name (id, contactid, fname, lname, title, cnl, address1,address2, city, state, postcode,country, phone, cell, fax, emailnl, smanager,percomplete, nfud, exrevenue, wl, cwl)VALUES (\"\", \"$contactid\", \"$fname\", \"$lname\",\"$title\", \"$cnl\", \"$address1\", \"$address2\", \"$city\", \"$state\",\"$postcode\", \"$country\", \"$phone\", \"$cell\", \"$fax\", \"$emailnl\", \"$smanager\",\"$percomplete\", \"$nfud\", \"$exrevenue\", \"$wl\", \"$cwl\")";$result = @mysql_query($sql,$connection) or die("Couldn't execute query.");I know this doesn't overwrite each entry. I've also tried something like this:$sql = mysql_query("update my_contacts set fname=$fname,lname=$lname where id=$id"); Whenever I would try to run that query I would get an error back saying I couldn't execute that query. If anyone has any ideas I would be more than grateful. Thanks for your time. I'm new to the php/mysql world so if I didn't provide enough relevant code let me know. Thanks. Kevin -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net