【发布时间】:2013-05-10 22:11:14
【问题描述】:
我正在尝试更新我的客户 mysql 表上的记录。但是我收到以下错误:
注意:未定义索引:E:\EasyPHP-12.1\www\Register1.php 中的用户名 在第 313 行
注意:未定义变量:db_password in E:\EasyPHP-12.1\www\Register1.php 315行错误更新记录
我看不出我的代码有什么问题。并且一直在看它几个小时,但没有运气。
<div class="footer">
<img src="images/gardening5.jpg" alt="Image">
<div>
<h1>Tips of the Week</h1>
<form method= "get">
<form method="get">
<p>Username:
<input name="username" type="text">
</p>
</form>
<p>
<form method="get">
<p>Password:
<input name="password" type="password">
</p>
<p>First Name:
<input name="first name" type="first name">
</p>
<p>Last Name:
<input name="last name" type="last name">
</p>
<p>1st Line of Address:
<input name="1st line of address" type="1st line of address">
</p>
<p>2nd Line of Address:
<input name="2nd line of address" type"2nd line of address">
</p>
<p>Town:
<input name="town" type"town">
</p>
<p>PostCode:
<input name="postcode" type="postcode">
</p>
<p>Phone Number
<input name="phone_number" type="phone_number">
</p>
<p>
<input name="submit3" type="submit" value="update customer record">
</p>
</form>
</form>
<?php
$host="localhost"; // Host name
$tbl_name="customer"; // Table name
$db_user="root";
$db_pass="";
$connect = mysql_connect("$host", "$db_user", "$db_pass");
$db_name="the_shop"; // Database name
mysql_select_db("$db_name");
if(isset($_GET['submit3'])){
$db_username = $_GET['username'];
$sql3 = "UPDATE `customer` SET `Password`='.$db_password.' WHERE `Username`='.$db_username.";
$result3 = mysql_query($sql3);
mysql_query($sql3) or die('error updating record');
echo $sql3;
}
?>
【问题讨论】:
-
您在一个父表单中嵌入了多个表单。你只需要一个。
-
此外,您的代码容易受到 SQL 注入的攻击。此外,不需要使用像
"$host"这样的语句,而不是简单的$host -
请不要将 $_GET 或 $_POST 变量传递到您的 sql 字符串中。您将容易受到 sql 注入的攻击。