akshay Posted January 27, 2010 Share Posted January 27, 2010 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 More sharing options...
jl5501 Posted January 27, 2010 Share Posted January 27, 2010 You need to quote the array elements $_POST['products'] Link to comment https://forums.phpfreaks.com/topic/189982-_post-select-elements-problem/#findComment-1002342 Share on other sites More sharing options...
akshay Posted January 29, 2010 Author Share Posted January 29, 2010 PROBLEM RESOLVED wow... It solved the problem! Thank you! Link to comment https://forums.phpfreaks.com/topic/189982-_post-select-elements-problem/#findComment-1003722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.