开发者

SQL error: query empty

mysql_select_db("musicDB", $con);

$sql = mysql_query("INSERT INTO Users (username, fname, lname, email, dob, password, occupation, genre )
VALUES ('$_POST[username]', '$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[dob]', sha1('$_POST[password]'), '$_POST[occupation]', '$_POST[genre]')");

if (!mysql_query($sql,$con))
{
    die('Error: ' . mysql_error());
}
echo "1 record added";
?>

I am new 开发者_如何学Cto PHP and I am getting this SQL error:

The query is empty.

What am I doing wrong?


$sql = mysql_query("INSERT INTO Users (username, fname, lname, email, dob, password, occupation, genre )
VALUES ('$_POST[username]', '$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[dob]', sha1('$_POST[password]'), '$_POST[occupation]', '$_POST[genre]')");

if (!sql)
{

is correct one. You were trying to do

if(!mysql_query(mysql_query("....")))
{


mysql_select_db("musicDB", $con);

// that's dirty but at least something to protect that silly code
$_POST['password'] = sha1($_POST['password'].$_POST['username']);
foreach($_POST as $key => $value) $_POST[$key] = mysql_real_escape_string($value);

$sql = "INSERT INTO Users (username, fname, lname, email, dob, password, occupation, genre )
        VALUES ('$_POST[username]', '$_POST[fname]', '$_POST[lname]', '$_POST[email]',
                '$_POST[dob]', '$_POST[password]', '$_POST[occupation]', '$_POST[genre]')");

if (!mysql_query($sql,$con))
{
    trigger_error(mysql_error()." ".$sql);
} else {
    echo "1 record added";
}
?>


when declaring the string query variable, dont use $sql = mysql_query(...); just simply $sql = "..."; and it should work fine

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜