下面是全部代码:
<?
$conn=mysql_connect("localhost","root","m1nnnnnm") or die("无法连接mysql".mysql_error());
mysql_select_db("db2",$conn) or die("无法连接mysql".mysql_error());
/*if($Submit3){
SetCookie("username", "");
SetCookie("userpass", "");
}*/
if($Submit){
//$name=$_POST['textfield'];
//$pass=$_POST['textfield2'];
/*if(empty($textfield)||empty($textfield2)){
echo("null");
echo "<META HTTP-EQUIV=REFRESH CONTENT='1;URL=user.php'>";
exit();
}*/
$sql="select * from user where name='$textfield' and passw='$textfield2'";
$query=mysql_query($sql,$conn) or die("无法1".mysql_error());
$result=mysql_fetch_array($query);
if(!empty($result)){
setcookie("username","aaa");
setcookie("userpass","bbb");
echo $HTTP_COOKIE_VARS["username"];
echo($userpass);
echo($result[name]);
}
else{
echo("用户名或密码错误");
echo "<META HTTP-EQUIV=REFRESH CONTENT='1;URL=user.php'>";
exit();
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<table width="700" border="1">
<tr>
<th scope="col">name</th>
<th scope="col">pass</th>
</tr>
<tr>
<td colspan="2">
<table width="700" border="1">
<?
//if($username&&$userpass){
if($Submit){
echo $HTTP_COOKIE_VARS["username"]; ?>
<form name="form2" method="post" action="<?php echo $PHP_SELF ?>">
<tr>
<td><label>
<input name="textfield3" type="text" value="<? echo($username); ?>">
</label>
</td>
<td>
<label>
<input name="textfield4" type="text" value="<? echo($userpass); ?>">
</label></td>
<td><label>
<input type="submit" name="Submit3" value="删除">
</label></td>
</tr>
</form>
<?
}
else{
?>
<form name="form1" method="post" action="<?php echo $PHP_SELF ?>">
<tr>
<th scope="col"><label>
<input type="text" name="textfield">
</label></th>
<th scope="col"><label>
<input type="text" name="textfield2">
</label></th>
</tr>
<tr>
<td><label>
<input type="submit" name="Submit" value="提交">
</label></td>
<td><label>
<input type="reset" name="Submit2" value="重置">
</label></td>
</tr>
</form>
<?
}
?>
</table>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
<?
$conn=mysql_connect("localhost","root","m1nnnnnm") or die("无法连接mysql".mysql_error());
mysql_select_db("db2",$conn) or die("无法连接mysql".mysql_error());
/*if($Submit3){
SetCookie("username", "");
SetCookie("userpass", "");
}*/
if($Submit){
//$name=$_POST['textfield'];
//$pass=$_POST['textfield2'];
/*if(empty($textfield)||empty($textfield2)){
echo("null");
echo "<META HTTP-EQUIV=REFRESH CONTENT='1;URL=user.php'>";
exit();
}*/
$sql="select * from user where name='$textfield' and passw='$textfield2'";
$query=mysql_query($sql,$conn) or die("无法1".mysql_error());
$result=mysql_fetch_array($query);
if(!empty($result)){
setcookie("username","aaa");
setcookie("userpass","bbb");
echo $HTTP_COOKIE_VARS["username"];
echo($userpass);
echo($result[name]);
}
else{
echo("用户名或密码错误");
echo "<META HTTP-EQUIV=REFRESH CONTENT='1;URL=user.php'>";
exit();
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<table width="700" border="1">
<tr>
<th scope="col">name</th>
<th scope="col">pass</th>
</tr>
<tr>
<td colspan="2">
<table width="700" border="1">
<?
//if($username&&$userpass){
if($Submit){
echo $HTTP_COOKIE_VARS["username"]; ?>
<form name="form2" method="post" action="<?php echo $PHP_SELF ?>">
<tr>
<td><label>
<input name="textfield3" type="text" value="<? echo($username); ?>">
</label>
</td>
<td>
<label>
<input name="textfield4" type="text" value="<? echo($userpass); ?>">
</label></td>
<td><label>
<input type="submit" name="Submit3" value="删除">
</label></td>
</tr>
</form>
<?
}
else{
?>
<form name="form1" method="post" action="<?php echo $PHP_SELF ?>">
<tr>
<th scope="col"><label>
<input type="text" name="textfield">
</label></th>
<th scope="col"><label>
<input type="text" name="textfield2">
</label></th>
</tr>
<tr>
<td><label>
<input type="submit" name="Submit" value="提交">
</label></td>
<td><label>
<input type="reset" name="Submit2" value="重置">
</label></td>
</tr>
</form>
<?
}
?>
</table>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
是不是我的方法不正确,应该如何做?