im tryn to delete a complete row from the database but when i click the delete link i get this error Query was empty.can someone pls help me <?php /* deletemovie.php delete movies from the database */ session_start(); ob_start(); include("includes/conn.php"); include("auth.php"); include("../template/header.html"); //$id=$_GET['memberid']; //$sq1="SELECT * FROM `movie_info` WHERE `memberid`='$_GET[memberid]'"; //$result=mysql_query($sql) or die(mysql_error()); //$row=mysql_fetch_array($result); $sql="DELETE * FROM `movie_info` WHERE memberid = '$_GET[memberid]'"; $result=mysql_query($sql) or die(mysql_error()); echo "Deleted"; header("Location:manage_movies.php"); exit(); ?> Code (markup):
give this a go: <?php /* deletemovie.php delete movies from the database */ session_start(); ob_start(); include("includes/conn.php"); include("auth.php"); include("../template/header.html"); $id=!empty($_GET['memberid']) ? $_GET['memberid'] : ""; if($id == ""){ echo "no id"; die(); }else{ $sql="DELETE FROM `movie_info` WHERE memberid = '".$id."'"; $result=mysql_query($sql) or die(mysql_error()); echo "Deleted"; header("Location:manage_movies.php"); exit(); } ?> PHP:
No need for the "else" when you die in the "if". And remember to use intval() and mysql_real_escape_string() to prevent MySQL injections. Ah yeah, and as for the error, remove the asterisk from your query. DELETE queries don't support these as you can't delete fields. (Not using DELETE queries at least) EDIT: And on a further note, you cannot redirect using header() after you've sent output to the browser. So remove the echo as well.
yeah, a bettter way to go about notifying the user that the row was deleted would be something like this: header("Location:manage_movies.php?message=Deleted"); PHP: and then out this code in manage_movies.php where you want the message to display: <?php if ($_GET['message']) { echo "<h2>" . $_GET['message'] . "</h2>"; } ?> PHP: or you can do whatever formatting you want, doesn't have to be H2