What's wrong with the code? MySQL query not correct?

<?php
const N = "\n";
if(!$mysqli = @mysqli_connect('127.0.0.1', 'root', 'password', 'site'))
 exit('Fatal error: Couldn\'t connect to MySQL DB.');
if(mysqli_num_rows(mysqli_query($mysqli, 'SHOW TABLES LIKE `users`)) == 0) {
mysqli_query($mysqli,
 'CREATE TABLE `users` ('.N.
 '`id` int(11) unsigned NOT NULL auto_increment,'.N.
 '`email` varchar(30) NOT NULL,'.N.
 '`password` varchar(32) NOT NULL,'.N.
 'PRIMARY KEY (`id`)'.N.
 ') ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'
);
}</property-->
<br / > Why is <code>mysqli_query()</code>gives out false, even though the request is valid. What's wrong?
July 4th 19 at 23:29
1 answer
July 4th 19 at 23:31
Solution
So it, telepaths are all busy. mysqli_error says that?
Nothing special:
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 "users` at line 1
- dion.Sipes commented on July 4th 19 at 23:34
Clear. Not those quotes from LIKE used. - Kenyatta commented on July 4th 19 at 23:37
: And why does this matter? I changed the quotes and now everything is OK. But what the hell? It's weird - dion.Sipes commented on July 4th 19 at 23:40
The problem is not completely solved. It is some kind of mass.. Again:
if(!$query=@mysqli_query($mysqli, "SELECT COUNT(id) FROM users WHERE email='".mysqli_real_escape_string($mysqli, $_POST['email'])."'"))
 exit('Fatal error: '.mysqli_error($mysqli));
if(mysqli_num_rows($query)>0)
 echo 'This email is already registered!<br>';

Displays "email was" though the table is empty. - dion.Sipes commented on July 4th 19 at 23:43
: Quotation marks - because in reverse inverted commas the names of tables, fields, indexes, etc. LIKE in the argument string.

And this error also just. This query will always return the result string, just COUNT(id) will be zero.

Also, don't use suppressing errors using @. Errors need to see and eliminate, not hide. - Kenyatta commented on July 4th 19 at 23:46
: on account of the LIKE clear.
On account of the following errors - so you need to check immediately
mysqli_query()>0 ? - dion.Sipes commented on July 4th 19 at 23:49
: Very simple. one row is returned, which indicates the number of selected records - 0.
Well, I would have just declared the `email` field as UNIQUE KEY, gave the command to add an entry, and then controlled mysqli_affected_rows. To follow the uniqueness easier on the base side, not the client. - Kenyatta commented on July 4th 19 at 23:52

Find more questions by tags MySQLPHPSQL