How PHP extracts data

Source: Internet
Author: User
How PHP extracts data // Receive data
// Use post for form verification
$ Conn = mysql_connect ('localhost', 'root', 'wampp ');
If (! $ Conn)
{
Echo "database connection failed". mysql_error ();
}
Else
{
Echo "database connection successful ";
}

// Set the encoding
// Double quotation marks are used.
Mysql_query ("set names 'gbk'") or die (mysql_error ());

// Select a database
Mysql_select_db ('ploy', $ conn) or die ("The cause of the error is". mysql_error ());

$ Id = $ _ POST ['id'];
$ Pwd = $ _ POST ['pwd'];


// Use the database for verification ,,
// Database statement
$ SQL = "select * from admin where id = $ id ";
// Database execution statement
$ Result = mysql_query ($ SQL, $ conn)

// Retrieve the associated array and the password corresponding to the ID number

If ($ row = mysql_fetch_array ($ result ))

{// Query the database and retrieve the database password
If ($ row ['pwd'] = $ pwd)
{

$ Name = $ row ['name'];
Header ("Location: manage. php? Name = $ name ");
Exit ();
}
}
Header ("Location: login. php? Error = 1 ");
Exit ();

?> The above is the code. this is the page code for processing user login. if ($ row = mysql_fetch_assoc ($ result) at runtime, there is no error in the database connection, always report an error. please answer


Reply to discussion (solution)

What is the error?
If the syntax is incorrect
$ Result = mysql_query ($ SQL, $ conn );
If the data type is incorrect
$ Result = mysql_query ($ SQL, $ conn) or die (mysql_error ());

Screenshot to see what is wrong

Post an error,

Incorrect IDE selection

The last and second if brackets are included in the final try

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.