hi

im working with two form
the first form is to insert cheek box into db
so the first code i write like this :

mysql_select_db("project", $con);
if(count($orders)>0)
{
foreach($orders as $key=>$order)
{
$query="INSERT INTO orders (ORDER_DESC) VALUES ('".$order."' )";
mysql_query($query) or die ('Error Updating the Database' . mysql_errno());
}
echo "Order Successfully Placed";
}
else
echo "No Orders";

and the second form is to update to same record for cheek box :

$ud_id = $_POST['ORDERING_DEPT'];
mysql_select_db("project", $con);

$query="UPDATE orders SET ORDERING_DEPT='$ud_id' WHERE ORDER_DESC='$orders'";

echo "Record Updated";

and after do this only shown in the first from is insert but the another form not work so anyhelp?

Recommended Answers

All 6 Replies

so the form html is like :

<table class="table">
<form action="cheekbox.php" method="post">
<tr>


<th class="th">ORDER_DESC </th>

</tr>
<tr>
<td class="td"><input type="checkbox" name="checkbox[]" value="CSF"/> CSF </td>
</tr>

<tr>
<td class="td"><input type="checkbox" name="checkbox[]" value="LFT"/> LFT </td>
</tr>

<tr>
<td class="td"><input type="checkbox" name="checkbox[]" value="RFR"/> RFR </td>
</tr>



<tr>
<td class="td" ><input type="submit" value="submit" name="Submit"/>
</td>
</tr>
</form>

I'd recommend you read up on PRIMARY KEYS for databases and see how they are used. It is rare and very inconvenient to do updates based on strings like that. What if two orders contain the same set of checks? You will update MULTIPLE orders.

Also, where is the value of $orders being set in each of the form handlers?

$ud_id = $_POST

Where is 'ORDERING_DEPT' ? That's not found in your form. Ensure that your form has required fields.

Are you retrieving your check boxes name?

the problem is for the order no is hidden
i make this but give me error

<table class="table">
<form action="cheekbox.php" method="post">
<tr>


<th class="th">ORDER_DESC </th>
<td class="td"><input type="hidden" name="order_no" value="order_no"/>  </td>
</tr>
<tr>
<td class="td"><input type="checkbox" name="checkbox[]" value="CSF"/> CSF </td>
</tr>

<tr>
<td class="td"><input type="checkbox" name="checkbox[]" value="LFT"/> LFT </td>
</tr>

<tr>
<td class="td"><input type="checkbox" name="checkbox[]" value="RFR"/> RFR </td>
</tr>



<tr>
<td class="td" ><input type="submit" value="submit" name="Submit"/>
</td>
</tr>
</form>
</table>

and for insert like this :

$orders = $_POST['checkbox'];
$order_no = $_POST['order_no'];

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("project", $con);
if(count($orders)>0)
{
foreach($orders as $key=>$order)
{
$query="INSERT INTO orders (order_no,ORDER_DESC) VALUES ('".$order_no.",'".$order."' )";
mysql_query($query) or die ('Error Updating the Database' . mysql_errno());
}
echo "Order Successfully Placed";
}
else
echo "No Orders";

On line 7 of the form, order_no is initialized to the string "order_no". Assuming order comes from a previous form and is mapped to a variable, try "$order_no" instead.

In your form handler above, make sure you received a number for the order number (hidden fields can be hacked, etc.)

$order_no = intval($_POST['order_no']);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.