為什么不能插入 求大神
添加頁(yè)面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>adduser</title> ??
</head>
<body>
<h2>添加用戶</h2>
<form action="doAction.php?act=addUser" method='post'>
<table border='1' cellpadding='0' cellspacing='0' bgcolor='#ABCDEF' width='80%'>
<tr>
<td>用戶名</td>
<td><input type="text" name="username" id="" placeholder='請(qǐng)輸入用戶名' required='required' /></td>
</tr>
<tr>
<td>密碼</td>
<td><input type="password" name="password" id="" placeholder='請(qǐng)輸入密碼' required='required' /></td>
</tr>
<tr>
<td>年齡</td>
<td><input type="number" name="age" id="" min='1' max='100' placeholder='請(qǐng)輸入年齡' required='required' /></td>
</tr>
<tr>
<td colspan='2'><input type="submit" value="添加用戶 ?" /></td>
</tr>
</table>
</form>
</body>
</html>
doAction頁(yè)面
<?php
header('content-type:text/html;charset=utf-8');
//接收頁(yè)面
$mysqli=new mysqli('localhost','root','123456','zcc');
?if($mysqli->connect_errno){
? ? ?die('CONNECT ERROR:'.$mysqli->connect_error);
?}
?$mysqli->set_charset('utf-8');
?$username=$_POST['username'];
?$username=$mysqli->escape_string($username);//將用戶名中的特殊符號(hào)進(jìn)行轉(zhuǎn)移
?$password=md5($_POST['password']);//選擇md5加密
?$age=$_POST['age'];
$act=$_GET['act'];
//根據(jù)不同的操作完成不同功能
switch ($act){
? ? case 'addUser':
? ? ? ? //echo '添加用戶操作';
? ? ? ?$sql="INSERT user(username,password,age) VALUES('{$username}','{$password}','{$age}');";
? ? ? ? $res=$mysqli->query($sql);
? ? ? ? if($res) {
? ? ? ? ? ? $insert_id=$mysqli->insert_id;
? ? ? ? ? ? echo "<script type='text/javascript'>
? ? ? ? ? ? ? ?alert('添加成功,網(wǎng)站的第{$insert_id}位用戶');
? ? ? ? ? ? ? ? location.href='Userlist.php';
? ? ? ? ? ? ? ? </script>";
? ? ? ? ? ? ? ?
? ? ? ? }else {
? ? ? ? ? ? echo "<script type='text/javascript'>
? ? ? ? ? ?alert('添加失敗,重新添加');
? ? ? ? ? ? location.href='addUser.php';
? ? ? ? ? ? </script>";
? ? ? ? }
? ? ? ? break;
}
似乎不能接受post過(guò)來(lái)的數(shù)據(jù)啊?
2017-05-24
我的也是這樣的問(wèn)題? 我把md5去掉之后就好了? 你試試看是不是這個(gè)問(wèn)題
2016-12-03
?我換我的數(shù)據(jù)庫(kù)你的代碼在我的電腦上測(cè)試完全正常。
2016-12-03
對(duì)著呢 ?可能是我的數(shù)據(jù)庫(kù)問(wèn)題吧
2016-12-03
在我的電腦測(cè)試時(shí)可以傳過(guò)來(lái)代碼沒(méi)有問(wèn)題
是不是跳轉(zhuǎn)頁(yè)面寫錯(cuò)了? 檢查一下location.href=? 的地址