Hi am trying to delete a row from a mysql database and can't work out why it is not working.

Here is the code

$link = mysql_connect('', '', '') or die('Could not connect: ' . mysql_error()); 
    mysql_select_db('') or die(mysql_error()); 

mysql_query("DELETE FROM gigs WHERE gigname='".$name."'");

mysql_close($link);

The $link is working, and $name is taken from url, do I need a $name=£_GET['name'] as I tried that but it didn't work.

Any help very appreciated.

echo your $name, also paste your url address here, seems like you are not passing correctly the name parameter.

You would need to set $name to equal $_GET['name'] (dependent on the URL). The first step is showing us the URL you have used, as Majestics said. You might not be using the correct key name for the gig name in the URL.

Have you also checked for SQL errors? You can use:

echo mysql_error();

Although your SQL looks correct, you may be trying to pass something in the URL which will invalidate the query, especially if it contains quotes. I recommend using mysql_real_escape_string($str) in this instance.

As a side note, I would totally recommend using PDO, which has prepared statements, amongst other benefits, meaning you do not need to use the verbose and ugly mysql_real_escape_string() and a lot of concatenation.

As mentioned before though, we really need to see the URL to diagnose the problem.

mysql_query("DELETE FROM gigs WHERE gigname='".$name."'");

Try:

mysql_query("DELETE FROM gigs WHERE gigname='$name'");

Other than that, output $name

Thanks for the help, it turned out it was working ok but that the one row I was trying to delete had special characters in as I must have entered it before I changed that part of the script.

Aha no problem :) Good luck with your application, if you need help with anything else - Please feel free to post!

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.