Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: _POST variable

  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    _POST variable

    this code didn't work for me:
    Code:
     
    <?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.

  • #2
    New Coder
    Join Date
    Apr 2004
    Location
    Texas
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...
    Last edited by black3842; 04-20-2004 at 02:59 AM.
    Jason B

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The enctype shouldnt make any difference, you should only need to use that for sending files.

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i changed it but it was the same

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    for simplification this code in one page:
    Code:
    <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:
    Code:
    <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.

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •