Php database problems, help .... I am a beginner in PHP and want to write a login page by myself, but now I cannot even access the verification account. Please check out what is wrong with my code.
Query ($ query) or die ("Error in the consult ..". mysqli_error ($ db); if ($ result = 1) {echo"Login successful
";} Elseif ($ result = 0) {echo"Not found
";} Echo $ _ POST [" user "]; $ dba = $ db-> affected_rows; echo $ dba; mysqli_close ($ db);?>
$ Result = $ db-> query ($ query) or die ("Error in the consult ..". mysqli_error ($ db ));
If this statement is not followed by an error, echo $ dba is followed by-1, but the account I entered is in the database.
The user123 I entered is vvvvy.
However, the Error in the consult is displayed after the web page is opened and submitted .. you have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user' WHERE 'user _ mail' = 'vvvvy' at line 1
Reply to discussion (solution)
Copy the following statement.
$query = "SELECT user_email FROM `user` WHERE user_email = '$user123'";
Two errors in your program
First, the symbols in your SQL statement are incorrect. can Fields and tables be enclosed by single quotation marks?
You can change it to $ query = "SELECT user_email FROM 'user' WHERE user_email = '$ user123 '";
Second, because the value of your $ result is either false or ID, and your judgment condition is incorrect, you do not need to be equal to 1 or 0.
Example: if ($ result ){
...
}
Else if ($ result ){
...
}
Two errors in your program
First, the symbols in your SQL statement are incorrect. can Fields and tables be enclosed by single quotation marks?
You can change it to $ query = "SELECT user_email FROM 'user' WHERE user_email = '$ user123 '";
Second, because the value of your $ result is either false or ID, and your judgment condition is incorrect, you do not need to be equal to 1 or 0.
Example: if ($ result ){
...
}
Else if ($ result ){
...
}
I have modified all of them according to your changes, but no matter whether the input is right or wrong or the display does not exist...
I Googled it and found that there is no problem with the current statements. Is there a problem with database settings? Mine is local, and wamp ~ is used ~
$ Query = "SELECT 'user _ email 'FROM 'user' WHERE 'user _ email' = '$ user123 '";
And
$ Query = "SELECT 'user _ email 'FROM 'user' WHERE 'user _ email' = '$ user123 '";
Is it the same?
$ Query = "SELECT 'user _ email 'FROM 'user' WHERE 'user _ email' = '$ user123 '";
And
$ Query = "SELECT 'user _ email 'FROM 'user' WHERE 'user _ email' = '$ user123 '";
Is it the same?
$ Query = "SELECT 'user _ email 'FROM 'user' WHERE 'user _ email' = '$ user123 '";
I changed this sentence.
$ Query = "SELECT user_email FROM 'user' WHERE user_email = '$ user123 '";
$ Query = "SELECT 'user _ email 'FROM 'user' WHERE 'user _ email' = '$ user123 '";
And
$ Query = "SELECT 'user _ email 'FROM 'user' WHERE 'user _ email' = '$ user123 '";
Is it the same?
$ Query = "SELECT 'user _ email 'FROM 'user' WHERE 'user _ email' = '$ user123 '";
I changed this sentence.
$ Query = "SELECT user_email FROM 'user' WHERE user_email = '$ user123 '";
... Why can't I edit a post ..
After I changed this sentence, no matter what I entered, it was correct?
Mysqli: query -- mysqli_query? Perform a query on the database
Return value
If the query fails, FALSE is returned. if mysqli_query () is used to successfully execute SELECT, SHOW, DESCRIBE or EXPLAIN, a mysqli_result object is returned. if other queries are used, TRUE is returned.
Therefore, the mysqli_result object is returned even if there is no SQL error in the input database. The "result set = 1" is always true, so the input is correct.
The correct method is to use it to compare the number of rows to 1.
If ($ result-> num_rows = 1) {echo"Login successful
";} Else {echo"Not found
";}
Two errors in your program
First, the symbols in your SQL statement are incorrect. can Fields and tables be enclosed by single quotation marks?
You can change it to $ query = "SELECT user_email FROM 'user' WHERE user_email = '$ user123 '";
Second, because the value of your $ result is either false or ID, and your judgment condition is incorrect, you do not need to be equal to 1 or 0.
Example: if ($ result ){
...
}
Else if ($ result ){
...
}
I have modified all of them according to your changes, but no matter whether the input is right or wrong or the display does not exist...
I Googled it and found that there is no problem with the current statements. Is there a problem with database settings? Mine is local, and wamp ~ is used ~
This is not correct either. else {...} should be used directly. do not use else if ($ result ){...}
Sort out your if judgment and check whether the executed SQL is correct.
Mysqli: query -- mysqli_query? Perform a query on the database
Return value
If the query fails, FALSE is returned. if mysqli_query () is used to successfully execute SELECT, SHOW, DESCRIBE or EXPLAIN, a mysqli_result object is returned. if other queries are used, TRUE is returned.
Therefore, the mysqli_result object is returned even if there is no SQL error in the input database. The "result set = 1" is always true, so the input is correct.
The correct method is to use it to compare the number of rows to 1.
If ($ result-> num_rows = 1) {echo"Login successful
";} Else {echo"Not found
";}
I always wanted to get the data I queried, but I didn't find the function. I didn't know English... Thank you, buddy... If you use $ result-> num_rows to check whether the account and password are insecure?