PHP向数据表出入数据出有关问题!求解

WBOY
Release: 2016-06-13 13:03:34
Original
817 people have browsed it

PHP向数据表出入数据出问题!求解
代码:

创建数字库数据表代码:
error_reporting(0);                                  //禁止错误的输出
$link = mysql_connect('localhost:3306','root','');   //建立连接
if(!$link) {
die('连接MySQL服务失败:'.mysql_error());
}
echo '连接MySQL服务成功!';
if(mysql_query("CREATE DATABASE xiaomai",$link))
{
echo "创建数据表成功!";
}
else {
echo "创建数据表失败!";
}
mysql_select_db("xiaomai",$link);
$sql ="CREATE TABLE student
(
name varchar(15),
size int,
heigh int)";
mysql_query($sql,$link);
echo "

创建数据表成功!";
mysql_close($link);
?>
运行时没有任何错误!



向数据表插入数据的代码:
表单数据插入



if ($_GET['act'] == 'insert') {
error_reporting(0);
$link = mysql_connect('localhost:3306','root','');   //建立连接
if(!$link) {
die('连接MySQL服务失败:'.mysql_error());
}
mysql_select_db("xiaomai",$link);
mysql_query("INSERT INTO student (name, size, heigh) VALUES ('".$_POST['name']."', '".$_POST['size']."',
'".$_POST['heigh']."')");

echo "

插入数据成功!";
mysql_close($link);
die();
}
?>





















姓名:
体重:
身高:
 



 在主界面有错误提示!但可以向数据表插入数据!

我输入的数据是: 我的名字 116  170  ,数据表却显示为: ?óè?D?  116  170

是什么原因呢?
------最佳解决方案--------------------
既然有错误提示,为什么不贴出来呢

mysql_query("set names gbk"); //插入前执行这句
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!