This has baffled me to no end:
<?php
include("config.php");
// add, edit or delete
if ($action == 'add') {
$sql = "INSERT INTO stories_pics VALUES('','$pics_stories_id','$images_id','$title','$sort')";
$message = "Image $images_id has been added!";
} elseif ($action == 'edit') {
$sql = "UPDATE stories_pics SET
pics_images_id = '$images_id',
pics_title = '$title',
pics_sort = '$sort'
WHERE pics_id = $pics_id";
$message = "Image $images_id has been updated!";
} elseif ($action == 'remove') {
$sql = "DELETE FROM stories_pics WHERE pics_id = $pics_id";
$message = "The image has been removed!";
}
// run query
$result = mysql_query($sql);
// redirect to main page
header("Location: storyimages.php?pics_stories_id=$pics_stories_id&message=$message");
exit;
?>
The above has three options: add, edit or remove. Add or edit work exactly how I want. Remove gives me the following error:
Error: 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 '' at line 1
The odd part is though, despite this supposed sytax error, the item in the database I want deleted is deleted. Furthermore, I've used this exact same system for four other tables in my database and the remove section works just fine. Lastly, if I comment out the "header" portion at the bottom, I don't get the syntax error. (Of course, I also don't get what I want, but...) . If I comment out everything in the remove section, I still get the error, despite the fact I'm not running a MySQL statement anymore.
Is there a correlation between MySQL syntax errors and php header functions? And even if so, why would the header work for the add and edit sections, but not the remove section?
The "config.php" include contains my db password stuff and since the database is actually deleting the entry, (and I've had no other connectivity problems) I can't imagine that has anything to do with it.
http://www.livinglegend.org/phpinfo.php
The more I think on it, the less sense it makes!