PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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=''" . $row['auktionnamn'] . ">";
echo "<br>";
echo '</form>';
echo "<br>";
echo "<input type='submit' name='submit' value='Få fram fakta'>";
//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>";
//break;
//}
if($_POST['tabort_ja'])
{
$tabort=addslashes($_POST['tabort_ja']);
mysql_unbuffered_query("DELETE FROM auction WHERE id=$tabort");
}
if(!$result=mysql_query("SELECT id,auktionnamn,item,datum_borja,maxantalbud,antalbud,bild,marknadsvarde,info,status FROM `auction` ORDER BY `id`"))echo(mysql_error());
}
?>
The checkbox got the value zero so none gets deleted. How should i solve it?
Thanks
Okey. Well first there is a script which shows all data from a mysql table and shows it in a select many. And then when you press submit You should get a checkbox with the value of the id of that mysql row. And then when you press on that submit button that row should get deleted.
Understand?
Thanks
NiGHTFiRE wrote:Okey. Well first there is a script which shows all data from a mysql table and shows it in a select many. And then when you press submit You should get a checkbox with the value of the id of that mysql row. And then when you press on that submit button that row should get deleted.
Understand?
Thanks
Yes, but are you saying the value in all the checkboxes are zero, or that when you get to the DELETE portion of your code, the value is zero? Have you checked the HTML source output from the script? One thing I can see is you're using addslashes to the value of $_POST['tabort_ja'], which appears to be the ID value brought down from the form submission. Are you certain magic_quotes are off? Do you need to use an escaping slash at this point? Would it make more sense to use is_numeric() on the $_POST index value first?
Is this code responsible for the checkbox with the ID value?
This is the output of it:
<input type="checkbox" name="tabort_ja" value="">
So the value is empty. Don't know how i will give it the id of that row.
$row['auktionnamn'] is a name, $row['id'] is the id of that row but it doesn't work.
NiGHTFiRE wrote:This is the output of it:
<input type="checkbox" name="tabort_ja" value="">
So the value is empty. Don't know how i will give it the id of that row.
$row['auktionnamn'] is a name, $row['id'] is the id of that row but it doesn't work.