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
?>