twilitegxa Posted July 7, 2009 Share Posted July 7, 2009 I have a newsletter subscription code I am writing, but I am receiving the following error: Parse error: parse error in C:\wamp\www\manage.php on line 80 And the code will not run at all. But, if I take out the code that contains the error ( a } on line 80), most of the code works. It allows an e-mail address to subscribe, it prints a message if a duplicate e-mail tries to subscribe, it prints a message if the e-mail address doesn't exist upon attempting to unsubscribe, but it produces this error if someone tries to unsubscribe: Notice: Undefined variable: display_block in C:\wamp\www\manage.php on line 88 How can I fix this problem? It appears I have defined the variable, but I also would like to know why I received the parse error before, because I was under the impression that the } was needed. Can anyone help? Here is the code without the { (it is supposed to go right above the ending php tag [?>]): <?php //set up a couple of functions function doDB() { global $conn; //connect to server and select database; you may need it $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); } function emailChecker($email) { global $conn, $check_result; //checl that e-mail is not already in list $check = "select id from subscribers where email = '$email'"; $check_result = mysql_query($check,$conn) or die(mysql_error()); } //determine if they need to see the form or not if ($_POST['op'] !="ds") { //they do, so create form block $display_block = " <form method=POST action=\"$_SERVER[php_SELF]\"> <p><strong>Your E-Mail Address:</strong><br> <input type=text name=\"email\" size=40 maxlength=150></p> <p><strong>Action:</strong><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['op'] == "ds") && ($_POST['action'] == "sub")) { //trying to subscribe; validate email address if ($_POST['email'] == "") { header("Location: manage.php"); exit; } //connect to database doDB(); //check that email is in list emailChecker($_POST['email']); //get number of results and do action if (mysql_num_rows($check_result) < 1) { //add record $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 { //print failure message $display_block = "<p>You're already subscribed!</p>"; } } else if (($_POST['op'] == "ds") && ($_POST['action'] == "unsub")) { //trying to unsubscribe; validate email address if ($_POST['email'] == "") { header("Location: manage.php"); exit; } //connect to database doDB(); //check that email is in list emailChecker($_POST['email']); //get number of results ad do action if (mysql_num_rows($check_result) < 1) //print failure message $display_block = "<p>Couldn't find your address!</p> <p>No action was taken.</p>"; } else { //unsubscribe the address $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>Subscribe/Unsubscribe</title> </head> <body> <h1>Subscribe/Unsubscribe</h1> <?php echo "$display_block"; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
priti Posted July 7, 2009 Share Posted July 7, 2009 Wish you must have shown us line 80 code it make one to debug your code around that line. !! Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted July 7, 2009 Share Posted July 7, 2009 you need to start indenting your code, try an editor with a syntax highlighter... i think like 5 or 6 of your { } are mis aligned... some arent even there Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 7, 2009 Author Share Posted July 7, 2009 This is the beginning of line 80: } ?> <html> <head> <title>Subscribe/Unsubscribe</title> </head> <body> <h1>Subscribe/Unsubscribe</h1> <?php echo "$display_block"; ?> </body> </html> But I think the error is above, somewhere maybe in these lines: 73-79 } else { //unsubscribe the address $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>"; } Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 7, 2009 Author Share Posted July 7, 2009 Also, I am using DreamWeaver to write my code and it does highlight the code, plus my lines are indented. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 7, 2009 Author Share Posted July 7, 2009 Because you mentioned my missing {'s, I was able to find where I was missing one. I added a { to line 69: if (mysql_num_rows($check_result) < 1) { It was missing there, and then when I added the } back to line 80, the problem was solved. Thanks for the help! 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.