can't update database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
justinb
Forum Newbie
Posts: 11
Joined: Fri Dec 06, 2002 12:11 am

can't update database

Post by justinb »

Hello,
I am trying to write an update script, this script is a reused script tht I've used for another db and it works there, but not here. I have allready created and add entry and delete entry with similar code
$table_name = business (name of table)
$id is variable that sends the table primary key from other page, i have a table at bottom of page that shows what is updated, And it has all the correct info, and says it was successful, but when I go back and check, it didn't update


$db = @mysql_select_db("$db_name", $connection) or die("Error2 - Couldn't connect - try again later");

$sql = "UPDATE $table_name

SET
catID = '$catID',
busName = '$busName',
busOwner = '$busOwner',
busAd = '$busAd',
busCity = '$busCity',
busPostal = '$busPostal',
busPhone = '$busPhone',
busPhone2 = '$busPhone2',
busFax = '$busFax',
busUrl = '$busUrl',
busEmail = '$busEmail',
busLogo = '$busLogo',
featured = '$featured',
keyWords = '$keyWords',
busDesc = '$busDesc'
WHERE busID = '$id'
";



$result = @mysql_query($sql, $connection) or die("Error3 - Couldn't connect - try again later");


?>
User avatar
qiangxd
Forum Newbie
Posts: 8
Joined: Thu Dec 05, 2002 6:00 pm

Post by qiangxd »

$result =mysql_query($sql, $connection) or die(mysql_error());


?>
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Re: can't update database

Post by f1nutter »

It might be a typo, but you need to remove the quotes from around $db_name.
justinb wrote: $db = @mysql_select_db("$db_name", $connection) or die("Error2 - Couldn't connect - try again later");
You also say that "it has all the correct info, and says it was successful, but when I go back and check, it didn't update". What is displaying the info and how?. What do you go back and check?

Use phpMyAdmin to look at the database. That will tell you exactly what is in your db, you can also check your query by running it directly from phpMyAdmin without going through a browser.
Post Reply