我想使用1更新按钮来更新整个表...我一直在使用更新的代码,但我做的php似乎需要每行更新按钮我想只使用1按钮更新整个表..
<?php
$username = "root";
$password = null;
$host = "localhost";
$dbname = "newspaper_system";
$conn = new mysqli($host,$username,$password ,$dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
mysqli_connect("localhost","root", $password ) or die(mysqli_error($conn));
mysqli_select_db($conn,"newspaper_system") or die(mysqli_error($conn));
if(!$conn){
die("cant connect db". mysqli_error());
}
if(isset($_POST['update'])){
$updatesql = "UPDATE newspaper_library SET Newspaper='$_POST[Newspaper]', Price='$_POST[Price]', Pricepersquare='$_POST[Pricepersquare]' WHERE News_ID='$_POST[hidden]}'";
$conn->query($updatesql);
print '<script type="text/javascript">';
print 'alert("UPDATE successful")';
print '</script>';
}
$result = mysqli_query($conn,"SELECT * FROM newspaper_library") or die(mysqli_error($conn));
echo "<center><table class='CSSTableGenerator table table-bordered table-hovered' border=1>
<tr>
<td width = 200><label1>News ID</td>
<td width = 200><label1>Newspaper</td>
<td width = 200><label1>Price</td>
<td width = 200><label1>Pricepersquare</td>
<td width = 200><label1></td>
</tr>";
while($record= mysqli_fetch_array($result)){
echo "<form action=Newslibrary.php method=post>";
echo "<tr>";
echo "<td width = 200> <label>". $record['News_ID'] . " </td>";
echo "<td width = 200>". "<input type=text name=Newspaper class='form-control' value =\"" . $record['Newspaper']. "\"> </td>";
echo "<td width = 200>". "<input type=text name=Price class='form-control' value=\"" . $record['Price']. "\"> </td>";
echo "<td width = 200>". "<input type=text class='form-control' name=Pricepersquare value=\"" . $record['Pricepersquare']. "\"> </td>";
//echo "<td width = 10>". "<input type=hidden name=hidden value=" . $record['News_ID']. "> </td>";
echo "<td width = 200>". "<input type=hidden name=hidden value=" . $record['News_ID']. "><input type='submit' class='btn btn-default' name=update value=update " . " </td>";
echo "</tr>";
echo "</form>";
}
echo "</table>";
$conn->close();
?>