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(); }

5th May 2019, 6:52 AM
Adetunji Sulaimon Tomiwa
Adetunji Sulaimon Tomiwa - avatar
9 ответов
+ 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.
5th May 2019, 7:28 AM
David Carroll
David Carroll - avatar
+ 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
5th May 2019, 7:33 AM
David Carroll
David Carroll - avatar
+ 4
Adetunji Adetomiwa What was the actual fix that worked?
7th May 2019, 5:16 PM
David Carroll
David Carroll - avatar
+ 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. 😉
7th May 2019, 5:42 PM
David Carroll
David Carroll - avatar
+ 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));
5th May 2019, 7:09 AM
Ipang
+ 2
maybe the last statement ? the query execution part. its mysql_query instead of mysqli_query. same with mysql_error
5th May 2019, 7:12 AM
Taste
Taste - avatar
+ 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 : )
5th May 2019, 7:41 AM
Ipang
+ 2
Thanks guys. Your suggestions really worked. Thanks
7th May 2019, 4:30 PM
Adetunji Sulaimon Tomiwa
Adetunji Sulaimon Tomiwa - avatar
+ 2
David Carroll .The is_numeric was the actual problem
7th May 2019, 5:19 PM
Adetunji Sulaimon Tomiwa
Adetunji Sulaimon Tomiwa - avatar