一个注册会员保存的PHP页,提示warning:mysql_fetch_array():supplied argument is not a valid MySQL result resource in C:\xampp\hodocs\shop\savereg.php on line 26
--------------------------------------------------------------------------------------------------------------全代码是:
<?php
session_start();
include("Connections/conn.php");
$name=$_POST[usernc];
$pwd1=$_POST[p1];
$pwd=md5($_POST[p1]);
$email=$_POST[email];
$truename=$_POST[truename];
$sfzh=$_POST[sfzh];
$tel=$_POST[tel];
$qq=$_POST[qq];
if($_POST[ts1]==1)
{
$tishi=$_POST[ts2];
}
else
{
$tishi=$_POST[ts1];
}
$huida=$_POST[tsda];
$dizhi=$_POST[dizhi];
$youbian=$_POST[yb];
$regtime=date("Y-m-j");
$dongjie=0;
$sql=mysql_query("select * from tb_user where name='".$name."'",$conn);
$info=mysql_fetch_array($sql);/*就是在这里出的问题*/if($info==true)
{
echo "<script>alert('该昵称已经存在!');history.back();</script>";
exit;
}
else
{
mysql_query("insert into tb_user (name,pwd,dongjie,email,truename,sfzh,tel,qq,tishi,huida,dizhi,youbian,regtime,pwd1) values ('$name','$pwd','$dongjie','$email','$truename','$sfzh','$tel','$qq','$tishi','$huida','$dizhi','$youbian','$regtime','$pwd1')",$conn);
session_register("username");
$username=$name;
session_register("producelist");
$producelist="";
session_register("quatity");
$quatity="";
echo "<script>alert('恭喜,注册成功!');window.location='index.php';</script>";
}
?>
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------全代码是:
<?php
session_start();
include("Connections/conn.php");
$name=$_POST[usernc];
$pwd1=$_POST[p1];
$pwd=md5($_POST[p1]);
$email=$_POST[email];
$truename=$_POST[truename];
$sfzh=$_POST[sfzh];
$tel=$_POST[tel];
$qq=$_POST[qq];
if($_POST[ts1]==1)
{
$tishi=$_POST[ts2];
}
else
{
$tishi=$_POST[ts1];
}
$huida=$_POST[tsda];
$dizhi=$_POST[dizhi];
$youbian=$_POST[yb];
$regtime=date("Y-m-j");
$dongjie=0;
$sql=mysql_query("select * from tb_user where name='".$name."'",$conn);
$info=mysql_fetch_array($sql);/*就是在这里出的问题*/if($info==true)
{
echo "<script>alert('该昵称已经存在!');history.back();</script>";
exit;
}
else
{
mysql_query("insert into tb_user (name,pwd,dongjie,email,truename,sfzh,tel,qq,tishi,huida,dizhi,youbian,regtime,pwd1) values ('$name','$pwd','$dongjie','$email','$truename','$sfzh','$tel','$qq','$tishi','$huida','$dizhi','$youbian','$regtime','$pwd1')",$conn);
session_register("username");
$username=$name;
session_register("producelist");
$producelist="";
session_register("quatity");
$quatity="";
echo "<script>alert('恭喜,注册成功!');window.location='index.php';</script>";
}
?>
--------------------------------------------------------------------------------------------------------------
而 $sql是mysql_query()返回的结果,如果出错,那么就是mysql_query()出错了。
在mysql_query()后面加一句 echo mysql_error(); 将mysql的错误信息输出看看
$sql = mysql_query();
var_dump($sql);
echo mysql_error();
mysql_fetch_array();
贴出结果
这样报什么错
warning:mysql_fetch_array():supplied argument is not a valid MySQL result resource in C:\xampp\hodocs\shop\savereg.php on line 28
在mysql_connect(。。); 后面加上一句
mysql_select_db('你所使用的数据库的名字');