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

Author Topic: Getting 'submit' behavior from a data entry box using HTML  (Read 4582 times)

0 Members and 1 Guest are viewing this topic.

aplusguy

  • Guest
Getting 'submit' behavior from a data entry box using HTML
« on: April 30, 2011, 04:27:46 AM »
   I am in the process of developing an online store, and need to complete it as soon as possible. I have been a computer programmer for years doing business applications, but have been working on development of my website for about the last 2 1/2 months, so I am a beginner at web development, and it is quite different from the programming languages I have experience in in many ways.  I have been writing a book for several years part-time, so I am a first-time author, and will be self publishing.  I need my online store to be working before I have my first printing done since my web site will be the primary way I will market my written book, and other books I am in the process of writing.
   I am using PHP with HTML and MySQL on an Apache server.  The first program is called shop.php, and is working fine.  That program gives a description about my website, and on the bottom is a listing of the books I am selling, and the customer may click on a book title to see details of the book.  The second program is called view_product.php, which enables the customer to see detailed information about the book the customer has clicked on in the previous screen, and is considering ordering.  This program creates a screen which enables the customer to input the quantity of a specific book.  When the customer wants to go to the next screen, the customer simply inputs the quantity to order, and clicks on the 'Add to Cart' button.  That program is also working fine.  The problem occurs in the next program, which is named edit_cart.php, and the quantity box next to the 'Change Quantity' button behaves like a 'submit' button, and prevents the customer from changing the quantity.  The 'Change Quantity' button also behaves like a 'submit' button, and that is as it should be.  I have a good HTML/CSS book, but does not cover a problem of this nature.  I have tried several different approaches to resolve this, but nothing I have tried works.  I'm hoping someone will help me resolve this problem soon.
   The first section of code below is from view_product.php, and works fine.  The second section of code is from edit_cart.php, and is where the problem is.  Let me know if you need more code or information from me.  Thanks.

Excerpt of code from view_product.php:

  <table>
   <tr>
    <td>
     <form action="edit_cart.php" method="post">
      <div>
       <input type="hidden" name="prodcode" value="<?php echo $prodcode; ?>"/>
        <label for="qty"><strong>Quantity: </strong></label>
<?php

   Various PHP commands with no HTML commands

if ($qty != 0) {
    echo '<input type="submit" name="submit" value="Change Qty"/>';
} else {
    echo '<input type="submit" name="submit" value="Add to Cart"/>';
}
echo '<input type="text" name="qty" id="qty" size="5" maxlength="5"
     value="' . $qty . '"/>';
?>

      </div>
     </form>
    </td>
   </tr>
  </table
   

  <p><a href="edit_cart.php">Edit Cart[/url]
   


  <p><a href="shop.php"><< Back to home page[/url]</p>
 </body>
</html>

Excerpt from edit_cart.php:

<html>
 <head>
  <title>Your Shopping Cart</title>
 </head>
 <body>
 

  <h1>Shopping Cart</h1>

<?php
Various PHP commands not containing any HTML commands
 ?>

 <table style="width: 90%;">
  <tr>
   <th><style="width: 100px;"> </th> <th>Item Name </th><th>Quantity</th>
   <th>Price Each</th><th>Extended Price</th>
  </tr>

<?php
    $prodcode = $_POST['prodcode'];
    $qty = $_POST['qty'];
?>

 <table style="width: 90%;">
  <tr>
   <th><style="width: 100px;"> </th> <th>Item Name </th><th>Quantity</th>
   <th>Price Each</th><th>Extended Price</th>
  </tr>
   <tr>
    <td style="text-align:center;"<a href=update_cart.php?prodcode=<?php
     echo $prodcode; ?>"><img src="images/<?php echo $prodcode; ?>_t.png"
     alt="<?php echo $prodname; ?>"/>[/url]</td>
    <td><?php echo $prodname; ?></td>
    <td><a href=update_cart.php?prodcode=<?php echo $prodcode; ?>[/url]
         <form action="update_cart.php" method="post">
      <div>
<!--       <input type="text" name="qty" maxlength="5" size="5"
        value="<?php echo $qty; ?>"/> -->
<?php
   echo '<input type="hidden" name=prodcode" value="' . $prodcode . '"/>';
   echo '<input type="hidden" name="redirect" value=update_cart.php"/>';
   echo '<input type="hidden" name="prodcode" value=' . $prodcode . '"/>';
   echo '<input type="submit" name="submit" value="Change Quantity"/>';
   echo '<input type="text" name="qty" size="5" maxlength="5"
       value="' . $qty . '"/>';
//   echo '<label for="qty">Change Quantity: </label>';
//   echo '<input type="submit" name="submit" value=Change Qty"/>';
?>

      </div>
     </form>
    </td>
    <td style="text-align: right;"> $<?php echo $price; ?></td>
    <td style="text-align: right;"> $<?php echo
        number_format($price * $qty, 2); ?>
    </td>
   </tr>

<?php
  $total = $total + $price * $qty;
?>

     </td>

    etc

 </body>
</html>


Thanks,

aplusguy