Aymen++
04-19-2004, 05:06 PM
this code didn't work for me:
<?php
function doDB() {
global $conn;
$conn = mysql_connect("localhost", "root", "123456") or die(mysql_error());
mysql_select_db("Aymen", $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><strong>Your E-Mail Address:</strong><br>
<input type=text name='email' size=40 maxlength=150>
<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><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>You'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>Subscribe/Unsubscribe</title>
</head>
<body>
<h1>Subscribe/Unsubscribe</h1>
<?php echo $display_block; ?>
</body>
</html>
always when i run it will return to the same page with the same components, i think my _POST variable doesn't work. can anybody tell me what is the reason.
<?php
function doDB() {
global $conn;
$conn = mysql_connect("localhost", "root", "123456") or die(mysql_error());
mysql_select_db("Aymen", $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><strong>Your E-Mail Address:</strong><br>
<input type=text name='email' size=40 maxlength=150>
<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><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>You'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>Subscribe/Unsubscribe</title>
</head>
<body>
<h1>Subscribe/Unsubscribe</h1>
<?php echo $display_block; ?>
</body>
</html>
always when i run it will return to the same page with the same components, i think my _POST variable doesn't work. can anybody tell me what is the reason.