PHP to data table Access data out of the problem! Solving
Code:
To create a digital library data table code:
error_reporting (0); Suppress incorrect output
$link = mysql_connect (' localhost:3306 ', ' root ', '); Establish a connection
if (! $link) {
Die (' connection to MySQL service failed: '. mysql_error ());
}
echo ' Connect MySQL service successfully! ';
if (mysql_query ("CREATE DATABASE Xiaomai", $link))
{
echo "created the data table successfully!" ";
}
else {
echo "Failed to create data table!" ";
}
mysql_select_db ("Xiaomai", $link);
$sql = "CREATE TABLE student
(
Name varchar (15),
Size int,
Heigh int) ";
mysql_query ($sql, $link);
echo "
Create data table successfully! ";
Mysql_close ($link);
?>
There are no errors at run time!
Code to insert data into the data table:
form data Insertion
if ($_get[' act '] = = ' Insert ') {
error_reporting (0);
$link = mysql_connect (' localhost:3306 ', ' root ', '); Establish a connection
if (! $link) {
Die (' connection to MySQL service failed: '. mysql_error ());
}
mysql_select_db ("Xiaomai", $link);
mysql_query ("INSERT into student (name, size, Heigh) VALUES ('". $_post[' name '). "', '". $_post[' size '. "',
' ". $_post[' Heigh ')."
echo "
Insert data Successfully! ";
Mysql_close ($link);
Die ();
}
?>
Error message on the main interface! But you can insert data into the data table!
The data I entered is: My name is 116 170, the data table is shown as:? Ó???? 116 170
What is the reason?
------Optimal Solution--------------------
Since there is a mistake, why not post it?
mysql_query ("Set names GBK"); Execute this sentence before inserting