我正在尝试使用 mysql 查询更新客户信息。变量已在此处定义:
$member_id = $_POST['member_id'];
$username = $_POST['username'];
$password = $_POST['password'];
$bizname = $_POST['bizname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$url = $_POST['url'];
$contact = $_POST['contact'];
$notes = $_POST['notes'];
$sales_rep = $_POST['sales_rep'];
$member_type = $_POST['member_type'];
$password = md5($password);
当我运行以下查询时,数据库中没有任何更新
$qry = "update members set username='".$username."',password='".$password."',bizname='".$bizname."',phone='".$phone."',email='".$email."',url='".$url."',contact='".$contact."',notes='".$notes."',sales_rep='".$sales_rep."',member_type='".$member_type."' where member_id='".$member_id."'";
我回应了$qry
,结果如下:
update members set
username='',password='d41d8cd98f00b204e9800998ecf8427e',bizname='',phone='',
email='',url='',contact='',notes='',sales_rep='',member_type=''
where member_id=''
有谁知道为什么只有$password
变量有值?我曾尝试对其他变量使用 md5 加密,只是为了看看这是否可行并且它们会有值,但显然我只想对密码执行此操作。
编辑:这是 edit-client.php 表单
<?php
require_once('auth.php');
require_once('config.php');
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; />
<title>Untitled Document</title>
</head>
<body>
<?php
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//define username variable and sanitize
$username = clean($_POST['username']);
//Run query for selected user and store in an array
$result = mysql_query("select * from members where username='".$username."'");
$row = mysql_fetch_array($result);
//display all clients information in a form to edit
echo '<h1>'.$username.'</h1>';
echo '<form name="update-client" action="update-client.php" />';
echo '<table>';
echo '<tr><td>';
echo '<input type="hidden" name="member_id" value="'.$row['member_id'].'"';
echo '</td></tr>';
echo '<tr><td>';
echo 'Username: <input name="username" type="text" value="'.$username.'" />';
echo '</td></tr>';
echo '<tr><td>';
echo 'Password: <input name="password" type="text" value="'.$row['password'].'" />';
echo '</td></tr>';
echo '<tr><td>';
echo 'Business Name: <input name="bizname" type="text" value="'.$row['bizname'].'" />';
echo '</td></tr>';
echo '<tr><td>';
echo 'Phone: <input name="phone" type="text" value="'.$row['phone'].'" />';
echo '</td></tr>';
echo '<tr><td>';
echo 'Email: <input name="email" type="text" value="'.$row['email'].'" />';
echo '</td></tr>';
echo '<tr><td>';
echo 'Website Address: <input name="url" type="text" value="'.$row['url'].'" />';
echo '</td></tr>';
echo '<tr><td>';
echo 'Contact: <input name="contact" type="text" value="'.$row['contact'].'" />';
echo '</td></tr>';
echo '<tr><td>';
echo 'Notes: <input name="notes" type="text" value="'.$row['notes'].'" />';
echo '</td></tr>';
echo '<tr><td>';
echo 'Sales Representative: <input name="sales_rep" type="text" value="'.$row['sales_rep'].'" />';
echo '</td></tr>';
echo '<tr><td>';
echo '<input name="submit" type="submit" value="Edit" />';
echo '</td></tr>';
echo '</table>';
echo '</form>';
?>
</body>
</html>