0
MySQL query not working but the database is connected . This is the code
if( !empty($lastname) && !empty($firstname) && !empty($emailaddress) && !empty($password) && is_numeric($phonenumber) && !empty($phonenumber) && empty($password2)){ //if errors free $password_encrypt = md5($password); $query = "INSERT INTO `users`(`user_id`, `firstname`, `lastname`, `password`, `email`, `phone_num`) VALUES ('NULL', '".mysqli_real_escape_string($firstname)."', '".mysqli_real_escape_string($lastname)."', '".mysqli_real_escape_string($password_encrypt)."', '".mysqli_real_escape_string($emailaddress)."', '".mysqli_real_escape_string($phonenumber)."')"; if($run_query = mysql_query($query)){ echo"<h1>Thank You</h1>"; }else{ echo mysql_error(); }
9 Respostas
+ 4
Adetunji Adetomiwa Make sure $password2 is actually empty? That is the only expression in the conditional statement expecting the value to be empty.
Or... perhaps you are expecting a value for $password2 and the expression should be preceeded with an [!] sign.
+ 4
Also, verify the $phonenumber variable is being posted only with numeric values, such as, 1234567890.
Phone numbers containing formatted values like below will all also fail the is_numeric() check.
(123) 456-7890
123-456-7890
123.456.7890
+ 4
Adetunji Adetomiwa What was the actual fix that worked?
+ 4
Adetunji Adetomiwa Nice... I'm glad we were able to isolate the issue without access to the actual code and reviewing only a snippet of code without knowledge of the POST data. 😉
+ 2
Can you elaborate on the error message to be clear?
Did you mean to escape the password before you apply MD5 hash into it; the way you're doing it now, you are escaping an already hashed password ($password_encrypt).
$password_encrypt = md5(mysqli_real_escape_string($password));
+ 2
maybe the last statement ? the query execution part.
its mysql_query instead of mysqli_query. same with mysql_error
+ 2
David,
I was wondering if there were 2 password input, one for password and another for confirmed password, in this case $password and $password2 should be checked for equality (being exactly similar) rather than having $password2 be empty. But OP has the answer : )
+ 2
Thanks guys. Your suggestions really worked. Thanks
+ 2
David Carroll .The is_numeric was the actual problem