我写了两个*.php文件.
页面1代码如下::login1.php 主要是实现登录判断功能.
<?
error_reporting(0);
$mysql_servername = "127.0.0.1";
$mysql_username = "root";
$mysql_password ="root";
$mysql_database ="t_user"; mysql_connect($mysql_servername , $mysql_username , $mysql_password);
mysql_select_db($mysql_database);
$tname=$_POST['txt_user'];
$tpassowrd=$_POST['txt_password'];
if ($tname && $tpassowrd){
$sql = "SELECT * FROM t_user WHERE cUserID = '$tname' and password='$tpassowrd'";
$res = mysql_query($sql);
$rows=mysql_num_rows($res);
if($rows){
echo "<script langrage=javascript>alert('恭喜您登陆成功')</script>";
echo "<script>window.location.href='Index_STR.php';</script>";
exit;
}
echo "<script language=javascript>alert('用户名密码错误');history.back();</script>";
}
else
{
echo "<script language=javascript>alert('用户名密码不能为空');history.back();</script>";
}
?> 页面2,就是调用 页面1的代码实现登录,
页面2 就是登陆界面.<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>STR Login</title>
<style type="text/css">
<!--
.STYLE1 {
font-size: 24px;
font-weight: bold;
}
-->
</style>
</head><body>
<table width="1002" border="0">
<tr>
<td width="340" height="33"> </td>
<td width="72"> </td>
<td width="267"><div align="left"><span class="STYLE1">欢迎登录STR</span></div></td>
<td width="185"> </td>
<td width="104"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="30"> </td>
<td>User ID </td>
<td><form id="userid" name="userid" method="post" action="">
<label>
<input name="txt_user" type="text" id="txt_user" />
</label>
</form></td>
</tr>
<tr>
<td height="28"> </td>
<td>Pass Word </td>
<td><input name="txt_password" type="password" id="txt_password" /></td>
</tr>
<tr>
</tr>
<tr>
<td height="56"> </td>
<td> </td>
<td><form id="form1" name="form1" method="post" action="login1.php">
<label>
<input type="submit" name="Submit" value="登 入" />
</label>
<label>
<input type="submit" name="Submit2" value="注 册" />
</label>
</form>
</td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
为什么我登录的时候,它就提示我"用户名密码不能为空" ,我是输入用户名和密码..
好像代码“if ($tname && $tpassowrd){ ” 这里就跳出啦
页面1代码如下::login1.php 主要是实现登录判断功能.
<?
error_reporting(0);
$mysql_servername = "127.0.0.1";
$mysql_username = "root";
$mysql_password ="root";
$mysql_database ="t_user"; mysql_connect($mysql_servername , $mysql_username , $mysql_password);
mysql_select_db($mysql_database);
$tname=$_POST['txt_user'];
$tpassowrd=$_POST['txt_password'];
if ($tname && $tpassowrd){
$sql = "SELECT * FROM t_user WHERE cUserID = '$tname' and password='$tpassowrd'";
$res = mysql_query($sql);
$rows=mysql_num_rows($res);
if($rows){
echo "<script langrage=javascript>alert('恭喜您登陆成功')</script>";
echo "<script>window.location.href='Index_STR.php';</script>";
exit;
}
echo "<script language=javascript>alert('用户名密码错误');history.back();</script>";
}
else
{
echo "<script language=javascript>alert('用户名密码不能为空');history.back();</script>";
}
?> 页面2,就是调用 页面1的代码实现登录,
页面2 就是登陆界面.<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>STR Login</title>
<style type="text/css">
<!--
.STYLE1 {
font-size: 24px;
font-weight: bold;
}
-->
</style>
</head><body>
<table width="1002" border="0">
<tr>
<td width="340" height="33"> </td>
<td width="72"> </td>
<td width="267"><div align="left"><span class="STYLE1">欢迎登录STR</span></div></td>
<td width="185"> </td>
<td width="104"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="30"> </td>
<td>User ID </td>
<td><form id="userid" name="userid" method="post" action="">
<label>
<input name="txt_user" type="text" id="txt_user" />
</label>
</form></td>
</tr>
<tr>
<td height="28"> </td>
<td>Pass Word </td>
<td><input name="txt_password" type="password" id="txt_password" /></td>
</tr>
<tr>
</tr>
<tr>
<td height="56"> </td>
<td> </td>
<td><form id="form1" name="form1" method="post" action="login1.php">
<label>
<input type="submit" name="Submit" value="登 入" />
</label>
<label>
<input type="submit" name="Submit2" value="注 册" />
</label>
</form>
</td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
为什么我登录的时候,它就提示我"用户名密码不能为空" ,我是输入用户名和密码..
好像代码“if ($tname && $tpassowrd){ ” 这里就跳出啦
是在下面这html 中调用 login1.php
<form id="form1" name="form1" method="post" action="login1.php">
//php中error_reporting(0);
$mysql_servername = "127.0.0.1";
$mysql_username = "root";
$mysql_password ="root";
$mysql_database ="t_user"; if(isset($_POST['Submit'])){
mysql_connect($mysql_servername , $mysql_username , $mysql_password);
mysql_select_db($mysql_database);
$tname=$_POST['txt_user'];
$tpassowrd=$_POST['txt_password'];
if ($tname && $tpassowrd){
$sql = "SELECT * FROM t_user WHERE cUserID = '$tname' and password='$tpassowrd'";
$res = mysql_query($sql);
$rows=mysql_num_rows($res);
if($rows){
echo "<script langrage=javascript>alert('恭喜您登陆成功')</script>";
echo "<script>window.location.href='Index_STR.php';</script>";
exit;
}
echo "<script language=javascript>alert('用户名密码错误');history.back();</script>";
}
else
{
echo "<script language=javascript>alert('用户名密码不能为空');history.back();</script>";
}
}
//html中
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>STR Login</title>
<style type="text/css">
<!--
.STYLE1 {
font-size: 24px;
font-weight: bold;
}
-->
</style>
</head><body>
<table width="1002" border="0">
<tr>
<td width="340" height="33"> </td>
<td width="72"> </td>
<td width="267"><div align="left"><span class="STYLE1">欢迎登录STR</span></div></td>
<td width="185"> </td>
<td width="104"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="30"> </td>
<td>User ID </td>
<td>
<form id="form1" name="form1" method="post" action="login1.php">
<label>
<input name="txt_user" type="text" id="txt_user" />
</label>
</form>
</td>
</tr>
<tr>
<td height="28"> </td>
<td>Pass Word </td>
<td><input name="txt_password" type="password" id="txt_password" /></td>
</tr>
<tr>
</tr>
<tr>
<td height="56"> </td>
<td> </td>
<td>
<label>
<input type="submit" name="Submit" value="登 入" />
</label>
<label>
<input type="submit" name="Submit2" value="注 册" />
</label>
</form>
</td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
“你的表单里没有名为 txt_user 和 txt_password 的输入框”
这句话不是很明白?
<form id="form1" name="form1" method="post" action="login1.php">
<label>
<input type="submit" name="Submit" value="登 入" />
</label>
<label>
<input type="submit" name="Submit2" value="注 册" />
</label>
</form>
你难道不需要输入用户名吗?而你的 login1.php 中是要做检查的
$tname=$_POST['txt_user'];
$tpassowrd=$_POST['txt_password'];
if ($tname && $tpassowrd){