php表单提交到数据库的问题

<?php$dbhost='localhost';//数据库主机$dbuser='root';//数据库用户$dbpass='';//数据库密码$dbname='exam... <?php
$dbhost='localhost'; // 数据库主机
$dbuser='root'; //数据库用户
$dbpass=''; //数据库密码
$dbname='exam'; // 数据库名
$conn=mysql_connect($dbhost, $dbuser, $dbpass);// or die ("无法连接数据库主机");
mysql_query("SET NAMES gb2312");
if ($conn=mysql_pconnect($dbhost, $dbuser, $dbpass))
{
echo "无法连接数据库主机";
}
if (mysql_select_db($dbname,$conn))
{
echo "无法选择数据库";
}
mysql_select_db($dbname,$conn);
if ($_POST[Submit]!="")
{
$sql="insert into news (`name`,`xuan1`,`xuan2`,`xuan3`,`xuan4`,`xuan5`,`xuan6`,`xuan7`,`xuan8`,`xuan9`,`xuan10`,`qq`,`tel`,`ad`) values('$_POST[name]','$_POST[xuan1]','$_POST[xuan2]','$_POST[xuan3]','$_POST[xuan4]','$_POST[xuan5]','$_POST[xuan6]','$_POST[xuan7]','$_POST[xuan8]','$_POST[xuan9]','$_POST[xuan10]','$_POST[qq]','$_POST[tel]','$_POST[ad]')";
mysql_query($sql);

echo "<script language='javascript'>alert('添加成功!');window.location.href='input.php';</script>";
}
?>

<form name="form1" method="post" action="file:///C|/wamp/www/input.php">
<table width="500" height="300" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#D0D0D0" bgcolor="#EAEAEA">
<tr>
<td width="261" nowrap><span class="style1">您的名字 (name)</span></td>
<td width="233"><input name="name" type="text" id="name" size="30" maxlength="30"></td>
</tr>
<tr>
<td nowrap><span class="style1">选择题1</span></td>
<td><input name="xuan1" type="radio" value="A" checked>
A
<input type="radio" name="xuan1" value="B">
B
<input type="radio" name="xuan1" value="C">
C
<input type="radio" name="xuan1" value="D">
D</td>

</tr>
<tr>
</tr>
<tr>
<td nowrap><span class="style1">选择题2</span></td>
<td><input name="xuan2" type="radio" value="A" checked>
A
<input type="radio" name="xuan2" value="B">
B
<input type="radio" name="xuan2" value="C">
C
<input type="radio" name="xuan2" value="D">
D</td>
</tr>
<tr>
<td nowrap><span class="style1">选择题3</span></td>
<td><input name="xuan3" type="radio" value="A" checked>
A
<input type="radio" name="xuan3" value="B">
B
<input type="radio" name="xuan3" value="C">
C
<input type="radio" name="xuan3" value="D">
D</td>
</tr>
<tr>
<td nowrap><span class="style1">选择题4</span></td>
<td><input name="xuan4" type="radio" value="A" checked>
A
<input type="radio" name="xuan4" value="B">
B
<input type="radio" name="xuan4" value="C">
C
<input type="radio" name="xuan4" value="D">
D</td>
</tr>
<tr>
<td nowrap><span class="style1">选择题5</span></td>
<td><input name="xuan5" type="radio" value="A" checked>
A
<input type="radio" name="xuan5" value="B">
以上代码为部分,提示无法连接数据库主机无法选择数据库,我的账号密码就是如代码所示,而且已经建立相关数据库和数据表,数据库可以使用,请问哪里有问题了?
展开
 我来答
一喉封剑
推荐于2016-06-20 · 超过59用户采纳过TA的回答
知道小有建树答主
回答量:246
采纳率:0%
帮助的人:171万
展开全部
你的逻辑都反了,其实已经连上了。而且一楼说得没错,你有多余的语句。这样改:
mysql_query("SET NAMES gb2312");
if ( !$conn=mysql_pconnect($dbhost, $dbuser, $dbpass))
{
echo "无法连接数据库主机";
exit;
}
if ( !mysql_select_db($dbname,$conn) )
{
echo "无法选择数据库";
exit;

}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
sunline_007
2009-10-19 · TA获得超过249个赞
知道小有建树答主
回答量:153
采纳率:0%
帮助的人:121万
展开全部
$conn=mysql_connect($dbhost, $dbuser, $dbpass);// or die ("无法连接数据库主机");
mysql_query("SET NAMES gb2312");
if ($conn=mysql_pconnect($dbhost, $dbuser, $dbpass))
{
echo "无法连接数据库主机";
}
我觉得你这里有重复的,两个函数都是连数据库的,留其中一个,就可以了.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
墙边小草
2009-10-20 · 超过75用户采纳过TA的回答
知道小有建树答主
回答量:272
采纳率:100%
帮助的人:0
展开全部
一,二楼说的都对,你已经提交成功,自己看看数据库就知道了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式