0

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.

4
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by phorce
1

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

1

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.

1

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

Try:

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

Other than that, output $name

0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.