Won't delete data from mysql database

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!

Moderator: General Moderators

Post Reply
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Won't delete data from mysql database

Post by NiGHTFiRE »

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:

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&nbsp;&nbsp;&nbsp;<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?

Code: Select all

$sql2 = "DELETE * FROM auction WHERE id = $item_id LIMIT 1";
Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

A blank page often indicates there was a file level error. Check your error logs..
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Oh i typed it wrong there. I don't get a blank page. I come back to the select menu and see all info from my mysql database but nothing is deleted.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It would appear you're missing the auction id in the confirmation submission.
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

So $item_id is empty?
Woudn't $item_id = $_POST['auction']; give me an id?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It would have to be in the submission data. If you look over your confirmation form, there's no auction ID reference in it.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

NiGHTFiRE wrote:So $item_id is empty?
Woudn't $item_id = $_POST['auction']; give me an id?
Yeah it would if $_POST['auction'] exists and isn't empty. I can't see where you're doing that though.
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

d11wtq:
look at

Code: Select all

if (isset($_POST['auction']))

{

        // You would really want to validate this here,

        // But I am keeping this intentionally simple

       $item_id = $_POST['auction'];
Hight up in the script.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

NiGHTFiRE wrote:d11wtq:
look at

Code: Select all

if (isset($_POST['auction']))

{

        // You would really want to validate this here,

        // But I am keeping this intentionally simple

       $item_id = $_POST['auction'];
Hight up in the script.
Do you see anything like that in here:

Code: Select all

echo '<form method="post" action="tabortauktion.php">';

                echo 'Ta bort denna auktion: ';

                echo "<br>";

                echo " Ja&nbsp;&nbsp;&nbsp;<input type='checkbox' name='tabort_ja' value='tabort_ja'>";

                echo "<br";

                echo "<input type='submit' name='submit' value='Ta bort auktionen'>";

        echo '</form>';
No, you don't. So how is the auction ID getting to the delete code?
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Oh smart. :P
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 ?

Thanks
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

How would i do it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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.
Post Reply