Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: PHP MySQL code for deleting items in cart doesnt work0  (Read 8455 times)

0 Members and 1 Guest are viewing this topic.

abha aggarwal

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    PHP MySQL code for deleting items in cart doesnt work0
    « on: April 30, 2013, 06:12:44 PM »
    i am making php mysql code for admin side  to delete items from shopping cart.Please find the error in the code , cause i cant find it.

    Delete product is the place where i show the items  selected by productid as options for admin to choose to delete.
    Delete product  works ,whose screen short can as well be shown in the document  file.Delete product then submits the chosen selected item to delete product1.

    Delete product 1 is where i am trying to delete the option as  chosen by admin via delete product.I tried my best to remove error in the delete product 1 but couldn't solve it , i will be grateful if you did.Please remove the errors in delete product document file.

    1)Delete product code working showing form to choose option for deletion as shown in the image
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Delete Product Details</title>
        <link href="design.css" rel="stylesheet" type="text/css" />
        <script language="javascript" type="text/javascript">
        function clearText(field)
        {
            if (field.defaultValue == field.value) field.value = '';
            else if (field.value == '') field.value = field.defaultValue;
        }
        </script>
    </head>
    <body>

    <div id="wrapper">

        <div id="header">
       
           <?php
             include 'header.php';      
          ?>
               
           
            </div> <!-- end of left_sidebar -->
           
            <div id="content">
           
             <div class="box">
                   <h2>Delete Product Details</h2>
                   
                    <div class="body">
                       
                        <?php
                      if(isset($_SESSION['uname']))
                      {
                         include 'dbconnect.php'; 
                         echo "<div id=welcome>Welcome ".$_SESSION['uname'].",</div>";
                   ?>
                            <?php
                           if($_SESSION['utype']=='A'  )
                         {
                            ?>
                             <form action="deleteproduct1.php" method="post" >
                             
                                <table cellspacing="20" align="center">
                                    <tr><td>Product Name</td><td><select id="txtPName" name="txtPName">
                                      <?php
                                        include 'dbconnect.php';
                                       
                                        $sql="select * from product";
                                        $res = $dbconn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
                                     $res->execute();
                               $disp="";
                                  while(   $rs = $res->fetch())
                                  {
                                     $disp.="<option value=".$rs['idProduct'].">".$rs['name']."</option>";
                                  }
                                  echo $disp;
                                           ?>
                                        </select></td></tr>
                                  
                                  
                                  <tr><td>&nbsp;</td><td><input type="submit" value="Delete" /></td></tr>
                               </table>
                               </form>
                  <?php
                   }
                   else
                         header('location: adminlogin.php');
                   }
                      else
                         header('location: adminlogin.php');
                     ?>      
                           
                     </div>
               
                   <div class="box_bottom"><span></span></div>
                </div>
            </div> <!-- end of content -->
           
         
          <?php               
             include 'footer.php';
           ?>
       
       </div> <!-- end of footer_wrapper -->
    </body>
    </html>





    2) Delete product 1 doesn’t work as there is some error in the code. Please remove the errors please. Here is the not working code of delete product 1. :
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Delete Product Details</title>
        <link href="design.css" rel="stylesheet" type="text/css" />
        <script language="javascript" type="text/javascript">
        function clearText(field)
        {
            if (field.defaultValue == field.value) field.value = '';
            else if (field.value == '') field.value = field.defaultValue;
        }
        </script>
        <script src="script/script.js" type="text/javascript"></script>
    </head>
    <body>

    <div id="wrapper">

        <div id="header">
       
           <?php
             include 'header.php';      
          ?>
               
           
            </div> <!-- end of left_sidebar -->
           
            <div id="content">
           
             <div class="box">
                   <h2>Delete Product Details</h2>
                   
                    <div class="body">
                       
                       <?php
                      if(isset($_SESSION['uname']))
                      {
                         include 'dbconnect.php'; 
                         echo "<div id=welcome>Welcome ".$_SESSION['uname'].",</div>";
                   ?>
                            <?php
                           if($_SESSION['utype']=='A'  )
                         {
                            ?>
                           
                             <?php
                           if(isset($_POST['txtPName']))
                         {
                          
                            include 'dbconnect.php';                     
                            $txtPName=$_POST['txtPName'];
                            try
                            {
                               $sql="delete from product where idProduct=:idProduct";
                               $q = $dbconn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
                               $q->execute(array(':idProduct'=>$txtPName));
                               echo "

    <p> Product ID : $txtPName one quantity deleted";   
                                                                   
             
                         
                            }
                            catch(PDOException $e)
                            {
                               echo  $e->getMessage();
                            }
                         }
                         else
                            header('location:deleteproduct.php');
                         }
                         else
                               header('location: adminlogin.php');
                         }
                      else
                         header('location: adminlogin.php');
                     ?>      
                         
                           
                     </div>
               
                   <div class="box_bottom"><span></span></div>
                </div>
            </div> <!-- end of content -->
           
         
          <?php               
             include 'footer.php';
           ?>
       
       </div> <!-- end of footer_wrapper -->
    </body>
    </html>


    [recovering disk space, attachment deleted by admin]