1

Im having trouble trying to find out why my script wont delete a row in my table.

Each user has a randomkey assigned to them. I need to say delete row in table where random key equals that to the user...

<?php 

$userRand = $_GET['Rand'];

$delUser = mysql_query("DELETE from users WHERE randomkey = '" . mysql_real_escape_string($userRand));
        if(! $qResult )
            {
                die('Could not delete data: ' . mysql_error());
            }
        elseif($qResult )
            {
                echo "deleted"; 
            }

?>

the following outputs...

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''111111111' at line 1
2
  • 1
    not related completly, but for a delete operation you should use POST and not GET. this will prevent some problems (like an image with this script in the url) Commented Jul 17, 2011 at 19:56
  • Indeed, POSTs for modifications, GETs only for retrieval. Commented Jul 17, 2011 at 21:43

2 Answers 2

2

You're missing the closing ' in your PHP code.

$delUser = mysql_query("DELETE from users WHERE randomkey = '" . mysql_real_escape_string($userRand) . "'");
Sign up to request clarification or add additional context in comments.

Comments

1

You are not closing the SQL-String.

$delUser = mysql_query(
    sprintf("DELETE from users WHERE randomkey = '%d'", mysql_real_escape_string($userRand)
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.