mysql - PHP language about shopping cart update -


sorry, i'm getting problem updating, in php, shopping cart. have been looking solution 2 days no avail. can provide advice me?

<?php if(isset($_post["act"])) {     if(isset($_post["updspc"]))     {         $id_form=$_post["id_form"];         $countid=count($id_form);            $sl=$_post["p_qty"];         $total=$_post["total"];         if(isset($_session["user"]))         {             for($i=0;$i<$countid;$i++)             {                            if($sl[$i]<=0)                     $del=mysql_query("delete pia_spcart id='$id_form[$i]' , p_stt1='addspcart1'");                 else{                        $tt[$i]=$total[$i]*$sl[$i];                 $sql2="update pia_spcart set p_qty=$sl[$i] user='$user' , id='$id_form[$i]' , p_stt1='addspcart1'";                 $sql2.=';';                 echo "sql2: $sql2<hr>";                 $kq2=mysql_query($sql2);                 }              }                    }            }         if(isset($_post["delspc"]))     {         $delete=$_post["delete"];                    $deletecount=count($_post["delete"]);         if($deletecount==0)             echo "<script>alert('please choose products delete');</script>";         else{             ($j=0;$j<$deletecount;$j++)             {                    $sql_delspc = "delete pia_spcart user='$user' , id='$delete[$j]' , p_stt1='addspcart1'";                 $kq_delspc=mysql_query($sql_delspc);                 $n+=mysql_affected_rows();             }                            }            }      if(isset($_post["order"]))     {         $id_form=$_post["id_form"];          $countid=count($id_form);         $now=date("y-m-d h:i:s");         $p_qty=$_post["p_qty"]; //      $total=$_post["total"];         for($k=0;$k<$countid;$k++)         {                        //$id_f=implode($_post["id_form"], "','");             $sql_kt="select * pia_spcart id='$id_form[$k]' , user='$user' , p_stt1='order'";         //  echo "$sql_kt<hr>";             $kq_kt=mysql_query($sql_kt);                         if(mysql_num_rows($kq_kt)==0)             {                        $sql_order="update pia_spcart set p_stt1='order',p_orddate='$now' id='$id_form[$k]' , user='$user' , p_stt1='addspcart1'";                 $kq_dathang=mysql_query($sql_order);                             echo "<script>window.location='index.php?pia=listcart';</script>";             }             else             {                 while($r_kt=mysql_fetch_array($kq_kt))                 {                     $sl_kt=$r_kt["p_qty"];                 //  echo "$sl_kt<hr>";                     $sql_del="delete pia_spcart user='$user' , id='$id_form[$k]' , p_stt1='addspcart1'";                                      $kq_del=mysql_query($sql_del);                     $sql_order="update pia_spcart set p_orddate='$now',p_qty=$sl_kt+$p_qty[$k] id='$id_form[$k]' , user='$user' , p_stt1='order'";                     $sql_order.=';';                     $kq_dathang=mysql_query($sql_order);                     echo "<script>window.location='index.php?pia=listcart';</script>";                  }             }          }                   //echo "sql: $sql_order";     }  } ?> <table width="560" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #333"> <form method="post" name="form">   <tr>     <td colspan="6" class="tieude" align="center">your cart</td>   </tr>   <tr bgcolor="#ad2200" align="center" height="30" style="font-weight:bold">     <td width="50" style="border-right:1px solid #666"><font color="#ffffff">no</font></td>     <td width="110" style="border-right:1px solid #666"><font color="#ffffff">product</font></td>     <td width="60" style="border-right:1px solid #666"><font color="#ffffff">quantity</font></td>     <td width="95" style="border-right:1px solid #666"><font color="#ffffff">price</font></td>     <td width="95" style="border-right:1px solid #666"><font color="#ffffff">subtotal</font></td>     <td width="50" ><font color="#ffffff">delete</font></td>                   </tr>   <?php        $user=$_session["user"];         $sql="select pia_spcart.*,pia_products.* pia_spcart,pia_products pia_spcart.id=pia_products.id , pia_spcart.user='$user' , pia_spcart.p_stt1='addspcart1'";      $kq=mysql_query($sql);     $i=0;     $tien=0;     if(mysql_num_rows($kq)==0)         echo "<tr><td colspan=6 height=30 align=center>no product in cart!</td></tr>";     else{     while($r=mysql_fetch_array($kq))     {         $id=$r["id"];         $tensp=$r["p_prodname"];         if(isset($_session["p_qty"])) $p_qty=$_session["p_qty"];          else $p_qty=$r["p_qty"];         $price=$r["p_price"]; $price2=number_format($price,0,'','.');         if($price==0) $s="(contact)"; else $s=$price2." sgd";         $total=$price*$p_qty; $total2=number_format($total,0,'','.');         if($total==0) $t="(contact)"; else $t=$total2." sgd";         $totaltien=$totaltien+$total;$totaltien2=number_format($totaltien,0,'','.');                 if($totaltien==0) $tt="(contact)"; else $tt=$totaltien2." sgd";         $i++; ?>                   <tr align="center" height="30" >             <td width="50" style="border-right:1px solid #666; border-bottom:1px solid #666"><?php echo $i; ?></td>             <td width="110" style="border-right:1px solid #666; border-bottom:1px solid #666"><?php echo $tensp; ?></td>             <td width="60" style="border-right:1px solid #666; border-bottom:1px solid #666">             <input type="text" name="p_qty[]" value="<?php echo $p_qty ?>" style="width:30px" />               <input type="hidden" name="id_form[]" value="<?php echo "$id"; ?>"  />              <input type="hidden" name="total[]" value="<?php echo "$total"; ?>" />              </td>             <td align="right" width="95" style="border-right:1px solid #666; border-bottom:1px solid #666; padding-right:3px"><?php echo $s; ?> </td>             <td align="right" width="95" style="border-right:1px solid #666; border-bottom:1px solid #666; padding-right:3px"><?php echo $t; ?> </td>             <td width="50" style=" border-bottom:1px solid #666" >             <input type="checkbox" name="delete[]" value="<?php echo "$id"; ?>"/>             </td>                        </tr>             <?php               }     }     if(mysql_num_rows($kq)==0)         echo "";     else         echo "<tr>   <td height=30 colspan=6 align=right style=\"padding-right:5px; padding-bottom:5px; color:#fff\">subtotal need pay: $tt </td></tr>   <tr>     <td colspan=\"6\" style=\" border-bottom:1px solid #666\" bgcolor=\"#fff\" align=\"center\" height=\"35\">     <input type=\"button\" name=\"continueshopping\" value=\"continue shopping\" class=\"button3\" onmouseover=\"style.background='url(images/button-150-2-o.png)'\" onmouseout=\"style.background='url(images/button-150-o.png)'\" onclick=\"document.form.action='index.php'; document.form.submit();\" />      <input type=\"submit\" name=\"updspc\" value=\"update\" class=\"button\" onmouseover=\"style.background='url(images/button-2-o.gif)'\" onmouseout=\"style.background='url(images/button-o.gif)'\" onclick=\"document.form.submit();\" />      <input type=\"submit\" name=\"delspc\" value=\"delete cart\" class=\"button2\" onmouseover=\"style.background='url(images/button-110-2-o.png)'\" onmouseout=\"style.background='url(images/button-110-o.png)'\" onclick=\"document.form.submit();\" />      <input type=\"submit\" name=\"order\" value=\"order\" class=\"button2\" onmouseover=\"style.background='url(images/button-110-2-o.png)'\" onmouseout=\"style.background='url(images/button-110-o.png)'\" onclick=\"document.form.submit();\"/>     </td>   </tr>";       ?>    <input type="hidden" name="act" />   </form> </table> <div style='font-size:11px; line-height:20px; color:#ff0000; width:560px'></div> 

too hard find error, inserted echo "sql2: $sql2<hr>"; , see following notice on website: sql2: update pia_spcart set p_qty=6 user='' , id='2' , p_stt1='addspcart1';

i recognized problem user db fine.

actually, insert db not change product information or delete it. such "change personal information function" , "shopping cart".

did define "$user"? don't see a:

$user=$_session["user"]; 

it should somewhere before entire script, like:

if (isset($_session["user"])) {     $user=$_session["user"]; } else {     /// something... } 

! , important, don't seem have a:

session_start(); // first line, others... 

at beginning of script. session variables not defined!


Comments