Won't delete data from mysql database
Posted: Thu Jun 15, 2006 4:48 pm
Hey, I've done a script where it selects all data from a mysql database and makes a <select> menu. And then you should be able to press a button and all data gets deleted.
This is my script:
I just get a blank page but it doesn't delete anything so is it anything wrong with my mysql delete query?
Thanks
This is my script:
Code: Select all
<?php
$mysql_server = "xxx";
$mysql_user = "xxx";
$mysql_password = "xxx";
$mysql_database = "xxx";
$conn = mysql_connect($mysql_server, $mysql_user, $mysql_password);
mysql_select_db($mysql_database, $conn);
$sql = "SELECT *
FROM auction
ORDER BY id DESC";
if (!$result = mysql_query($sql))
{
die("Could not get the item list: " . mysql_error());
}
echo '<form method="post" action="tabortauktion.php">';
echo '<select name="auction">';
while ($row = mysql_fetch_array($result))
{
echo '<option value="' . $row['id'] . '">' . $row['auktionnamn'] . '</option>';
}
echo '</select>';
echo "<input type='submit' name='submit' value='Få fram auktion'>";
echo '</form>';
?>
<?php
include "connect.php";
error_reporting(E_ALL);
if (isset($_POST['auction']))
{
// You would really want to validate this here,
// But I am keeping this intentionally simple
$item_id = $_POST['auction'];
$sql = "SELECT *
FROM auction
WHERE id = $item_id ORDER BY id DESC";
if (!$result = mysql_query($sql))
{
die("Could not get the selected item: " . mysql_error());
}
$item_array = mysql_fetch_array($result);
$sql2 = "SELECT * FROM bud WHERE item = $item_id";
if (!$result2 = mysql_query($sql2))
{
die("Could not get the selected item: " . mysql_error());
}
echo '<form method="post" action="tabortauktion.php">';
echo 'Ta bort denna auktion: ';
echo "<br>";
echo " Ja <input type='checkbox' name='tabort_ja' value='tabort_ja'>";
echo "<br";
echo "<input type='submit' name='submit' value='Ta bort auktionen'>";
echo '</form>';
if($_POST['tabort_ja']) {
$sql2 = "DELETE * FROM auction WHERE id = $item_id LIMIT 1";
$result2 = mysql_query($sql2) or die(mysql_error());
echo "Auktionen har blivit raderat";
echo "<a href='admin.php'>Tillbaka till Admin Panelen</a>";
}
}
?>Code: Select all
$sql2 = "DELETE * FROM auction WHERE id = $item_id LIMIT 1";