PHP connection to the database, how to resolve

Source: Internet
Author: User
PHP Connection Database
/**************denglu.php****************/
Session_Start ();
$username =$_post[' username '];
$password =$_post[' password '];
@ $db = mysql_connect (' localhost ', ' root ', ' root '); Connecting to a database
if (! $db) {
Die (' Could not connect: '. Mysql_error ());
}
Echo ' Connection is successful! ';
mysql_select_db (' WWJ '); Select Database File WWJ
Execute SQL statement
mysql_query ("Set names UTF8");//The database is UTF8, there is no "-". Web page!!
$sql = "SELECT * from Pre_common_member where username= $username";
$res =mysql_query ($sql);
if ($row =mysql_fetch_assoc ($res)) {
if ($row [' Password ']==md5 ($password)) {
$name = $row [' username '];
echo "";
Session_register (' $name ');
Header (' Location:ClassWeb.php '); exit ();
}
}
echo "";
Header (' Location:ClassWeb.php '); exit ();
Mysql_free_result ($res);
?>
I entered the password of the account is correct, but the message is garbled, I do not know whether the login success or error, the prompt window appears, I clicked OK, the second warning error appears!!!! Error:
WARNING:MYSQL_FETCH_ASSOC (): supplied argument is not a valid MySQL result resource in F:\Apache HTTP server\appserv\www\ classweb\denglu.php on line 15

Warning:cannot Modify header Information-headers already sent by (output started at F:\Apache HTTP server\appserv\www\c lassweb\denglu.php:15) in F:\Apache HTTP server\appserv\www\classweb\denglu.php on line 24
------to solve the idea----------------------
$sql = "SELECT * from Pre_common_member where username='$username'";
------to solve the idea----------------------
The pop-up window is garbled because your program files are not utf-8.
The error message is because you are
Header (' Location:ClassWeb.php ');
Front output
echo "";
------to solve the idea----------------------
Sample PHP Connection Database display
Database Connection Conn.php Page
$conn =mysql_connect ("localhost", "root", "root");//Connect to the database server
mysql_select_db ("Db_forumm", $conn);//connect the specified database
mysql_query ("Set names gb2312");//convert the encoding format in the database to avoid the problem of Chinese garbled characters
?>
Feature page display data

$TB _forum_name=$_session["tb_forum_name"];//record user name
if ($TB _forum_name== "") {
echo "";//Login control
Exit
}//codego.net/tags/4/1/
$sql =mysql_query ("select * from Tb_forum_user where tb_forum_name= '". $TB _forum_name. "'", $conn);
$info =mysql_fetch_array ($sql);//Select database data
?>



  • 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.