can someone please give me some advice on debugging and security matters.......
i am working on a script to insert data ina DB and it got me stuck on a error wich i think is being caused by the escape string or the $sql query. tried changing the order of events....without the escapestring.....and some random things but it keeps giving me:
ERROR: 1064You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(dt, username, email, pwd)values('Saturday 7 April 2012 14:11:42', '1', '2', '8'' at line 1
the code that's bugging me.....
//request data from form(method=post)
$username = htmlentities($_REQUEST['username']);
$email = htmlentities($_REQUEST['email']);
$password = htmlentities($_REQUEST['password']);
$datetime = date("l j F Y H:i:s"); //create date time
//connect db
mysql_connect("$db_host", "$db_username", "$db_password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//clean data
$res_username = mysql_real_escape_string ($username);
$res_email = mysql_real_escape_string ($email);
$res_password = mysql_real_escape_string ($password);
if (empty ($res_username) or empty($res_email) or empty($res_password) or empty($datetime)){
die ('error!');
}
//insert data
$sql="insert into $tbl_name(dt, username, email, pwd)values('$datetime', '$res_username', '$res_email', '$res_password')";
$result=mysql_query($sql);
if (!$result){
die('ERROR: ' . mysql_errno() .mysql_error());
}
mysql_close();
what's going wrong here?
can someone give me advice on how to deal with issues like this?
is this a good way to add db security? do i need to request htmlentities AND a mysql escape string?
thanks Roll!
Edited by Rollins, 07 April 2012 - 12:52 PM.












