in as one of the first lines and see what error it gives.
Just a note, none of the data is being escaped; this means that I could submit a MySQL command like "DROP TABLE", and the entire database/table would be wiped clean. This code is very poorly written and I would advise you to steer clear of any code written by this author/site.
Right first off, there is no legitimate reason for wrapping your variables in double quotes when passing into a function (for example your mysql_connect etc), all it does is make php do extra work for no apparent reason.
Secondly you don't call mysql_query at any point in your script, mysql can't read your mind.
Also in your sql, there is no need to escape the single quotes if the string is wrapped in doubles
heres a more or less cleaned version:
<?php $host = 'localhost'; // Host name $username = 'xx'; // Mysql username $password = 'xx'; // Mysql password $db_name = 'xx'; // Database name $tbl_name = 'test_mysql'; // Table name
// Connect to server and select database. mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db($db_name)or die("cannot select DB");
// update data in mysql database $sql = "UPDATE " . mysql_real_escape_string($tbl_name) . " 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) . "'";
// Set some default data. $name = 'John'; $lastname = 'Doe'; $email = 'email@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.
No i forgot the php tags.. Sorry..
Now have put the tags in then it goes to a blank page when i press submit. No errors nothing.. The database is still not updated. Should i not tell the script what tabel in the database it should update.