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!
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:
<?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>";
}
}
?>
I just get a blank page but it doesn't delete anything so is it anything wrong with my mysql delete query?
if (isset($_POST['auction']))
{
// You would really want to validate this here,
// But I am keeping this intentionally simple
$item_id = $_POST['auction'];
if (isset($_POST['auction']))
{
// You would really want to validate this here,
// But I am keeping this intentionally simple
$item_id = $_POST['auction'];
Oh smart.
I'll try to fix it tomorrow. Would i do the checkbox: <input type='checkbox' name='tabort_ja' value='$row[id]'>
And fix the $row ? Or how would i do it? $item_id ?
Try stuff, figure it out.. and bumping inside the 24 hour limit isn't cool.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not recieve a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.