Jump to content

Delete


nadinengland

Recommended Posts

Riiight im having trouble with my coding... *dur*

I want to be able to go to "delete.php" say with "?postID=10" at the end, and do the following...

[code]
<?php $con = mysql_connect("host","username","password");
mysql_select_db("database", $con);

$postIDdel = $_GET['postID'];

$sql_delete = 'DELETE FROM yearbook WHERE postID="$postIDdel"';
if (mysql_query($sql_delete,$con)) {
  mysql_query($sql_delete,$con);
  header("Location: http://www.tea-and-crumpets.com/yearbook/admin-delete.php");
  exit;
  }
else
  {echo "<b>Error deleteing post:</b> " . mysql_error();}

?>

[/code]

Now... that doesn't work... it does take you to admin-delete afterwords, but doesnt delete the post.

I know its something to do with the $sql_delete line, but im not sure what.

Thanks alot. nad
Link to comment
Share on other sites

[quote=nadinengland]
'DELETE FROM yearbook WHERE postID="$postIDdel"'
[/quote]

Variables are not expanded when inside a single quoted string.

Change the single quotes to double quotes and the doubles to singles. In the posted code snippet you also have 2 calls to mysql_query(). I assume you meant to only have the first one.

[quote=nadinengland]
if (mysql_query($sql_delete,$con)) {
  mysql_query($sql_delete,$con);
[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.