Home  >  Article  >  Backend Development  >  新手半夜求解:Unknown column 'qq' in 'field list'如何解决

新手半夜求解:Unknown column 'qq' in 'field list'如何解决

WBOY
WBOYOriginal
2016-06-13 13:35:571558browse

新手半夜求解:Unknown column 'qq' in 'field list'怎么解决
这个是我自己练习的时候遇到的问题,新手,别笑话...

这个是建表的代码:
$con=@mysql_connect('localhost','root','123');
if($con)
{
mysql_select_db("employee",$con);
$sql="CREATE TABLE personal_data
(
id int(5) not null auto_increment primary key,
name char(10) not null,
qq char(16) not null,
tel char(14) not null,
email char(20) not null,
social_security char(22) not null,
postcode char(15) not null,
home_add char(26) not null,
home_tel char(14) not null,
residence_registration char(10) not null,
nation_place char(14) not null
)";
$do=mysql_query($sql,$con);
if($do)
{
echo "成功在employee数据库中创建用户表!";
}
else echo "建表有错误...";
}
else
{
echo "连接错误";
}
?>


因为分不是很清楚int 和 char 的区别,所以都是用 char 。



这个是deal的代码:
echo " ";
if($_POST)
{
$name=$_POST["name"];
$qq=$_POST["qq"];
$tel=$_POST["tel"];
$email=$_POST["email"];
$social_security=$_POST["social_security"];
$postcode=$_POST["postcode"];
$home_add=$_POST["home_add"];
$home_tel=$_POST["home_tel"];
$residence_registration=$_POST["residence_registration"];
$nation_place=$_POST["nation_place"];


$con=mysql_connect("localhost","root","123");
mysql_select_db("employee");
mysql_query("SET NAMES GB2312");
$sql="SELECT COUNT(*) FROM personal_data WHERE name='$name'";

$result=mysql_query($sql);
$num=mysql_fetch_row($result);
if($num[0]>0)
{
echo "存在同名用户,重新输入用户名!";
}
else
{
$sql="INSERT INTO staff_information(name,qq,tel,email,social_security,postcode,home_add,home_tel,residence_registration,nation_place) VALUES ('".$name."','".$qq."','".$tel."','".$email."','".$social_security."','".$postcode."','".$home_add."','".$home_tel."','".$residence_registration."','".$nation_place."')";
$re=mysql_query($sql)or die(mysql_error());
if($re) echo "成功插入记录!";
else echo "插入记录失败!";
echo "

";
}
}
else
{
echo "没有提交内容!
";
}
echo "
这里返回";
?>



大学里的新手,研究了几个小时了,百度谷歌了好久都解决不了,希望有高手可以帮我,万分感谢。

------解决方案--------------------
1.int 是整数类型 char 是字符类型 现在一般使用varchar
int:从 -2^31 (-2,147,483,648) 到 2^31 - 1 (2,147,483,647) 的整型数据(所有数字)。存储大小为 4 个字节
char 和varchar:CHAR列的长度固定为创建表时声明的长度。长度可以为从0到255的任何值。当保存CHAR值时,在它们的右边填充空格以达到指定的长度。当检索到CHAR值时,尾部的空格被删除掉。在存储或检索过程中不进行大小写转换。
VARCHAR列中的值为可变长字符串。长度可以指定为0到65,535之间的值。(VARCHAR的最大有效长度由最大行大小和使用的字符集确定。整体最大长度是65,532字节)。

2.qq 这个字段在数据库里不存在


------解决方案--------------------

SQL code
CREATE TABLE personal_data
(
id int(5) not null auto_increment primary key,
name char(10) not null,
qq char(16) not null,
tel char(14) not null,
email char(20) not null,
social_security char(22) not null,
postcode char(15) not null,
home_add char(26) not null,
home_tel char(14) not null,
residence_registration char(10) not null,
nation_place char(14) not null
)
<br><font color="#e78608">------解决方案--------------------</font> <div class="clear">
                 
              
              
        
            </div>
Statement:
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