elginwick Posted April 20, 2006 Share Posted April 20, 2006 I am trying to create a simple mailing list that the user can subscribe and unsubscribe to. I can get the new subscriptions and it works, but when i try to unsubscribe, i get this errorquery was emptyi don't know what is going wrong.Thanks.here is the code:<?phpfunction doDB() { global $conn; $conn = mysql_connect("localhost", "user", "pass"); mysql_select_db("db",$conn) or die(mysql_error());}function emailChecker($email) { global $conn, $check_result; $check = "select id from subscribers where email = '$email'"; $check_result = mysql_query($check,$conn) or die (mysql_error());}if ($_POST[op] != "ds") { $display_block = " <form method=POST action=\"$_SERVER[PHP_SELF]\"> <p><font color=\"#164059\">Your E-Mail Address:<br> <input type=text name=\"email\" size=40 maxlength=150> <p>Action:<br> <input type=radio name=\"action\" value=\"sub\" checked> subscribe <input type=radio name=\"action\" value=\"unsub\"> unsubscribe <input type=\"hidden\" name=\"op\" value=\"ds\"> <p><input type=submit name=\"submit\" value=\"Submit Form\"></p> </form>"; } else if (($_POST[op] == "ds") && ($_POST[action] == "sub")) { if ($_POST[email] == "") { header("Location: manage.php"); exit; } doDB(); emailChecker($_POST[email]); if (mysql_num_rows($check_result) < 1) { $sql = "insert into subscribers values('', '$_POST[email]')"; $result = mysql_query($sql,$conn) or die(mysql_error()); $display_block = "<p>Thanks for signing up!</p>"; } else { $display_block = "<p>Your're already subscribed!</p>"; }} else if (($_POST[op] == "ds") && ($_POST[action] == "unsub")) { if ($_POST[email] == "") { header("Location: manage.php"); exit; } doDB(); emailChecker($_POST[email]); if (mysql_num_rows($check_result) < 1) { $display_block = "<p>Couldn't find your address!</p> <P> No action was taken.</p>"; } else { $id = mysql_result($check_result, 0, "id"); $sql = "delete from subscribers where id = '$id'"; $result = mysql_query($sql,$conn) or die(mysql_error()); $display_block = "<p>You're Unsubscribed!</p>"; }}?><html><head><title>Newsletter Subscription</title><style type="text/css"><!--.style5 { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #164059;}body,td,th { font-family: Arial, Helvetica, sans-serif; color: #164059;}body { background-color: #FFFFFF;}a:link { color: #164059; text-decoration: none;}a:visited { text-decoration: none; color: #164059;}a:hover { text-decoration: none; color: #164059;}a:active { text-decoration: none; color: #164059;}--></style><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><div align="center"><span class="style5"><?php echo "$display_block"; ?></span></div></body></html> Quote Link to comment Share on other sites More sharing options...
Darkness Soul Posted April 20, 2006 Share Posted April 20, 2006 try to change these lines[code]} else {$id = mysql_result($check_result, 0, "id");$sql = "delete from subscribers where id = '$id'";[/code]for these ones[code]} else {$arr_result = mysql_fetch_array ( $check_result );$sql = "delete from subscribers where id = '$arr_result['id']'";[/code]I fast-read your code and can't see anything wrong..D.Soul Quote Link to comment Share on other sites More sharing options...
elginwick Posted April 20, 2006 Author Share Posted April 20, 2006 I am still getting the same error,it doesn't make sense to me. i have checked it over and over again, but to no avail. Quote Link to comment Share on other sites More sharing options...
Darkness Soul Posted April 20, 2006 Share Posted April 20, 2006 I just change little structure... but, never know.. try it..I need to go home, so, good luck with your code =)Bye, D.Soul[code]<?phpfunction doDB(){ global $conn; $conn = mysql_connect("localhost", "user", "pass"); mysql_select_db("db",$conn) or die(mysql_error());}function emailChecker($email){ global $conn, $check_result; $check = "select id from subscribers where email = '$email'"; $check_result = mysql_query($check,$conn) or die (mysql_error());}if ($_POST[op] != "ds"){ $display_block = "<form method=POST action=\"$_SERVER[PHP_SELF]\"> <p> <font color=\"#164059\">Your E-Mail Address:<br> <input type=text name=\"email\" size=40 maxlength=150> </p> <p> Action:<br> <input type=radio name=\"action\" value=\"sub\" checked> subscribe <input type=radio name=\"action\" value=\"unsub\"> unsubscribe <input type=\"hidden\" name=\"op\" value=\"ds\"> </p> <p> <input type=submit name=\"submit\" value=\"Submit Form\"> </p></form> ";}else if ($_POST[action] == "sub"){ if ($_POST[email] == "") { header("Location: manage.php"); exit; } doDB(); emailChecker($_POST[email]); if (mysql_num_rows($check_result) < 1) { $sql = "insert into subscribers values('', '$_POST[email]')"; $result = mysql_query($sql,$conn) or die(mysql_error()); $display_block = "<p>Thanks for signing up!</p>"; } else { $display_block = "<p>Your're already subscribed!</p>"; }} else if ($_POST[action] == "unsub"){ if ($_POST[email] == "") { header("Location: manage.php"); exit; } doDB(); emailChecker($_POST[email]); if (mysql_num_rows($check_result) < 1) { $display_block = "<p>Couldn't find your address!</p> <P> No action was taken.</p>"; } else { $id = mysql_result($check_result, 0, "id"); $sql = "delete from subscribers where id = '$id' limit 1"; $result = mysql_query($sql,$conn) or die(mysql_error()); $display_block = "<p>You're Unsubscribed!</p>"; }}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.