PHP help me to see, receive this file 16, 17 line where error, register the same user name he gave an error

Source: Internet
Author: User
Tags dsn
register.php




<title>Registered</title>





Sign In | register

Welcome to Register



User name:


Secret code:


Confirm Password:


Mail box:
Placeholder= "Please enter the correct email format" name= "email" >



Verification Code:



Require (' yzm.php ');
?>



I have read and agree to the agreement
"Book" clause







receive.php

if (Isset ($_post[' submit ')) {
Session_Start ();
$checkstr = $_session[' Yzm '); Use the $_session variable to get the verification code on the 03.php page
$str = $_post[' Check ']; User-entered string
if (strcasecmp ($STR, $checkstr)! = 0)//case-insensitive comparison
echo "";
else {
$username = $_post["username"];
$password = $_post["PSW1"];
$email = $_post["email"];
$DSN = "Mysql:host=localhost;dbname=book";
$db =new PDO ($dsn, ' root ', ' 123456 ');
$db->query (' Set names UTF8 ');
16 rows: $chkusername = mysql_query ("Select username from register where username=". $username. ");
17 rows: $numrow = mysql_num_rows ($chkusername);
if ($numrow! = 0) {
Print ("

");
}
else {
$sql = "INSERT into register (username,password,email) VALUES (?,?,?)";
$stmt = $db->prepare ($sql);
$stmt->bindparam (1, $username);
$stmt->bindparam (2, $password);
$stmt->bindparam (3, $email);
$stmt->execute ();
$_session[' username '] = $username;
Print ("

");
}
}
}
else echo "illegal access";
?>


Reply to discussion (solution)

This is how you connect to the database.
$DSN = "Mysql:host=localhost;dbname=book";
$db =new PDO ($dsn, ' root ', ' 123456 ');
$db->query (' Set names UTF8 ');
And then you do it.
16 rows: $chkusername = mysql_query ("Select username from register where username=". $username. ");
17 rows: $numrow = mysql_num_rows ($chkusername);
Do you think it would be appropriate to do so?

The SQL statement also needs to be changed, unless your username is a number, you need to add a single quotation mark

$sql = "Select username from register where username = ' {$username} '";

Link PDO is used with native

17 line How to change, who can give a changed 16 line, 17 line out to me to see

Finally changed the good!

You're using the PDO connection. Executing SQL with native methods is bound to go wrong.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.