mysql - PHP login code error with mysql_query() -


i've been following login system tutorial. can find here. there 2 parts of coding c# , php. c# part working fine php part returning error. here php code:

<?php      $servername = getenv('ip');     $username = getenv('c9_user');     $passwordp = "";     $database = "game_database";     $dbport = 3306;      // create connection     mysql_connect($servername, $username, $passwordp, $dbport)or die("cant connect server");     mysql_select_db($database) or die("cant connect database");     // check connection   $email = $_request["email"]; $password= $_request["password"];  if (!$email || !$password){     echo"email or password must used"; } else{     $sql = "select * 'users' email = '"  . $email ."'";     $result_id = @mysql_query($sql) or die("database error");     $total = mysql_num_rows($result_id);     if ($total){         $datas = @mysql_fetch_array($result_id);         if (strcmp($password, $datas["password"])){                     $sql2 = "select characters users email = '" . $email ."'";                     $result_id2 = @mysql_query($sql2) or die("database error!!!");                     while ($row = mysql_fetch_array($result_id2)){                         echo $row ["characters"];                         echo ":";                         echo "success";                     }         }         else{             echo "wrongpassword";         }         }else {             echo "namedoesnotexist";         }     }  ?> 

it seems error comes $result_id i'm not sure?

you true, error $result_id, because sql statement has problem , there stuff fix.

you have put users table in 2 single quotes, wrong.

your code is:

$sql = "select * 'users' email = '"  . $email ."'"; 

it should out quotes:

$sql = "select * users email = '"  . $email ."'"; 

you have wrote:

if ($total){ 

it should check how many users record found, typically should find 1 record , return 1, therefore change to:

if ($total == 1){ 

note1: when said, not mean code perfect, should further develop code fulfill nowadays requirement. suggest think of password hashing, use mysqli or pdo in sted of mysql , input sensitization. suggest @ link describes of things mentioned.

note2: able write total solution mysqli/pdo etc, wanted point errors have catch far in code can learn mistakes , develop self.

and in general read security principles, check page.

link1: http://www.wikihow.com/create-a-secure-login-script-in-php-and-mysql

link2: https://www.owasp.org/index.php/category:owasp_top_ten_project


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -