This is the drop down list of security questions:

<form action="ddlprocess.php" method="post">
	<select name="security1">
	<option value="placeOfBirth">What city were you born in?</option>
	<option value="childhoodFriend">Who was your childhood best friend?</option>
	<option value="mothersMaiden">What is your mother's maiden name?</option>
	<option value="mothersMiddle">What is your mother's middle name?</option>
	<option value="fathersMiddle">What is your father's middle name?</option>
	</select><br />
	<input type="submit" value="Register"></input>
		
</form>

This is the page to process it (ddlprocess.php):

<?php 

if ($_POST['security1'])

{
		// db connection established
				
	$sq1 = ($_POST['security1']) or die("evil bug " . mysql_error());		
			
		echo $security1 or die("cannot find security1 ");

}
?>

When php echoes security1, it gives me the number 1 instead of the value of the drop down list.

I have scoured the web and search engines trying to find someone with a similar problem or to learn additional information on how $_POST works, and i have learned nothing but that this should be working the way it is!

Heeellllppp Meeeeee Pleeaasssee!!!:(

Dani AI

Generated

Short diagnosis and a safe fix (two things were happening in the original snippet).

  1. A variable-name mix-up: the form value was assigned to $sq1 but the script echoed $security1, so the displayed output came from an expression, not the intended string. 2) Combining output and an or check on one line (for example echo ... or die(...)) can produce a 1 because PHP can evaluate the boolean result of the expression instead of printing the raw string. Separating checks, assignments and output avoids that ambiguity.

Quick, robust example (put near the top of the processing script):

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $selected = filter_input(INPUT_POST, 'security1', FILTER_SANITIZE_SPECIAL_CHARS);
    var_dump($selected);                           // exact type and value for debugging
    echo htmlspecialchars($selected ?? 'no value', ENT_QUOTES, 'UTF-8');
}
?>

Practical checklist:

  • Turn on full error reporting (shown above) and inspect the POST payload (browser devtools Network tab) to confirm the field name is security1.
  • Ensure the same variable name is used for assignment and output (no $sq1 vs $security1 mismatch).
  • Do not mix echo/print and or die(...) on the same line — separate the operations or use explicit conditionals.
  • Use htmlspecialchars when echoing into HTML and validate/sanitize before any DB work (use prepared statements).

Notes on prior replies: was right to suggest directly reading the POST value for testing; adding the error-reporting + var_dump step will reveal whether the problem is a name typo, a missing POST key, or the operator-precedence issue. ’s early copy of $_POST can be a useful workaround, but copying should come after diagnosing the root cause so the bug isn’t hidden.

Recommended Answers

All 5 Replies

Use:

echo $_POST['security1'];

and get rid of the or die() statement as that is not how its suppose to be used.

Don't use:

if ($_POST['security1']) {

You need to use isset() otherwise you will get errors.

When I use "isset" I get errors. I fixed the other, but it still gives me the same response.

<?php

if ( isset( $_POST['security1'] ) ) {
	echo $_POST['security1'];
}
else {
	echo 'Security1 not set';
}

?>

That should work. There is no reason why it shouldn't.

You can also put echo '<pre>' . print_r( $_POST,true ) . '</pre>'; to check the values of post.

I still get the same response. Number 1 and not POST value.

I dont know if you are still having this problem or not, but I was having the same exact problem. To solve it I copied the POST array to an alternate array at the very start of the script. I then used the alternate array instead of POST. For what ever reason POST is changed by the time I called it later in my script.

Verified by print_r($_POST) at start and then again print_r($_POST) at time of calling.

Corrected by placing POST in alternate array:

if($action == "register")
{
    $user_name  = $_POST['USER_NAME'];
    $password1  = isset($_POST['PASSWORD1']);
    $password2  = isset($_POST['PASSWORD2']);
    $email      = isset($_POST['EMAIL']);
    $first_name = isset($_POST['FIRST_NAME']);
    $last_name  = isset($_POST['LAST_NAME']);
    $phone      = isset($_POST['PHONE']);

    $registerData = array('USER_NAME'=>$user_name,'PASSWORD1'=>$password1, 'PASSWORD2'=>$password2, 'EMAIL'=>$email,'FIRST_NAME'=>$first_name, 'LAST_NAME'=>$last_name, 'PHONE'=>$phone);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.