php - MYSQL query using a set of values (values stored from a session array) not working -


i'm beginner , i'm doing project (a shopping cart). user can add product cart , id of product stores in session. when use ids echo out price db it's not working. i'm using php & mysql. here code

if(count($_session['cart_items'])>0){ // getting product ids $nos = ""; foreach($_session['cart_items'] $no=>$value){     $nos = $nos . $no . ","; } // removing last comma $nos = rtrim($nos, ',');                          //echo $nos; (will display int values  1,2,3,4) $nos=mysql_real_escape_string($nos); $site4->dblogin(); $qry = "select * vendorproducts product_no in('.implode(',',$nos).')";         $result = mysql_query($qry); $row = mysql_fetch_assoc($result); echo $row['price']; } 

php not recursively embeddable:

$qry = "select * vendorproducts product_no in('.implode(',',$nos).')";                ^---start of string                                    end of string ---^ 

since you're in string, .implode(...) plain text, not executable code.

this means query illegal/invalid sql, , if had basic/minimal error checking, have been told this:

$result = mysql_query($qry) or die(mysql_error());                            ^^^^^^^^^^^^^^^^^^^^^^ 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -