源代码如下: 最后说是成功输入了,但是数据库里面却没有内容
我验证过了,表单上面是有内容的,就是$name等里面东西是有的,但是就是不能写到数据库里面
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>留言处理</title>
</head><body>
<p align=center>[留言本]</p>
<?php 
$dbhost="localhost";//主机地址 
$dbnanme="dowebs"; //数据库名字 
$dbusername=""; //dbuser 
$dbpassword=""; //数据库口令 
$name=htmlspecialchars(trim($name)); 
$mail=htmlspecialchars(trim($mail)); 
$host=htmlspecialchars(trim($host)); 
if($host=="http://"){$host="";} 
$title=htmlspecialchars(trim($title)); 
$text=htmlspecialchars(trim($text)); 
$errormsg=""; 
if($name=="") 
{$errormsg="请输入您的大名!";} 
else{ 
if($title==""and $text=="") 
{$errormsg="请输入您的主题或内容";} 
else 

if($title==""){$title="无主题";} 
if($text==""){$text="无内容";} 
$db=mysql_connet($dbhost,$dbusername,$dbpassword); 
mysql_select_db($dbname,$db); 
$sql="insert into dat (name, mail host ,title,text addtime attrib) values ('$name','$mail','$host','$title','$text',NOW(),1)"; 
$result=mysql_query($sql); echo("<center>"); 
echo"您已经留下您的宝贵意见!谢谢您的留言! <p><a href=index.php> 返回</a>"; 
echo("</center>"); 
}} 
if($errormsg<>""){echo"$errormsg<a href=gustbook.php>返回重写</a>";} 
?></body></html>
我用下面代码
<?
$dbhost = "localhost";  // 数据库主机名
$dbuser = "root";      // 数据库用户名
$dbpasswd = "";  // 数据库密码
$dbname = "mysql";     //数据库名称$connect=mysql_connect($dbhost,$dbuser,$dbpasswd) or die ("数据库连接失败");
mysql_select_db($dbname);
$query=mysql_query("select * from user");
$array=mysql_fetch_array($query);
echo $array["User"];
?>
结构是有输出 root

解决方案 »

  1.   

    1。
    $dbhost="localhost";//主机地址 
    $dbnanme="dowebs"; //数据库名字 
    $dbusername=""; //dbuser 
    $dbpassword=""; //数据库口令 和$dbhost = "localhost";  // 数据库主机名
    $dbuser = "root";      // 数据库用户名
    $dbpasswd = "";  // 数据库密码
    $dbname = "mysql";     //数据库名称不一样,看看dbuser部分。
    2。输入的留言中有一些 " ' \ 等字符,也会导致数据不能插入。在数据库操作前,对要保存的变量用 addslashes 函数处理一下看看。