我需要更新頁面中的選定行。我有一個用戶輸入ID的網頁。在第二頁中輸入的所有行和具有相同ID的值將被顯示用於編輯。我怎樣才能做到這一點..更新php中的選定行
下面是代碼
<form method="post" action="edituser.php">
<label type="text" name="name" maxlength="50" size="30" class="label">Enter the Membership Number</label><br />
<input type="text" name='id' placeholder="enter Membership Number" class="input" size="40"/><br />
<span class="field">(* Required field)</span><br /><br />
<input type="submit" name="submit" value="SUBMIT" class="button"><br /><br /><br /><br />
</form>
</body>
</html>
<?php
mysql_connect("localhost","root","");
mysql_select_db("anthonys");
if(isset($_POST['submit']))
{
$id= $_POST['id'];
if(! ctype_alnum($id))
die('invalid id');
$query = "SELECT id FROM `member` WHERE `id` =$id";
$run = mysql_query($query);
if(mysql_num_rows($run)>0){
echo "<script>window.open('edit.php?id=".$id."','_self')</script>";
}
else {
echo "<script>alert('Membership No is Invalid!')</script>";
}
}
?>
<
h2>Application for the Membership</h2><br /><br />
<table border="0px" style="border-collapse:collapse; width:810px;" align="center">
<tr>
<td>
<form name="XIForm" id="XIForm" method="POST" action="pdf/pdf2.php">
<label type="text" name="uid" maxlength="50" size="30" class="label">Membership No</label><br />
<input type="text" name="id" id="id" value="<?php if(isset($_GET['id'])) { echo $_GET['id']; } ?>" readonly> <br /><br />
<label type="text" name="fathername" maxlength="50" size="30" class="label">Father`s Name</label><br />
<input name="fathername"name="fathername" placeholder="" class="input" size="40"value="<?php if(isset($_GET['fathername'])) { echo $_GET['fathername']; } ?>"> <br /><br />
<input type="hidden" name="formType" id="formType" value="reg"/>
<input type="button" name="XISubmit" id="XISubmit" value="ADD" class="button" />
<br /><br /><br /><br />
</form></td>
</tr>
</table>
</div>
</div>
</section>
</body>
</html>
<?php
mysql_connect("localhost","root","");
mysql_select_db("anthonys");
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE member SET fathername='$_POST[fathername]' WHERE id='$_POST[hidden]'";
$run=mysql_query($UpdateQuery);
};
echo "<table border=1>
<tr>
<th>Fathers_Name</th>
"</tr>";
while($record = mysql_fetch_array($myData)){
echo "<form action=edit.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name=Father_name value=" . $record['fathername'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['id'] . " </td>";
echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "</tr>";
echo "</form>";
}
echo "<form action=edit.php method=post>";
echo "<tr>";
echo "<td><input type=text name=fathername></td>";
echo "</form>";
echo "</table>";
?>
</body>
</html>
唯一的ID,而不是PDO? – Cylindric
首先更正你的mysql連接代碼。 – Sadikhasan