问:使用get方法更新和删除
我有这段代码可以更新数据库中的数据我
没有错误报告,但是他没有更新任何数据
,您可以帮我吗
我的数据库和我的代码
------------------------------------------------- ----------
-
Table structure for table `examinee`
--
CREATE TABLE `examinee` (
`examinee_id` int(10) UNSIGNED NOT NULL,
`user_name` varchar(30) NOT NULL,
`password` varchar(40) NOT NULL,
`date_of_registration` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `examinee`
--
INSERT INTO `examinee` (`examinee_id`, `user_name`, `password`, `date_of_registration`) VALUES
(1, 'khalidswaisi', 'swaisi2016', '2016-03-23 00:00:00'),
(2, 'user', 'user', '2016-04-10 16:38:00'),
(3, 'mohammed', 'nasyia', '0000-00-00 00:00:00');
-- --------------------------------------------------------
display page
<?php include ("connection.php"); ?>
<center><h2>Examinee List</h2></center>
<table border="1" cellpadding = "0" cellspacing = "0" width = "700" align = "center">
<thead>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
</thead>
<?php
$sql = mysqli_query ($link,"SELECT * FROM `examinee`") or die ();
while ( $row = mysqli_fetch_assoc($sql)) {
echo "<tr>
<td>".$row['examinee_id']."</td>
<td>".$row['user_name']."</td>
<td>".$row['password']."</td>
<td>".$row['date_of_registration']."</td>
<td align = 'center'>
<a href = 'examinee_Edit.php?examinee_id=$row[examinee_id]'>Update</a>
<a href = 'examinee_Delete.php?examinee_id=$row[examinee_id]'> Delete</a>
</td>
</tr>";
}
?>
</table>
</body>
</html>
</body>
</html>
更新页面
<?php include ("connection.php"); ?>
<?php
$msg = "";
if (isset($_POST['update'])) {
if(is_numeric($_POST['examinee_id'])){
$examinee_id = mysqli_real_escape_string($link,htmlspecialchars($_POST['examinee_id']));
$user_name = $_POST['user_name'];
$password = $_POST['password'];
$date_of_registration = $_POST['date_of_registration'];
$sql = mysqli_query ($link,"UPDATE `examinee` SET
`user_name`=[$user_name],
`password`=[$password],
`date_of_registration`=[$date_of_registration]
WHERE `examinee_id` = $examinee_id ")
;
header ("location : index.php");
}
}
else
{
if(isset($_GET['examinee_id']) && is_numeric($_GET['examinee_id']) && $_GET['examinee_id'] > 0 ){
$examinee_id=$_GET['examinee_id'] ;
$sql = mysqli_query ($link,"SELECT * FROM `examinee` WHERE `examinee_id`=$examinee_id ") ;
while( $row = mysqli_fetch_assoc ($sql) ){
$examinee_id = $row ['examinee_id'];
$user_name = $row['user_name'];
$password = $row['password'];
$date_of_registration = $row['date_of_registration'];
}
}
}
?>
<html dir="rtl">
<head>
<title> </title>
<meta http-equiv ="content-type" content="text/html"; charset = utf8" />
<meta http-equiv="refresh" content="30">
<center><h3>Update</h3></center>
<center><h3><a href="examinee_Search.php"> </a></h3></center>
</head>
<body>
<form method= "POST" action = "" >
<table width = "400" align = "center" >
<tr>
<td> </td>
<td><input type="text" name = "examinee_id" value="<?php echo $examinee_id ;?>" /></td>
</tr>
<tr>
<td> </td>
<td><input type="text" name = "user_name" value="<?php echo $user_name ;?>" /></td>
</tr>
<tr>
<td> </td>
<td><input type="text" name = "password" value="<?php echo $password ;?>" /></td>
</tr>
<tr>
<td> </td>
<td><input type="text" name = "date_of_registration" value="<?php echo $date_of_registration ;?>" /></td>
</tr>
<tr>
<td><input type="submit" name = "update" value=" " /></td>
</tr>
<tr>
<td><input type="hidden" name = "examinee_id" value="<?php echo $_GET['examinee_id']; ?>" /></td>
</tr>
</table>
</form>
</body>
</html>
答:请尝试此代码
$ sql = mysqli_query($ link,“ UPDATE考生SET user_name ='”。$ user_name。“',password ='”。$ password。“',date_of_registration ='”。$ date_of_registration。“' );
说明:您正在使用varchar数据类型存储数据库中的用户名,密码和注册日期。因此该值应为字符串格式,例如“用户名”。