无法获取表格来更新,删除和添加额外的代码

时间:2016-04-27 03:21:37

标签: php

所以我想做的是让用户向表单添加代码,并填写表单,A添加到表,D删除,U更新...删除不工作,也不是插入,是我的逻辑吗?我也只想打印一次这个表,有时它会做两次......有什么建议吗?

$Code=$_POST["Code"];

if ($Code == "A") 
    {
$sql = "INSERT INTO movieDATA values ('$idno', '$Name', '$Genre', '$Starring', '$Year', '$BoxOffice')";
$result= mysqli_query($link,$sql) or die(mysqli_error($link));
$showresult = mysqli_query($link,"SELECT * from movieDATA") or die("Invalid query: " . mysqli_error($link));
while ($row = mysqli_fetch_array($showresult))
   {
    echo ("<br> ID = ". $row["IDNO"] . "<br> NAME =  " . $row["Name"] . "<br>");
    echo("Genre = " . $row["Genre"] . "<br> Starring = " . $row["Starring"] . "<br>");
    echo("Year = " . $row["Year"] . "<br> Box Office = " . $row["BoxOffice"] . "<br>");
   }

}
elseif ($Code == "D")
{
$sql = "DELETE FROM movieDATA WHERE IDNO = '$idno'";
$result= mysqli_query($link,$sql) or die(mysqli_error($link));
$showresult = mysqli_query($link,"SELECT * from movieDATA") or die("Invalid query: " . mysqli_error($link));
while ($row = mysqli_fetch_array($showresult))
   {
    echo ("<br> ID = ". $row["IDNO"] . "<br> NAME =  " . $row["Name"] . "<br>");
    echo("Genre = " . $row["Genre"] . "<br> Starring = " . $row["Starring"] . "<br>");
    echo("Year = " . $row["Year"] . "<br> Box Office = " . $row["BoxOffice"] . "<br>");
   }

}

elseif ($Code == "U")
{
$sql = "UPDATE movieDATA SET Name = '$Name', Genre = '$Genre', Starring = '$Starring', Year = '$Year', BoxOffice = '$BoxOffice' where IDNO = '$idno'";
$result= mysqli_query($link,$sql) or die(mysqli_error($link));
$showresult = mysqli_query($link,"SELECT * from movieDATA") or die("Invalid query: " . mysqli_error($link));
while ($row = mysqli_fetch_array($showresult))
   {
    echo ("<br> ID = ". $row["IDNO"] . "<br> NAME =  " . $row["Name"] . "<br>");
    echo("Genre = " . $row["Genre"] . "<br> Starring = " . $row["Starring"] . "<br>");
    echo("Year = " . $row["Year"] . "<br> Box Office = " . $row["BoxOffice"] . "<br>");
   }
}
?>

0 个答案:

没有答案