...

View Full Version : _POST variable



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.

black3842
04-20-2004, 02:45 AM
Try changing
this
<form method=POST action=\"$_SERVER[PHP_SELF]\">
to
<form method=POST action=\"$_SERVER[PHP_SELF]\" ENCTYPE=\"multipart/form-data\">

or u can use this if you want it to use a fully qualified URL for the post
<FORM METHOD=POST ACTION=\"http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."\" ENCTYPE=\"multipart/form-data\">

- hope this helps...

missing-score
04-20-2004, 09:00 AM
The enctype shouldnt make any difference, you should only need to use that for sending files.

Aymen++
04-20-2004, 02:27 PM
i changed it but it was the same

Aymen++
04-20-2004, 02:56 PM
for simplification this code in one page:


<html>
<form action='next.php' method=get>
<input type='textbox' name='somevariable' size="20">
<input type='submit' value='Submit'>
</form>
<body>
</body>
</html>

and this is the next.php page:


<html>
<body>
<?php
echo $_POST[somevariable];
?>
</body>
</html>

this code didn't work with me also, after pressing Submit button the next.php is empty.

Nightfire
04-20-2004, 03:05 PM
That's due to you using GET in the form
method=get>

If you want to use GET, then use the super global $_GET['variable'] and not $_POST



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum