gpt4 book ai didi

php - 在一页内编辑/删除/列出

转载 作者:行者123 更新时间:2023-11-29 13:21:04 25 4
gpt4 key购买 nike

我正在尝试创建一个包含数据库中所有信息的页面,用户可以在其中编辑或删除行。我不太明白如何使按钮起作用。我是编程初学者,如果您能帮助我,我将非常感激。

我的代码:

<form action="" method="post">
<?php
$sqlquery="SELECT artistId, firstname, lastname, nationality, dateofBirth, otherInfo, image from $artists order by 1";
$result = mysqli_query($connect, $sqlquery);
if($result)
{
echo "<table id=\"artists\">";

while ($sqlRow=mysqli_fetch_array($result, MYSQL_ASSOC))
{


echo "<tr>";
echo "<td>";
echo"<input type=\"text\" name=\"textid[]\" value=\"".$sqlRow['artistId']."\"/>";
echo "</td>";
echo "<td>";
echo "<input type=\"text\" name=\"textfirstname[]\" value=\"".$sqlRow['firstname']."\"/>";
echo "</td>";
echo "<td>";
echo "<input type=\"text\" name=\"textlastname[]\" value=\"".$sqlRow['lastname']."\"/>";
echo "</td>";
echo "<td>";
echo "<input type=\"text\" name=\"textnation[]\" value=\"".$sqlRow['nationality']."\"/>";
echo "</td>";
echo "<td>";
echo "<input type=\"text\" name=\"textdateofbirth[]\" value=\"".$sqlRow['dateofBirth']."\"/>";
echo "</td>";
echo "<td>";
echo "<input type=\"text\" name=\"textotherinfo[]\" value=\"".$sqlRow['otherInfo']."\"/>";
echo "</td>";
echo "<td>";
echo "<input type=\"text\" name=\"textimage[]\" value=\"".$sqlRow['image']."\"/>";
echo "</td>";
echo "<td>";
echo "<input type=\"submit\" onclick=\"return confirm('Edit the record?')\" name=\"edit[]\" value=\"Edit\" />";
echo "<input type=\"submit\" name=\"delete[]\" value=\"Delete\" onclick=\"return confirm('Delete the record?')\"/>";
echo "<input type=\"reset\" name=\"reset[]\" value=\"Cancel\" />";
echo "</td>";
echo "</tr>";
}


}
print '</table>';

if($_POST)
{
$artistId=$_POST['textid'];
$fname=$_POST['textfirstname'];
$lname=$_POST['textlastname'];
$nation=$_POST['textnation'];
$dateofBirth=$_POST['textdateofbirth'];
$otherInfo=$_POST['textotherinfo'];
$image=$_POST['textimage'];


for($i=0;$i<sizeof($artistId);$i++)
{
if (isset($_POST['edit[$i]']))
{
$query="UPDATE $artists set artistId='".$artistId[$i]."', firstname='".$fname[$i]."', lastname='".$lname[$i]."', nationality='".$nation[$i]."', dateofBirth='".$dateofBirth[$i]."', otherInfo='".$otherInfo[$i]."', image='".$image[$i]."' WHERE (artistId='".$sqlRow['artistId']."')";
}

}
}
?>

最佳答案

尝试围绕输入字段创建公式。

例如:

<form name="form" action="yourfilename.php" method="post">
<input....
</form>

关于php - 在一页内编辑/删除/列出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20839894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com