我正在尝试更新我的卡片表。用户选择“更新”按钮后,它会将他重定向到更新页面,在那里他可以看到和修改他的数据。问题是,输入字段不会加载他的数据,并且由于某种原因也无法更新它们。这是第一页上的按钮:
<a href="update.php?id=<?php echo $record['id']; ?>" class="btn btn-succes" role="button">Edit</a>
这是更新页面:
<?php
session_start();
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'reg');
/* Attempt to connect to MySQL database */
$mysqli = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check connection
if($mysqli === false){
die("HIBA: Nem sikerült csatlakozni. " . mysqli_connect_error());
}
$stmt = $mysqli -> prepare('UPDATE cards SET name=?, phone=?, phone2=?, email=?, zipcode=?, address=?, job=?, description=?, visibility=?, confirmed=?, userid=? WHERE id = ?');
if (
$stmt &&
$stmt->bind_param('ssssisssiiii', $name, $phone, $phone2, $email, $zipcode, $address, $job, $description, $visibility, $confirmed, $userid, $id)
&&
$stmt -> execute() &&
$result = mysqli_query($mysqli,"SELECT * FROM cards WHERE id='$id'") &&
$result = $stmt -> get_result()
) {
$id = $row['id'];
$name = $row['name'];
$phone = $row['phone'];
$phone2 = $row['phone2'];
$email = $row['email'];
$zipcode = $row['zipcode'];
$address = $row['address'];
$job = $row['job'];
$description = $row['description'];
$userid = $_SESSION['userid'];
echo 'Updated';
}
else {
echo $mysqli -> error;
}
?>
<form action="update.php" method="post">
<table cellpadding="10" cellspacing="0" width="500" class="tblSaveForm">
<tr class="header">
<td colspan="2">Edit Card</td>
</tr>
<tr>
<td><label>Username</label></td>
<td><input type="text" name="name" class="txtField" value="<?php echo $result['name']; ?>">
</tr>
<tr>
<td><label>phone</label></td>
<td><input type="text" name="phone" class="txtField" value="<?php echo $result['phone']; ?>"></td>
</tr>
HUX布斯