UltroGames YT UltroGames YT - 3 months ago 8
PHP Question

PHP Error on if statment

I keep getting this error:


PHP Error Message

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in
/home/a6941725/public_html/php/usersystem/signup.php on line 4


Here is the code:

if (mysql_query("SELECT * FROM Main WHERE username LIKE $_POST['username']"); !== "$_POST['username']") {
$username = $_POST['username'];
}


I am normally good at php but I can't figure out why it is not working!

Answer

You should try it like,

$query = sprintf("SELECT * FROM Main WHERE username LIKE '%s'",
        mysql_real_escape_string($_POST['username']);
$result = mysql_query($query);// gives result
while ($row = mysql_fetch_array($result)) {
    if ($row['username'] !== $_POST['username']) { // remove quotes from post field
       $username = $_POST['username']; 
       break;// if both are not same then break
    }
}

Also mysql is removed in PHP 7 so use PDO or mysqli instead.