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
https://forums.phpfreaks.com/topic/26628-delete/
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
https://forums.phpfreaks.com/topic/26628-delete/#findComment-121793
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.