我對網絡編程非常陌生,除了我的意大利麪代碼中的所有其他衆多錯誤,我一直在我的網頁上打印出所有這些信息,但我不確定是什麼原因造成的:像HTML一樣嵌入PHP打印?
作爲參考,我試圖創建一個網頁,可以追加和刪除SQL表中的行。學校項目。
<fieldset>
<legend><h3> Edit Listings </h3> </legend>
<?php
if (isset($_POST['buttondelete']))
{
$key=$_POST['key'];
$query="DELETE FROM theatre WHERE key='$key'";
$result=$conn->query($query);
if(!$result) echo "DELETE failed: $query<br>";
}
if(isset($_POST['buttonadd']))
{
if(isset($_POST['key']) &&
isset($_POST['name']) &&
isset($_POST['genre']) &&
isset($_POST['showtime']) &&
isset($_POST['days'])) &&
isset($_POST['cost'])
{
$key = $_POST['key'];
$name = $_POST['name'];
$genre = $_POST['genre'];
$showtime = $_POST['showtime'];
$days = $_POST['days'];
$cost = $_POST['cost'];
$query = $conn->prepare('INSERT INTO theatre (key, name, genre,
showtime, days, cost) VALUES (?,?,?,?,?,?)');
$query->bind_param('ssssss', $key, $name, $genre, $showtime, $days,
$cost);
$query->execute();
if($query->affected_rows==0) echo 'Insert FAILED: $query<br>';
}
}
?>
<form action='appendtheatre.html' method='post'>
<pre>
Key: <input type='text' name='key'>
Name: <input type='text' name='name'>
Genre: <input type='text' name='category'>
Showtime: <input type='text' name='showtime'>
Days: <input type='text' name='days'>
Cost: <input type='text' name='cost'>
<br>
<input type='submit' value='ADD RECORD' name='buttonadd'>
</pre>
</form>
</fieldset>
你在哪裏初始化了$ conn變量?似乎你的文本轉儲就在那裏。你禁用了錯誤輸出嗎? – Heroselohim