开发者

PHP noob, creating registration system error

I am attempting to write a user registration system for my web site. I am running PHP 5 on my web server and am getting this error:

Parse error: syntax error, unexpected ';' in /nfs/.../processreg.php on line 18

Line 18:
if (mysql_num_rows($s?>0))

The rest of the code is this:

<?php

include("db.php");

if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email'])) {
    //Prevent SQL injections
    $username = mysql_real_escape_string($_POST['username']);
    $email    = mysql_real_escape_string($_POST['email']);

    //Get MD5 hash of password
    $password = md5($_POST['password']);

    //Check to see if username exists
    $sql = mysql_query("SELECT username FROM usersystem WHERE username = '".$username."'");
    if(mysql_num_rows($s?>0)) {
        die("Username taken.");
    }

 开发者_JAVA技巧   mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')") or die (mysql_error()); echo "Account created.");
}

?>

I do not understand the error because there is not a ';' at the end of this line.


if (mysql_num_rows($s?>0))

should be

if (mysql_num_rows($sql) > 0)

and....

die (mysql_error()); echo "Account created.";)

should be

die (mysql_error()); echo "Account created.";


17     if (mysql_num_rows($s?>0))

Should be something like

17     if (mysql_num_rows($sql) > 0)

The issue being that that ?> in there actually matches your opening <?php declaration. Looks like you accidentally typed that in.

You've also got an error on your last line:

mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')") or die (mysql_error()); echo "Account created.";)

This should be separated into two statements (you've got your echo statement inside the die())

mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')") or die (mysql_error()); 
echo "Account created.";


if(isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email'])) {
    //Prevent SQL injections
    $username = mysql_real_escape_string($_POST['username']);
    $email    = mysql_real_escape_string($_POST['email']);

    //Get MD5 hash of password
    $password = md5($_POST['password']);

    // or as suggested sha1
    $password = sha1($_POST['password']);

    //Check to see if username exists
    $sql = mysql_query("SELECT username FROM usersystem WHERE username = '".$username."'");
    if(mysql_num_rows($sql) > 0)) {
        echo "Username taken, try again";
    } else {
        mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( $username', '$password', '$email')") or die(mysql_error()));
        echo "Account created.";
    }
}
?>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜