我想更新客户注册表。任何时候我在编辑数据后尝试保存,都会带来错误。 注意:未定义的索引:第6行的C:\ wamp64 \ www \ customer \ edit.php中的prc_id 调用堆栈
1 0.0007 251696 {main}()... \ edit.php:0
(!)注意:第7行的C:\ wamp64 \ www \ customer \ edit.php中的未定义索引:prc_name 调用堆栈
1 0.0007 251696 {main}()... \ edit.php:0
(!)注意:未定义的索引:第8行的C:\ wamp64 \ www \ customer \ edit.php中的prc_email 调用堆栈
1 0.0007 251696 {main}()... \ edit.php:0
(!)注意:第9行的C:\ wamp64 \ www \ customer \ edit.php中的未定义索引:prc_phone 调用堆栈
1 0.0007 251696 {main}()... \ edit.php:0
(!)注意:未定义的索引:第10行的C:\ wamp64 \ www \ customer \ edit.php中的prc_gender 调用堆栈
1 0.0007 251696 {main}()... \ edit.php:0
请,任何帮助。
index.php
<?php
include_once('connect.php');
$result = $db->prepare("SELECT * FROM p_r_customers ORDER BY prc_id DESC");
$result->execute();
?>
<table border="1" cellspacing="0" cellpadding="2" >
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Gender</th>
<th>Birthday Day</th>
<th>Birthday Month</th>
<th>Age Group</th>
<th>Card ID</th>
<th>Password</th>
<th>Country</th>
<th>State</th>
<th>rand</th>
</tr>
<tbody>
<?php
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
<td><?php echo $row['prc_id']; ?></td>
<td><?php echo $row['prc_name']; ?></td>
<td><?php echo $row['prc_email']; ?></td>
<td><?php echo $row['prc_phone']; ?></td>
<td><?php echo $row['prc_gender']; ?></td>
<td><?php echo $row['prc_dob_day']; ?></td>
<td><?php echo $row['prc_dob_month']; ?></td>
<td><?php echo $row['prc_age_group']; ?></td>
<td><?php echo $row['prc_card']; ?></td>
<td><?php echo $row['prc_password']; ?></td>
<td><?php echo $row['prc_country']; ?></td>
<td><?php echo $row['prc_state']; ?></td>
<td><?php echo $row['prc_rand']; ?></td>
<td><a href="editform.php?id=<?php echo $row['prc_id']; ?>"> Edit </a></td>
</tr>
<?php
}
?>
</tbody>
</table>
editform.php
<?php
include_once('connect.php');
$id=$_GET['id'];
$result = $db->prepare("SELECT * FROM p_r_customers WHERE prc_id= :userid");
$result->bindParam(':userid', $id);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<form action="edit.php" method="POST">
<input type="hidden" name="ids" value="<?php echo $id; ?>" />
Name<br>
<input type="text" name="name" value="<?php if(isset($_row)){ echo $_row['prc_name'];} ?>" /><br>
Email<br>
<input type="text" name="email" value="<?php if(isset($_row)){ echo $_row['prc_email'];} ?>" /><br>
Phone<br>
<input type="text" name="phone" value="<?php if(isset($_row)){ echo $_row['prc_phone'];} ?>" /><br>
Gender<br>
<input type="text" name="gender" value="<?php if(isset($_row)){ echo $_row['prc_gender'];} ?>" /><br>
Birthday Day<br>
<input type="text" name="dob_day" value="<?php if(isset($_row)){ echo $_row['prc_dob_day'];} ?>" /><br>
Birthday Month<br>
<input type="text" name="dob_month" value="<?php if(isset($_row)){ echo $_row['prc_dob_month'];} ?>" /><br>
Age group<br>
<input type="text" name="age_group" value="<?php if(isset($_row)){ echo $_row['prc_age_group'];} ?>" /><br>
Card ID<br>
<input type="text" name="card" value="<?php if(isset($_row)){ echo $_row['prc_card'];} ?>" /><br>
Password<br>
<input type="text" name="password" value="<?php if(isset($_row)){ echo $_row['prc_password'];} ?>" /><br>
Country<br>
<input type="text" name="country" value="<?php if(isset($_row)){ echo $_row['prc_country'];} ?>" /><br>
State<br>
<input type="text" name="state" value="<?php if(isset($_row)){ echo $_row['prc_state'];} ?>" /><br>
Rand<br>
<input type="text" name="rand" value="<?php if(isset($_row)){ echo $_row['prc_rand'];} ?>" /><br>
<input type="submit" value="Save" />
</form>
<?php
}
?>
edit.php
<?php
include_once('connect.php');
// new data
$id = $_POST['prc_id'];
$name = $_POST['prc_name'];
$email = $_POST['prc_email'];
$phone = $_POST['prc_phone'];
$gender = $_POST['prc_gender'];
$dob_day = $_POST['prc_dob_day'];
$dob_month = $_POST['prc_dob_month'];
$age_group = $_POST['prc_age_group'];
$card = $_POST['prc_card'];
$password = $_POST['prc_password'];
$country = $_POST['prc_country'];
$state = $_POST['prc_state'];
$rand = $_POST['prc_rand'];
// query
$sql = "UPDATE p_r_customers
SET prc_name=?, prc_email=?, prc_phone=?, prc_gender=?, prc_dob_day=?, prc_dob_month=?,
prc_age_group=?, prc_card=?, prc_password=?, prc_country=?, prc_state=?, prc_rand=?
WHERE prc_id=?";
$q = $db->prepare($sql);
$q->execute(array($id,$name,$email,$phone,$gender,$dob_day,$dob_month,$age_group,$card,$password,$country,$state,$rand));
header("location: index.php");
?>
答案 0 :(得分:1)
尝试将$id = $_GET['prc_id'];
更改为$id = $_GET['id'];
。
答案 1 :(得分:0)
您的表单中没有包含&#39; prc_id&#39;的名称。在您的情况下,它的名称是&#39; ids&#39;。将其替换为&#39; prc_id&#39;。