我正在尝试从表中连续编辑数据。我有一个查询设置,只显示每个用户他们的狗,他们将能够编辑有关该特定狗的信息。我可以让编辑显示在每一行旁边,当我点击"编辑"编辑的表格确实出现了,但是在查询中填写了最后输入的狗,而不是我要编辑的狗:如果用户有三只狗而dog_id是6,7,12只有关于将显示12,我需要能够挑选任何狗并编辑他们的信息。任何人都可以帮我弄清楚我做错了什么?
以下是查询用户狗的代码:
<table border="1" cellspacing="0" cellpadding="2" >
<thead>
<tr>
<th> Your Dogs </th>
<th> Breed </th>
<th> User </th>
<th> Dog Id </th>
</tr>
</thead>
<tbody>
<?php
include('scripts/check_user.php');
$stmt = $db->prepare("SELECT * FROM dogs_info WHERE id=:log_user_id");
$stmt->bindPARAM(':log_user_id',$log_user_id,PDO::PARAM_INT);
$stmt->execute();
for($i=0; $row = $stmt->fetch(); $i++){
?>
<tr class="record">
<td><?php echo $row['dogs_callname']; ?></td>
<td><?php echo $row['dogs_breed']; ?></td>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['dogs_id']; ?></td>
<td><a href="dogform_edit.php?dogs_id=<?php echo $row['dogs_id']; ?>"> edit </a></td>
</tr>
<?php
}
?>
</tbody>
</table>
以下是点击编辑链接的结果代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php
include_once("scripts/check_user.php");
if($user_is_logged == true){
}
$dogs_id=$_GET['dogs_id'];
$stmt = $db->prepare("SELECT * FROM dogs_info WHERE id=:log_user_id");
$stmt->bindValue(':log_user_id',$log_user_id,PDO::PARAM_INT);
try{
$stmt->execute();
}
catch(PDOException $e){
//echo $e->getMessage();
print_r($e->getTrace());
$db = null;
exit();
}
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$dogs_id=$row['dogs_id'];
$id=$row['id'];
$dogs_breed=$row['dogs_breed'];
$dogs_variety=$row['dogs_variety'];
$dogs_gender=$row['dogs_gender'];
$dogs_UKCname=$row['dogs_UKCname'];
$dogs_altered=$row['dogs_altered'];
$dogs_PR=$row['dogs_PR'];
$dogs_callname=$row['dogs_callname'];
$dogs_dob=$row['dogs_dob'];
$dogs_owners=$row['dogs_owners'];
$dogs_address=$row['dogs_address'];
$dogs_city=$row['dogs_city'];
$dogs_state=$row['dogs_state'];
$dogs_postcode=$row['dogs_postcode'];
$dogs_day=$row['dogs_day'];
$dogs_eve=$row['dogs_eve'];
$dogs_Perm=$row['dogs_Perm'];
$dogs_TL=$row['dogs_TL'];
$dogs_LP=$row['dogs_LP'];
$dogs_UKCnumber=$row['dogs_UKCnumber'];
$dogs_AKCnumber=$row['dogs_AKCnumber'];
$dogs_intnumber=$row['dogs_intnumber'];
$dogs_email=$row['dogs_email'];
$dogs_microchip=$row['dogs_microchip'];
}
?>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="" />
<title>dog entry</title>
<body>
<h3>Edit information for <?php echo $dogs_callname; ?> </h3>
<?php $dogs_id = isset($_POST['dogs_id']) ? $_POST['dogs_id'] : '';?>
<form id="mydogs" method="post" action="dogedit_process.php">
Dog's
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<?php echo $dogs_id; ?>
<input type="hidden" name="memids" value="<?php echo $dogs_id; ?>" />
<br />
<?php if ($dogs_id != ''): ?>
<h2><strong><?php echo $dogs_callname; ?></strong></h2>
<?php else: ?>
<h2><strong><?php echo $username; ?></strong></h2>
<?php endif; ?>
<label>Breed of Dog:<br />
<input type="text" name="dogs_breed" id="dogs_breed" value="<?php echo $log_uname ?>"/>
</label><br />
<label>Variety:<input type="text" name="dogs_variety" id="dogs_variety" value="<?php echo $dogs_variety ?>"/>if applicable
</label><br />
<label>Gender:
<select name="dogs_gender" id="dogs_gender">
<option value="0" selected="selected">Select</option>
<option value="Dog">Dog</option>
<option value="Bitch">Bitch</option>
</select>
</label><br />
<label>Dog's Name:
<input type="text" name="dogs_UKCname" id="dogs_UKCname" value="<?php echo $dogs_UKCname ?>"/></label><br />
<label> Altered
<input name="dogs_altered" type="hidden" value="0" />
<input name="dogs_altered" type="checkbox" value="1" />
</label>
<input name="dogs_PR" id="dogs_PR" value="0" type="hidden"/>
<input name="dogs_PR" value="1" type="checkbox">
Purple Ribbon<br />
<label>Dog's Call Name:
<input name="dogs_callname" type="text" id="dogs_callname" value="<?php echo $dogs_callname ?>" />
</label><br />
<label>Date of Birth:
<input name="dogs_dob" type="text" id="dogs_dob" value="M/D/Year" size="10" maxlength="10" />
</label><br />
<label>Dog owner’s name(s):
<input name="dogs_owners" type="text" id="dogs_owners" size="70" maxlength="200" />
</label><br />
<label>Address:
<input name="dogs_address" type="text" id="dogs_address" value= "<?php echo $address; ?>"/>
* this should be the address with whome the dog lives</label><br />
<label>City:
<input type="text" name="dogs_city" id="dogs_city"value= "<?php echo $city; ?>" />
</label><br />
<label>State:
<input type="text" name="dogs_state" id="dogs_state"value= "<?php echo $dogs_state; ?>" />
</label><br />
<label>ZIP:
<input name="dogs_postcode" type="text" id="dogs_postcode" value= "<?php echo $dogs_postcode; ?>" />
</label><br />
<label>Telephone (day):
<input type="text" name="dogs_day" id="dogs_day"value= "<?php echo $dogs_day; ?>" />
</label><br />
<label>(Eve)
<input name="dogs_eve" type="text" id="dogs_eve"value= "<?php echo $dogs_eve; ?>"/></label>
<br />
<label>
<input name="dogs_Perm" type="checkbox" id="dogs_Perm" value="1" />
<input name="dogs_Perm" type="hidden" id="dogs_Perm" value="0" />
UKC permanent reg#</label>
<label>
<input name="dogs_TL" type="checkbox" id="dogs_TL" value="1" />
<input name="dogs_TL" type="hidden" id="dogs_TL" value="0" />
UKC TL #</label>
<label>
<input name="dogs_LP" type="checkbox" id="dogs_LP" value="1" />
<input name="dogs_LP" type="hidden" id="dogs_LP" value="0" />
UKC LP #</label>
<input type="text" name="dogs_UKCnumber" id="dogs_UKCnumber" value= "<?php echo $dogs_UKCnumber; ?>"/><br />
<label>
AKC #</label>
<input type="text" name="dogs_AKCnumber" id="dogs_AKCnumber"value= "<?php echo $dogs_AKCnumber; ?>" />
<label>International#</label>
<input type="text" name="dogs_intnumber" id="dogs_intnumber"value= "<?php echo $dogs_intnumber; ?>" /><br />
<label>Email:
<input name="dogs_email" type="text" id="dogs_email" value= "<?php echo $dogs_email; ?>" />
</label><br />
<label>Microchip:
<input name="dogs_microchip" type="text" id="dogs_microchip" value= "<?php echo $dogs_microchip; ?>" />
</label><br />
<tr>
<p class="submit">
<button type="submit">Update</button>
</table>
</form>
<p> </p>
</body>
</html>
以下是连接的代码:
<?php
session_start();
include_once("connect.php");
$user_is_logged = false;
$log_user_id = "";
$log_uname = "";
$log_pass = "";
if(isset($_SESSION['uid']) && isset($_SESSION['username']) && isset($_SESSION['password'])){
$log_user_id = preg_replace('#[^0-9]#', '', $_SESSION['uid']);
$log_uname = preg_replace('#[^a-z0-9]#i', '', $_SESSION['username']);
$log_pass = preg_replace('#[^a-z0-9]#i', '', $_SESSION['password']);
$stmt = $db->prepare("SELECT id FROM members WHERE id=:log_user_id");
$stmt->bindValue(':log_user_id',$log_user_id,PDO::PARAM_INT);
try{
$stmt->execute();
if($stmt->rowCount() > 0){
$user_is_logged = true;
}
}
catch(PDOException $e){
return false;
}
}else if(isset($_COOKIE['id']) && isset($_COOKIE['username']) && isset($_COOKIE['password'])){
$_SESSION['uid'] = preg_replace('#[^0-9]#', '', $_COOKIE['id']);
$_SESSION['username'] = preg_replace('#[^a-z0-9]#i', '', $_COOKIE['username']);
$_SESSION['password'] = preg_replace('#[^a-z0-9]#i', '', $_COOKIE['password']);
$log_user_id = $_SESSION['uid'];
$log_uname = $_SESSION['username'];
$log_pass = $_SESSION['password'];
$stmt = $db->prepare("SELECT id FROM members WHERE id=:log_user_id LIMIT 1");
$stmt->bindValue(':log_user_id',$log_user_id,PDO::PARAM_INT);
try{
$stmt->execute();
if($stmt->rowCount > 0){
$user_is_logged = true;
}
}
catch(PDOException $e){
return false;
}
if($user_is_logged == true){
$db->query("UPDATE members SET lastlog=now() WHERE id='$log_user_id' LIMIT 1");
}
}
?>
如果有人可以提供帮助,我会非常感激!我对此非常陌生。