473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

I want the values of the check box checked alogn with other information

how to work with the checkboxes

I have a mysql table test_equipment
with fields
Expand|Select|Wrap|Line Numbers
  1. Equipment_name varchar(100) NOT NULL,
  2. image_url varchar (300),
  3. 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
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include('db_connect.php');
  3. ?>
  4. <form action="selected_test_equipment.php" method="post">
  5. <?php
  6. $result_orders = mysql_query("Select * from test_equipment")or 
  7. die ("<font color = red> Query Error </font>".mysql_error);
  8. ?>
  9. <br>
  10. <center>Equipments availabe for testing</center>
  11. <br>
  12.   <table width=80% border="1" cellspacing="1" cellpadding="1">
  13.           <tr>
  14.                  <td>   
  15.       <font size="3"><b>Equipment Name</b></font>
  16.       <td align = center>
  17.                    <font size="3"><b>image</b></font>
  18.                    <td width="" align = center>
  19.                   <font size="3"><b>Description</b></font>
  20.                    <td width="" align = center>
  21.                   <font size="3"><b>Select for Enquiry</b></font>
  22.  
  23. <?php
  24. while ($row=mysql_fetch_array($result_orders)) 
  25. {
  26. $image = "../admin/images/Test_Equipment_images/".$row['image_url'];
  27. $img = $image;
  28.  
  29. echo '<tr align = "left">';
  30.       echo '<td>';
  31.         echo $row["Equipment_name"];
  32.       echo '</td>';
  33.       echo '<td width = 60>';
  34.          echo "<img src = '$img' width = 60 height = 60>";
  35.       echo '</td>';
  36.       echo '<td>';
  37.         echo $row["Description"];
  38.       echo '</td>';
  39.       echo '<td>';
  40.         echo '<input type="checkbox" name="Equipment_name[]" value= $row["Equipment_name"];>';
  41.       echo '</td>';
  42.      echo "</tr>";
  43. }
  44.   echo '</table>';
  45.   echo '<br>';
  46. mysql_free_result($result_orders);
  47. ?>
  48.   </table> 
  49. <center> <input type="submit" name="formSubmit" value="Submit">
my output is like this

Expand|Select|Wrap|Line Numbers
  1. ------------------------------------------------------
  2. Equipment Name|Image|Description |select for Enquiry | 
  3. ------------------------------------------------------
  4. abc           |img1 |asdfasfffas |Checkbox[](i select this)
  5. ---------------------------------------------------------
  6. xyz          |img2 |8789798     |Checkbox[](idonotselect)
  7. -----------------------------------------------------------
  8. mno           |image|oiop0980    |Checkbox[](i select this)
  9. ----------------------------------------------------------
  10.  
  11.                      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

Expand|Select|Wrap|Line Numbers
  1. You have selected the follwing Equipment for enquiry
  2. ------------------------------------------------------
  3. Equipment Name|Image|Description |select for Enquiry | 
  4. ------------------------------------------------------
  5. abc           |img1 |asdfasfffas |Checkbox[](i select this)
  6. ---------------------------------------------------------
  7. mno           |image|oiop0980    |Checkbox[](i select this)
  8. ----------------------------------------------------------
  9.  
  10. Woule you like to add more equipment then goback or process the enquiry
Please help, i am new to php
Nov 26 '10 #1
1 986
dlite922
1,584 Expert 1GB
Welcome back saiabhi,

What you need to do to redisplay the selected equipment in the selected_test_equipment page is to grap the names from POST variable $_POST['Equipment_name'] (Which is the name of your checkbox array in your form.

Loop through that array and query the database for each of them using the WHERE clause to find the image URL and description again.

With that out of the way, here's a few suggestions to improve your code (and the code you're about to write for selected_test_equipment.php)

1. SECURITY THREAT: Make sure you run every post variable through mysql_real_escape_string() function to prevent SQL injection attacks. Don't put your variable directly into the WHERE clause.

2. I know your new to PHP, but it's best to keep your logic (php code) away from your HTML (presentation). Look up MVC in your favorite search engine and try to adopt it as early on as possible.

3. Code with HTML 4 and CSS 2. Don't use <font> tags anymore. Keep structure (html tags) away from formatting and styling (alignments, colors, fonts,etc in other words use CSS)

4. Next time you post here please use CODE tags. It's the pound sign you see when you write your message here on bytes. It makes it easier for us to read your code.


Good luck,


Dan
Nov 26 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Paris_Sucks | last post by:
I'm trying to redirect when testing for certain condidtions as shown below. When the conditions are ture, it redirects, but still goes ahead and processes the sql query. What am I doing wrong??? ...
2
by: Danny Stolle | last post by:
Hi all, i can't figure this one out. from a main window i am opening another window with a form in it. this form has an inputbox. from the main window i want to write a value into this inputbox....
7
by: sumi | last post by:
Hi, from my login i want to login as a other user , how can i do it using python.
1
by: jm001 | last post by:
Hi, I am creating a database that will hold contact information plus additional information on different tables. ID on contact will auto assign. I want to have the system prompt for ID and...
1
by: Thief_ | last post by:
I'd like to check if a textbox contains text & symbols. Sometimes it will have just carriage returns and/or spaces, and lots of them, and I want to check if this is the case so that I can clear the...
6
by: JPG4 | last post by:
Hello, I am creating a form in Access that uses the days of the week (I am looking at flight patterns for an airline). I have created a check box for each day; therefore I have 7 total. The...
0
by: PankajMhatre | last post by:
want to check the "mms" url format validation in ASP.NET C# i.e mms://10.3.19.129/DRMTest/ & not like any other format
1
by: ttamilvanan81 | last post by:
Hai i have using the checkbox in for loop. I need the urgent help from anyone, for example in the loop there is having 5 checkbox if i checked 3 of the ckeckboxes and 2 of the checkboxes are...
2
rsmccli
by: rsmccli | last post by:
Access 2002 Hi, I have a number of comboboxes/textboxes in the header of a form that the user selects values from. These comboboxes/textboxes correspond to controls in a datasheet view subform....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.