akshay Posted February 28, 2010 Share Posted February 28, 2010 Hello. My codes for these pages produce errors: array.php errors: Warning: array_merge() [function.array-merge]: Argument #1 is not an array in D:\wamp\www\test\session\array.php on line 12 Warning: array_unique() [function.array-unique]: The argument should be an array in D:\wamp\www\test\session\array.php on line 12 array_read.php errors: Warning: Invalid argument supplied for foreach() in D:\wamp\www\test\session\array_read.php on line 12 Basically, I'm trying to add products to cart and display them. Simple! Then, why so many errors? Also, I didnt understand what serialize() and unserialize() are for, despite referring to php.net manual My coding: array.php: <?php session_start(); //Turn off Notices $ebits = ini_get('error_reporting'); error_reporting($ebits ^ E_NOTICE); //Notices Turned OFf if(isset($_POST['form_products'])) { if(!empty($_POST['form_products'])) { $products=array_unique(array_merge(unserialize($_SESSION['products']),$_POST['form_products'])); } $_SESSION['products']=serialize($products); print "Your products have been saved!"; } ?> <html> <body> <form method="post" action="<?php print $_SERVER[php_SELF] ?>">; <p>Select some products:</p> <select name="form_products[]" multiple size=3> <option>iBall Li'l Book 1710</option> <option>Lenovo S10 Netbook</option> <option>ASUS Netbook</option> </select><br><br> <input type="submit" value="Add to Cart"></form><br> <a href="array_read.php">Array Read</a> </body></html> array_read.php : <?php //Turn off Notices $ebits = ini_get('error_reporting'); error_reporting($ebits ^ E_NOTICE); //Notices Turned OFf session_start(); if(isset($_SESSION['products']) && !empty($_SESSION['products'])) { echo "Your cart:<ol>"; foreach($_SESSION['products'] as $p) { print "<li>$p</li>"; } print "</ol>"; } echo '<br><br><a href="/test/session/array.php">Back to Product Choices</a>'; ?> Thanks a lot! Akshay Link to comment https://forums.phpfreaks.com/topic/193669-_session-variables-producing-warnings/ Share on other sites More sharing options...
inversesoft123 Posted February 28, 2010 Share Posted February 28, 2010 Try Changing this if(!empty($_POST['form_products'])) { $products=array_unique(array_merge(unserialize($_SESSION['products']),$_POST['form_products'])); } to if(!empty($_POST['form_products'])) { $newnew= array_merge(unserialize($_SESSION['products']),$_POST['form_products']); $newnew = array(); $products=array_unique($newnew); } Not sure but try Link to comment https://forums.phpfreaks.com/topic/193669-_session-variables-producing-warnings/#findComment-1019399 Share on other sites More sharing options...
teamatomic Posted February 28, 2010 Share Posted February 28, 2010 <option value="need_a_value_or_what_gets_passed">OPTION</option> HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/193669-_session-variables-producing-warnings/#findComment-1019419 Share on other sites More sharing options...
akshay Posted March 1, 2010 Author Share Posted March 1, 2010 Hey. Errors occur no more by array_read.php din't show up a single selected product! Pls. help. Thanks. Link to comment https://forums.phpfreaks.com/topic/193669-_session-variables-producing-warnings/#findComment-1019713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.