Re: Using PHP to get user input via checkbox through a data base

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you Jim...this is helpful.  I will try this when I get home.

Wil
----- Original Message ----- From: "Jim Moseby" <JMoseby@xxxxxxxxxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Tuesday, July 26, 2005 4:03 PM
Subject: RE: Using PHP to get user input via checkbox through a data base



Hello everyone,

What I want to do is have a form (which is already created)
where the user selects (via checkbox) on an item or group of
items (almost like a shopping cart).  These items are stored
in a MySql database and the program was written in PHP.  So
far I have created an insert form that inserts the products
into a database.  The database is displayed in a form where
the user now needs to click on the select box so that he/she
can choose their items.  Once they have chosen the items a
confirmation page is supposed to come out with the user's
choices and the user will confirm that this is correct or not
and either click submit or go back to choose again.  If they
click submit than I am supposed to receive an email with all
of the user's choices.  The part I am still stuck in is when
the user attempts to choose, nothing really happens.
Following is the code that displays the database and allows
the user to choose via the check box....Any help would be
appreciated.

<?php require_once('Connections/connBlog.php'); ?>
<?php
mysql_select_db($database_connBlog, $connBlog);
$query_Recordset1 = "SELECT * FROM ebay_products";
$Recordset1 = mysql_query($query_Recordset1, $connBlog) or
die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php require_once('Connections/connBlog.php'); ?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<div align="center">
  <p>&nbsp;</p>
  <form action="" method="post" name="form1">
    <table width="75%" height="10%" border="10"
align="center" cellpadding="0" cellspacing="0" bordercolor="#99FFCC">
      <tr>
        <td><div align="center">Description of Product</div></td>
        <td><div align="center">Coupon Amount</div></td>
        <td><div align="center">Expiration Date</div></td>
        <td><div align="center">Your Selection</div></td>
      </tr>
      <?php do { ?>
      <tr>
        <td width="65%">
          <div align="center"><?php echo
$row_Recordset1['product']; ?></div></td>
        <td width="8%">
          <div align="center">$<?php echo
$row_Recordset1['discount']; ?></div></td>
        <td width="15%">
          <div align="center"><?php echo
$row_Recordset1['expire']; ?></div></td>
        <td width="2%">
          <div align="center">
            <input name="select" type="checkbox" id="select"
value="checkbox">
          </div></td>
      </tr>
      <?php } while ($row_Recordset1 =
mysql_fetch_assoc($Recordset1)); ?>
    </table>
    <table width="25%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>
<div align="center">
            <input type="submit" name="Submit" value="Submit">
          </div></td>
        <td>
<div align="center">
            <input name="back" type="button" id="back"
value="Go Back">
          </div></td>
      </tr>
    </table>
    <p>&nbsp;</p>
  </form>
  <p>&nbsp;</p>
</div>
<p align="center"> <a href="ebayinsert.php">Insert Data</a></p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>


Problems I see right off the bat are:
 1)  your form tag has no action (action=""), therefore no action will be
taken upon submit.
 2)  your checkboxes have no unique value, so even if your form WAS being
submitted to some other page, you wouldn't be able to tell which ones were
checked.

To solve these problems, set your form action to the page that is to process
the POST, then change this line:

            <input name="select" type="checkbox" id="select"
value="checkbox">

...to be something like

            <input name="select" type="checkbox" id="select"
value="<?php echo $row_Recordset1['product'];?>">

JM

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux