View Single Post
Old 11-09-2009, 10:51 PM   #13 (permalink)
adamdecaf
The Addict
 
adamdecaf's Avatar
 
Join Date: May 2009
Posts: 309
Thanks: 5
adamdecaf is on a distinguished road
Default

PHP Code:
// Take this out when you're ready to make the code live.
error_reporting(E_ALL);

// Connect to server and select database.
$hostname 'CHANGE ME';
$username 'CHANGE ME';
$password 'CHANGE ME';
$database 'CHANGE ME';

$link mysql_connect($host$username$password) || die(mysql_error());
// mysql_select_db($database, $link)or die(mysql_error());

// Set some default data.
$name 'John';
$lastname 'Doe';
$email 'user@example.com';
$id 123145;

// update data in mysql database
$sql "UPDATE " $database .
       
" SET name='" mysql_real_escape_string($name) .
       
"', lastname='" mysql_real_escape_string($lastname) .
       
"', email='" mysql_real_escape_string($email) .
       
"' WHERE id='" mysql_real_escape_string($id) . "'";

$result mysql_query($sql$link); 
Ok, wow, I was stupid and escaped $db_name. This will cause MySQL to try to update the data into a nonexistence/new database. Sorry!!

I would recommend the code in the post above me (sketchMedia's), or use this code, it's just easier for me to read. I was going through the code trying to fix any mundane bug and I found that I was escaping the table name.
__________________
My Site
adamdecaf is offline  
Reply With Quote