php-mysql checkboxes
Posted: Thu Nov 25, 2010 11:39 pm
how to work with the checkboxes
I have a mysql table test_equipment
with fields
Equipment_name varchar(100) NOT NULL,
image_url varchar (300),
Description varchar(1000) NOT Null,
my file name is view_test_equipment.php where i dump all the data from the test_equipment in html table.
the code is
<?php
include('db_connect.php');
?>
<form action="selected_test_equipment.php" method="post">
<?php
$result_orders = mysql_query("Select * from test_equipment")or
die ("<font color = red> Query Error </font>".mysql_error);
?>
<br>
<center>Equipments availabe for testing</center>
<br>
<table width=80% border="1" cellspacing="1" cellpadding="1">
<tr>
<td>
<font size="3"><b>Equipment Name</b></font>
<td align = center>
<font size="3"><b>image</b></font>
<td width="" align = center>
<font size="3"><b>Description</b></font>
<td width="" align = center>
<font size="3"><b>Select for Enquiry</b></font>
<?php
while ($row=mysql_fetch_array($result_orders))
{
$image = "../admin/images/Test_Equipment_images/".$row['image_url'];
$img = $image;
echo '<tr align = "left">';
echo '<td>';
echo $row["Equipment_name"];
echo '</td>';
echo '<td width = 60>';
echo "<img src = '$img' width = 60 height = 60>";
echo '</td>';
echo '<td>';
echo $row["Description"];
echo '</td>';
echo '<td>';
echo '<input type="checkbox" name="Equipment_name[]" value= $row["Equipment_name"];>';
echo '</td>';
echo "</tr>";
}
echo '</table>';
echo '<br>';
mysql_free_result($result_orders);
?>
</table>
<center> <input type="submit" name="formSubmit" value="Submit">
my output is like this
-------------------------------------------------------------------------------------------------------------------------
Equipment Name | Image | Description | select for Enquiry |
-------------------------------------------------------------------------------------------------------------------------
abc | some image | asdfasfffas | Checkbox [] (if i select this)
-------------------------------------------------------------------------------------------------------------------------
xyz | some image | 8789798 | Checkbox [] (if i do not select)
-------------------------------------------------------------------------------------------------------------------------
mno | some image | oiop0980 | Checkbox [] (if i select this)
-------------------------------------------------------------------------------------------------------------------------
Submit button
Now I want code in the file name selected_test_equipment.php which should contain the selcted items in the html table
i want the out put like this
You have selected the follwing Equipment for enquiry
-------------------------------------------------------------------------------------------------------------------------
Equipment Name | Image | Description
-------------------------------------------------------------------------------------------------------------------------
abc | some image | asdfasfffas
-------------------------------------------------------------------------------------------------------------------------
mno | some image | oiop0980
-------------------------------------------------------------------------------------------------------------------------
Woule you like to add more equipment then goback or process the enquiry
Please help, i am new to php
I have a mysql table test_equipment
with fields
Equipment_name varchar(100) NOT NULL,
image_url varchar (300),
Description varchar(1000) NOT Null,
my file name is view_test_equipment.php where i dump all the data from the test_equipment in html table.
the code is
<?php
include('db_connect.php');
?>
<form action="selected_test_equipment.php" method="post">
<?php
$result_orders = mysql_query("Select * from test_equipment")or
die ("<font color = red> Query Error </font>".mysql_error);
?>
<br>
<center>Equipments availabe for testing</center>
<br>
<table width=80% border="1" cellspacing="1" cellpadding="1">
<tr>
<td>
<font size="3"><b>Equipment Name</b></font>
<td align = center>
<font size="3"><b>image</b></font>
<td width="" align = center>
<font size="3"><b>Description</b></font>
<td width="" align = center>
<font size="3"><b>Select for Enquiry</b></font>
<?php
while ($row=mysql_fetch_array($result_orders))
{
$image = "../admin/images/Test_Equipment_images/".$row['image_url'];
$img = $image;
echo '<tr align = "left">';
echo '<td>';
echo $row["Equipment_name"];
echo '</td>';
echo '<td width = 60>';
echo "<img src = '$img' width = 60 height = 60>";
echo '</td>';
echo '<td>';
echo $row["Description"];
echo '</td>';
echo '<td>';
echo '<input type="checkbox" name="Equipment_name[]" value= $row["Equipment_name"];>';
echo '</td>';
echo "</tr>";
}
echo '</table>';
echo '<br>';
mysql_free_result($result_orders);
?>
</table>
<center> <input type="submit" name="formSubmit" value="Submit">
my output is like this
-------------------------------------------------------------------------------------------------------------------------
Equipment Name | Image | Description | select for Enquiry |
-------------------------------------------------------------------------------------------------------------------------
abc | some image | asdfasfffas | Checkbox [] (if i select this)
-------------------------------------------------------------------------------------------------------------------------
xyz | some image | 8789798 | Checkbox [] (if i do not select)
-------------------------------------------------------------------------------------------------------------------------
mno | some image | oiop0980 | Checkbox [] (if i select this)
-------------------------------------------------------------------------------------------------------------------------
Submit button
Now I want code in the file name selected_test_equipment.php which should contain the selcted items in the html table
i want the out put like this
You have selected the follwing Equipment for enquiry
-------------------------------------------------------------------------------------------------------------------------
Equipment Name | Image | Description
-------------------------------------------------------------------------------------------------------------------------
abc | some image | asdfasfffas
-------------------------------------------------------------------------------------------------------------------------
mno | some image | oiop0980
-------------------------------------------------------------------------------------------------------------------------
Woule you like to add more equipment then goback or process the enquiry
Please help, i am new to php