Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

PHP- why does this not select the posted value?



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<form action="testy.php" method="post">
<select name="listname">
<option value="php3"<? if(isset($_POST['listname']) && $_POST['listname'] == 'php3'){echo  ' selected = "selected" '; }?>> PHP 3</option>

<option value="php4"<? if(isset($_POST['listname']) && $_POST['listname'] == 'php3'){echo  ' selected = "selected"'; }?>> PHP 4</option>

<option value="php5"<? if(isset($_POST['listname']) && $_POST['listname'] == 'php3'){echo  ' selected = "selected"'; }?>>PHP 5</option>

</select>

<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
0
roscoeh23
Asked:
roscoeh23
1 Solution
 
AndyWHVCommented:
The Problem is the login in the if structure...

look at
if ( (isset($_POST['listname'])) && ($_POST['listname'] == 'php3') )

you check for php3 every time.

Greetz
Andy ;-)
0
 
T3LogicCommented:
<option value="php3"<? if(isset($_POST['listname']) == 'php3'){echo  ' selected = "selected" '; }?>> PHP 3</option>

<option value="php4"<? if(isset($_POST['listname']) == 'php4'){echo  ' selected = "selected"'; }?>> PHP 4</option>

<option value="php5"<? if(isset($_POST['listname']) == 'php5'){echo  ' selected = "selected"'; }?>>PHP 5</option>
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now