Erasing information from a database using forms
Posted: Fri Jul 21, 2006 4:13 pm
Hey all,
I've got a problem. And i've tryed several diffrent ways and now i'm up to 3 diffrent scripts of trying to do it(yes it's dumb but i've tryed with less and still got the same result).
This is my code:
tabortauktion.php
That works good so far, then it forwards to tabortauktion1.php
And that code is:
That code should make so when you press submit you come to tabourtauktion2.php but it doesn't.
And that code is:
So nothing never gets taken away from the database. How should i solve that?
Thanks,
David
I've got a problem. And i've tryed several diffrent ways and now i'm up to 3 diffrent scripts of trying to do it(yes it's dumb but i've tryed with less and still got the same result).
This is my code:
tabortauktion.php
Code: Select all
<?php
$mysql_server = "xx";
$mysql_user = "xx";
$mysql_password = "xx";
$mysql_database = "xx";
$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 name="test1" method="post" action="tabortauktion1.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("Kunde inte komma in i databasen: " . mysql_error());
}
$item_array = mysql_fetch_array($result);
$sql2 = "SELECT * FROM bud WHERE item = $item_id";
if (!$result2 = mysql_query($sql2))
{
die("Kunde inte komma in i databasen: " . mysql_error());
}
}
?>And that code is:
Code: Select all
<?php
include("connect.php");
?>
<form name="test2" method="post" action="tabortauktion2.php">
<br>
<?php
echo "Om du vill ta bort den auktionen tryck på Ja. Annars tryck på <i>Tillbaka till startsidan</i>";
echo "<br>";
echo "Ja <input type='checkbox' name='tabort_ja' value={$item_id}";
?>
<br>
</form>
<br>
<input type='submit' name='submit' value='Ta bort auktion'>And that code is:
Code: Select all
<?php
$mysql_server = "xx";
$mysql_user = "xx";
$mysql_password = "xx";
$mysql_database = "xx";
$conn = mysql_connect($mysql_server, $mysql_user, $mysql_password);
mysql_select_db($mysql_database, $conn);
$tabort = $_POST['tabort_ja'];
if($_POST['tabort_ja']) {
$delete = "DELETE FROM auction WHERE id={$tabort}";
$resultat = mysql_query($delete) or die(mysql_error());
echo "Auktion har tagits bort";
echo "<br>";
echo "<br>";
echo '<a href="emil/admin.php">Tillbaka till startsidan</a>';
?>Thanks,
David