
Originally Posted by
justlukeyou
This is the error part, I just need to sort this out.
Code:
password = MD5("' . mysql_real_escape_string($registerPassword) . '");
date_registered = "' . date('Y-m-d H:i:s') . '"';
Further to @Cups post this is the way I simplify SQL statements (which have first been tried and tested using "http://localhost/phpmyadmin/" )
An SQL statement is always a string and can be echoed first to ensure the string is valid.
Source:
PHP Code:
if(1) // DEBUG: replace 1 with 0 to try with real values
{
$registerPassword ='123456';
$registerEmail ='joe-bloggs@email.com';
$firstname ='Josephine';
$surname ='Bloggs';
$password ='Q-123456';
$password = md5($registerPassword);
}
echo '<pre>'; // DEBUG: retains line-feeds
echo $sql =
"
INSERT INTO users
(
email
, firstname
, surname
, password
, date_registered
)
VALUES
(
'". mysql_real_escape_string($registerEmail) ."'
, '" . $firstname ."'
, '" . $surname ."'
, '" . $password ."'
, '" . date('Y-m-d H:i:s') ."'
)
";
echo '</pre>'; // DEBUG: retains line-feeds
// $query = mysql_query($sql);
<hr />
Output:
INSERT INTO users
(
email
, firstname
, surname
, password
, date_registered
)
VALUES
(
'joe-bloggs@email.com'
, 'Josephine'
, 'Bloggs'
, 'e10adc3949ba59abbe56e057f20f883e'
, '2012-09-24 05:55:44'
)
Once the SQL is doing what I want it to do then all echo statements are REMMED.
To save a fraction of a millisecond the line-feeds could removed.
Bookmarks