i have created a page which has a table that enables user to delete a record via a delete button but somehow the queary isnt working.

php coding

<?php

include("dbase.php");

$idURL = $_GET['id'];

// Connect to database server
mysql_connect("localhost", "root", "") or die (mysql_error ());

// Select database
mysql_select_db("studiobooking") or die(mysql_error());

// The SQL statement that deletes the record
$query = "DELETE FROM studio WHERE id = '$idURL'";
$result = mysql_query($query);


if($result)
{
 echo ('<script type="text/javascript">alert("Record is Deleted !");
                    window.location = "BookingnDisplay.php"</script>');
 }

// Close the database connection
mysql_close();
?>

the part that doesnt work:

$query = "DELETE FROM studio WHERE id = '$idURL'";
$result = mysql_query($query);

but the if($result) runs.

any ideas? thanks in advance!

Recommended Answers

All 4 Replies

Member Avatar for diafol

Don't use this on a live site!

Without login/session and input sanitizing, you could lose all your data or worse still you could have all your data exposed by SQL injection.

Check for the number of affected rows.

i don't understand. how does this solve my problem?

i don't understand. how does this solve my problem?

If number of affected rows equals 0 no rows were deleted. That might be the case if no rows matched $idURL.

But to check there are no other issues, use simple debugging technique - insert this code right after line 14:

die($query);

This will display the query as in its final form and stop the script. Now inspect the query or copy it to phpmyadmin and test it.

And take a note from the previous post: do clean the data received from the GET. And drop the mysql extension - switch to mysqli.

Member Avatar for diafol

i don't understand. how does this solve my problem?

As broj1 has elucidated,

mysql_affected_rows()

will give you the number of rows deleted. I hope that's clear enough for you.

The other info was there to help you avoid the pitfalls of noob security issues.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.