Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL syntax error with PHP
    primarykey
    data
    text
    <p>I'm having a problem with MySQL 5.5.24 and PHP 5.4.3. I have the following HTML/PHP Code:</p> <pre><code>&lt;?php function connect() { $con = mysql_connect( "127.0.0.1", "root", "" ); if ( !$con ) { die( "Could not connect: " . mysql_error() ); } mysql_select_db( "game" ); } function protect( $string ) { return mysql_real_escape_string( strip_tags( addslashes( $string ) ) ); } if ( isset( $_POST[ 'register' ] ) ) { connect(); $username = protect( $_POST[ 'username' ] ); $register = mysql_query( "SELECT 'id' FROM 'user' WHERE 'username'='$username'" ) or die( mysql_error() ); if ( mysql_num_rows( $register ) &gt; 0 ) { echo "That username is already in use!"; } else { $ins = mysql_query( "INSERT INTO 'user' ('username') VALUES ('$username')" ) or die( mysql_error() ); echo "You have registered!"; } } ?&gt; &lt;form action="register.php" method="POST"&gt; Username: &lt;input type="text" name="username"/&gt;&lt;br/&gt; &lt;input type="submit" name="register" value="Register"/&gt; &lt;/form&gt; </code></pre> <p>Whatever I input, MySQL will always return </p> <pre><code>"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 'username'='XXX'' at line 1" </code></pre> <p>I checked these queries with phpmyadmin and they work just fine! There is also no connection problem. I even tried plain <code>"SELECT * FROM 'user'"</code> with the same result. I simply do not get any response, just the mentioned error about malformed SQL syntax.</p> <p>Now I checked tons of articles having the same error and in each case the problem was having used a keyword of PHP or missing/mispelling a variable name and that kind. I checked my statements a hundred times now and I can't find any error. I'm quiet new to PHP so maybe I miss something...</p> <p>One of my last experiments was changing the collation of the database as well as the storage engine, also with no result...</p> <p>Hope you guys see what I can't! :-)</p> <p>BTW, I'm running Windows 7 and WAMP 2.2.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload