-2

I have created a simple page which will be displayed after logging in. From that page, I print my html code in it with the SELECT option for the user to select the items they needed.

This is the code.

<?php  //Start the Session
session_start();
require('connect.php');

if (isset($_POST['email']) and isset($_POST['password'])){


$username = $_POST['email'];
$password = $_POST['password'];

$query = "SELECT * FROM `user` WHERE email='$username' and password='$password'";
$result = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($result);

if ($count == 1){
$_SESSION['email'] = $username;

print '
<html>
<body>
<br>
<form action="" method="POST">
Shirt:
<select name="shirt_string">
    <option value=" "> </option>
    <option value="Long Sleeves">Long Sleeves</option>
    <option value="Short Sleeves">Short Sleeves</option>
    <option value="T-Shirt">T-Shirt</option>
    <option value="Singlet">Singlet</option>
</select> </br>
<br>
Pants:
<select name="pants_string">
    <option value=" "> </option>
    <option value="Dress pants">Dress pants</option>
    <option value="Shorts">Shorts</option>
    <option value="Jeans">Jeans</option>
    <option value="Chinos">Chinos</option>
</select> </br>
<br>
Shoes:
<select name="shoes_string">
    <option value=" "> </option>
    <option value="Dress shoes">Dress shoes</option>
    <option value="Slipper">Slipper</option>
    <option value="Sneakers">Sneakers</option>
    <option value="Track shoes">Track shoes</option>
</select> </br>
<br>
<input type="submit">
<br/>
<br/>
<a href="login.php?action=logout">Log out</a>

</form>
</body>
</html>
';
echo $_POST['pants_string'];
}
else
{
    echo "Invalid Login Credentials.";
}
}

if (isset($_SESSION['email'])){
$username = $_SESSION['email'];

}else{}


echo "<br />\n";
$now = new DateTime();
$Singapore = new DateTimeZone('Asia/Singapore');
$now->setTimezone($Singapore);
echo $now->format('F j, Y h:ia');

?>

From the above codes, how am I supposed to get the value from the SELECT option to php?

I tried calling something like $_POST['pants_strings']; but it does not work.

EDIT: This is the full code.

Luke
  • 85
  • 2
  • 2
  • 13
  • Possible duplication of http://stackoverflow.com/questions/17139501/using-post-to-get-select-option-value-from-html – P Clegg Feb 10 '15 at 03:05
  • where and how you call $_POST['pants_strings'] please provide your complete code. i think you may have a small mistake. – Shahadat Hossain Khan Feb 10 '15 at 03:11
  • please provide full code. otherwise we can't help you dear – Shahadat Hossain Khan Feb 10 '15 at 03:16
  • so, you trying to get value before it submitted? i'm afraid, its not possible :( you checking credential by email and password. but its not in form. so when after validation when user submit your form its evaluate without email and password. so credential is not valid that moment – Shahadat Hossain Khan Feb 10 '15 at 03:26
  • @ShahadatHossainKhan I want to get the value after clicking the submit button. – Luke Feb 10 '15 at 03:28
  • you checking credential by email and password. but its not in form. so when after validation when user submit your form its evaluate without email and password. so credential is not valid that moment – Shahadat Hossain Khan Feb 10 '15 at 03:29

1 Answers1

1

Its not the problem of "select" option of PHP. Please take a look at your form, you are checking credential by email and password, but email and password not in form that is generated by PHP after checking credential. So, after validation when user submit your form its evaluate without email and password. So credential is not valid that moment.

So, put user and password in hidden field (but its not a good idea) OR handle valid user login through session.

Yes, Definitely use sessions (php.net/manual/en/book.session.php). DO NOT include user name / password in hidden fields (and be sure to always SHA1 the password) - thanks to @Mawg