-1
我想要做的是在數據庫上創建一個按鈕,點擊時允許您編輯該行。這也要求用戶能夠看到該行,以便他們知道他們正在編輯什麼。到目前爲止,我的表格在每行上都有一個編輯按鈕,點擊後會將您帶到合適的頁面。例如,如果單擊ID = 23的行上的編輯,您將被帶到http://website.com/filepath/editForm.php?id=23如何使用我的數據庫中的數據填充此php表單,然後才能更新/編輯它?
問題是,這些字段都是空白的,即使您自己填寫它們,它們也不會更新表格。我將發佈editform.php,並且如果請求了view.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; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</form>
<?php
// Only process the form if $_POST isn't empty
if (! empty($_POST)) {
// Connect to MySQL
$mysqli = new mysqli('localhost', 'user', 'mypass', 'dbname');
// Check our connection
if ($mysqli->connect_error) {
die('Connect Error: ' . $mysqli->connect_errno . ': ' . $mysqli->connect_error);
}
$ID=$_POST['ID'] ;
$RYP=$_POST['RYP'] ;
$SHE=$_POST['SHE'] ;
$SCO=$_POST['SCO'] ;
$CName=$_POST['CName'] ;
$Contact= $_POST['Contact'] ;
$Address=$_POST['Address'] ;
$City=$_POST['City'] ;
$State=$_POST['State'] ;
$Zip=$_POST['Zip'] ;
$Phone1=$_POST['Phone1'] ;
$Phone2=$_POST['Phone2'] ;
$EMail=$_POST['EMail'] ;
$Web=$_POST['Web'] ;
$sql = ("SELECT * FROM DEALERS WHERE 'ID' = $ID");
$sql = ("UPDATE dealers WHERE `ID`='$ID'(RYP, SHE, SCO, CName,Contact,Address,City, State, Zip, Phone1, Phone2, EMail, Web)
VALUES ('$RYP','$SHE','$SCO','$CName','$Contact','$Address','$City', '$State','$Zip','$Phone1','$Phone2','$EMail','$Web')");
}
?>
<form method="post">
<table>
<tr>
<td>RYP</td>
<td><input type="checkbox" name="author" value="<?php $row['RYP'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>SHE</td>
<td><input type="checkbox" name="author" value="<?php $row['SHE'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>SCO</td>
<td><input type="checkbox" name="author" value="<?php $row['SCO'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>Contact</td>
<td><input type="text" name="author" value="<?php $row['Contact'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="name" value="<?php $row['Address'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>City</td>
<td><input type="text" name="copy" value="<?php $row['City'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>State</td>
<td><input type="text" name="copy" value="<?php $row['State'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>Zip</td>
<td><input type="text" name="copy" value="<?php $row['Zip'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>Phone1</td>
<td><input type="text" name="copy" value="<?php $row['Phone1'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>Phone2</td>
<td><input type="text" name="copy" value="<?php $row['Phone2'] ?>" class="form-control"/></td>
</tr><tr>
<td>EMail</td>
<td><input type="text" name="copy" value="<?php $row['EMail'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>Web</td>
<td><input type="text" name="copy" value="<?php $row['Web'] ?>" class="form-control"/></td>
</tr>
<tr>
<td>CName</td>
<td><input type="text" name="title" value="<?php $row['CName'] ?>"class="form-control"/></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="submit" class="btn btn-success btn-lg"/></td>
</tr>
</table>
</form></body>
'value =「<?php $ row ['RYP']?>」'(從你的輸入)你永遠不會回顯任何這些值,基本上要注意它們 - 所以當腳本加載時,輸入始終會讀爲「value =」「'(空)。而且你從來沒有真正運行任何這些查詢!所以沒有數據被提取 - 此外,看看['error_reporting(E_ALL);'](http://php.net/manual/en/function.error-reporting.php) ['ini_set('display_errors ',1);'](http://php.net/manual/en/function.ini-set.php),可能會產生很多來自未定義變量的警告。 – Qirel
而且你有很多具有相同'name'屬性的輸入。 – Qirel