Jump to content

$_POST[] select elements problem!


akshay

Recommended Posts

Hello.

 

I'm reading Sams - Teach Yourself PHP, mySQL, Apache in 24 hours.

 

It's going great, but...

 

I used this code :

 

select.php :

 

<html>...
<form method="POST" action="sql_select.php">

Welcome to KrisShop<br><Br>

Name:<input type="text" name="name"><BR>
Address & Contact Details: <textarea name="address"></textarea>
<Br><Br>
Please select the products you wish to buy:<BR><BR>

<select name="products[]" multiple>
<option>Microwave Oven</option>
<option>Apple iTouch</option>
<option>Blackberry</option>

</select>
<Br>

<input type="submit" value="♥ Submit ♥">
</form><body>

</body>
</html>

 

sql_select.php :

 

<?php
print "Welcome <b>$_POST[name]</b><p>\n\n";
print "Your address is:<p>\n\n<b>$_POST[address]</b><p>\n\n";
print "Your product choices are:<p>\n\n";
if (!empty($_POST[products])) {
      print "<ul>\n\n";
foreach ($_POST[products] as $value) {
    print "<li>$value\n";
     }
      print "</ul>";
}


?>

 

It does print Name and Address properly.

 

But, SELECT element - 'products' are printed with warnings:

 

Example:

 

* Microwave Oven

* Blackberry

Notice: Use of undefined constant products - assumed 'products' in D:\wamp\www\test\sql_select.php on line 32

 

Wherever, 'products' variable is used, these warnings (notice) appear with output, I've tried 'products[]' and 'products' too.

 

I tried adding $a=$_POST[products]; and adding $_POST[products] in the entire code by $a, one notice was eleminated, but, another one, next to "foreach" loop still appears.

 

Thank you :)

Best Regards

Akshay

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/189982-_post-select-elements-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.