...

View Full Version : Redirect



Noumenon
02-09-2006, 07:09 PM
I'm trying to make this script to show the form when you first visit it, then when you submit it it does the things under action=subscribe or action=unsubscribe. Not working however. Ideas?



$act = $_POST['action'];
// THIS IS WHAT THE SCRIPT SHOULD DO IF subscribe IS SELECTED AND SUBMITTED THROUGH THE FORM
if ( $act == "subscribe" ) {
// setting variables
$email = $_POST[email];
// inserting values into database
$query = "SELECT email FROM newsletter WHERE email = '$email'";
$result = mysql_query($query);
if(mysql_num_rows($result) != 0) {
print "<FONT>Your email address already exist in our database.</FONT>";
} else {
$sql = "INSERT INTO `newsletter` (`id`, `email`) VALUES ('', '$email')";
$result = mysql_query($sql) or die ("Not working try again");
if($result) {
print "<FONT>You have been added to our Mailing List.</FONT>";
}
}
}
// THIS IS WHAT THE SCRIPT SHOULD DO IF unsubscribe IS SELECTED AND SUBMITTED THROUGH THE FORM
elseif ( $act == "unsubscribe" ) {
$query = "SELECT email FROM newsletter WHERE email = '$_POST[email]'";
$result = mysql_query($query);
if(mysql_num_rows($result) == 0) {
print "<FONT>Your Email doesnot exist in our Database.</FONT>";
} else {
$sql = "DELETE FROM `newsletter` WHERE email='$_POST[email]'";
$result = mysql_query($sql) or die ("Not working try again");
if($result) {
print "<FONT>Your Email address has been removed successfully.</FONT>";
}
}
// THIS IS THE FORM THAT SHOULD BE SHOWING WHEN YOU FIRST GO TO THE PAGE
else {
echo "<FORM NAME=\"newsletter\" ID=\"newsletter\" METHOD=\"post\" ACTION=\"<?php echo $PHP_SELF; ?>\">\n";
echo " <FONT CLASS=\"f2\">SUBSCRIBE TO NEWSLETTER</FONT>\n";
echo " <TABLE BORDER=\"0\" CELLSPACING=\"3\" CELLPADDING=\"0\">\n";
echo " <TR>\n";
echo " <TD ALIGN=\"right\" VALIGN=\"top\">\n";
echo " <INPUT TYPE=\"text\" NAME=\"email\" SIZE=\"16\" MAXLENGTH=\"70\" VALUE=\"&nbsp;your@email.here\" CLASS=\"formstyle\" OnFocus=\"javascript:this.select()\">\n";
echo " </TD>\n";
echo " <TD ALIGN=\"left\" VALIGN=\"top\">\n";
echo " <INPUT TYPE=\"image\" SRC=\"pics/go.gif\" NAME=\"submit\" VALUE=\"&nbsp;GO&nbsp;\" ALT=\"GO\" CLASS=\"submitstyle\">\n";
echo " </TD>\n";
echo " </TR>\n";
echo " <TR>\n";
echo " <TD COLSPAN=\"2\" ALIGN=\"center\" VALIGN=\"top\">\n";
echo " <INPUT TYPE=\"radio\" NAME=\"action\" VALUE=\"subscribe\" CHECKED><FONT>Subscribe</FONT><BR>\n";
echo " <INPUT TYPE=\"radio\" NAME=\"action\" VALUE=\"unsubscribe\"><FONT>Unsubscribe</FONT>\n";
echo " </TD>\n";
echo " </TR>\n";
echo " </TABLE>\n";
echo "</FORM>\n";
}

Noodles24
02-09-2006, 07:57 PM
Can you be a bit more specific than "it's not working" is there an error?

Noumenon
02-09-2006, 08:05 PM
Nothing is shown when first entering the page.
The form should be showing, it's not.

After that, when submitting the form it should do either the subcribe part or unsubscribe.

degsy
02-10-2006, 03:39 PM
You are missing a }

If you are not getting a parse error then check your error reporting



print "<FONT>Your Email address has been removed successfully.</FONT>";
}
}
}

Noumenon
02-11-2006, 12:30 AM
Thanx!

I fixed that, plus changed


echo "<FORM NAME=\"newsletter\" ID=\"newsletter\" METHOD=\"post\" ACTION=\"<?php echo $PHP_SELF; ?>\">\n";


to



echo "<FORM NAME=\"newsletter\" ID=\"newsletter\" METHOD=\"post\" ACTION=\"newsletter.php\">\n";


it works now :)

Al_90
02-11-2006, 12:33 AM
a } is usually the first reason a page turns up blank if you have php errors turned off, otherwise if they were on you would get an error message

Noumenon
02-11-2006, 01:15 AM
ok. don't have much control over that since I'm not running my own server.

degsy
02-13-2006, 04:56 PM
http://uk.php.net/error_reporting

You can add the code to your page(s)


// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting(E_ALL);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum