Thank you for your question about implementing the shopping cart. Session_start ();
Include ("conn/conn. php ");
If ($ _ SESSION [username] = ""){
Echo "script" alert ('Please log on first and then shop! '); History. back (); script ";
Exit;
}
$ Id = strval ($ _ GET [id]);
$ SQL = mysql_query ("select * from tb_shangpin where id = '". $ id. "'", $ conn );
$ Info = mysql_fetch_array ($ SQL );
If ($ info [shuliang] <= 0 ){
Echo "script" alert ('This item has been sold out! '); History. back (); script ";
Exit;
}
$ Array = explode ("@", $ _ SESSION [producelist]);
For ($ I = 0; $ I If ($ array [$ I] ==$ id ){
Echo "script" alert ('This item is already in your shopping cart! '); History. back (); script ";
Exit;
}
}
$ _ SESSION [producelist] =_ _ SESSION [producelist]. $ id ."@";
$ _ SESSION [quatity] =_ _ SESSION [quatity]. "1 @";
Header ("location: gouwu1.php ");
?>
Why should I subtract one from the count ($ array) Above? thank you!
Reply to discussion (solution)
Because the $ _ SESSION [producelist] =$ _ SESSION [producelist]. $ id ."@";
$ _ SESSION [producelist] content ends @
After explode, the last element of $ array is empty.
Because the $ _ SESSION [producelist] =$ _ SESSION [producelist]. $ id ."@";
$ _ SESSION [producelist] content ends @
After explode, the last element of $ array is empty.
Thank you very much.