473,396 Members | 1,676 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,396 software developers and data experts.

update check box

ddtpmyra
333 100+
Hi Guru's
This is a continuation of my last post, but I decided to create a new thread for my new question.

Last post click here:

Problem:
How to update a check box value to mysql records

Code submitting the check box
[PHP]
# Print the top of a table or headers
echo "<table width='100%'><tr>";
echo "<td><b>Deadline Feedback</b></td>";
echo "<td><b>Check to approved</b></td>";
echo "<td><b>Date Created</b></td>";
echo "<td><b>Author</b></td>";
echo "<td><b>Requestor</b></td>";
echo "</tr>";

#Print data
while($row = mysql_fetch_assoc($result))
echo "<tr border=10><td>". $row['DeadLineFeedback']. "</td>";

#Here where I place the checkbox
echo "<td><input type=\"checkbox\" name=\"approved_$id\"></td>";
echo "<td>". $row['Created']. "</td>";
echo "<td>". $row['Author']. "</td>";
echo "<td>". $row['Requestor']. "</td>";
echo "</tr>";
[/PHP]

Code updating the check box
[PHP]

# assigning the checbox rows
$approved = $_POST['approved_$id'];

# This is where I'm having trouble how to tell my php code to pick the checked box

$query = "update fileStorage set approved='Y' where $approved=approved_$id";

# Execute the query
$result = mysql_query($query, $dbLink);

# Check if it was successfull
if($result)
{
echo "Success! Your file was updated!";
}
else
{
echo "Error! Failed to update";
echo "<pre>". mysql_error($dbLink) ."</pre>";
}

[/PHP]

Note:
Approved value = 'Y' or 'N' only
Sep 12 '08 #1
6 7786
Hi ddtpmyra,

There are two steps to this solution:

1. Properly gathering the data

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <form action='checkboxread.php' method='post'>
  3. <input type='checkbox' name='field[]' value='1'   checked ='True'> Field 1<br>
  4. <input type='checkbox' name='field[]' value='2'> Field 2<br>
  5. <input type='checkbox' name='field[]' value='3'> Field 3<br>
  6. <input type='checkbox' name='field[]' value='4'> Field 4<br>
  7. <input type='checkbox' name='field[]' value='5'> Field 5<br>
  8. <input type='checkbox' name='field[]' value='6' checked ='True'> Field 6<br>
  9. <input type='hidden' name='fieldcount' value='6' >
  10. <input type='submit' value='Submit'>
  11. </form>
  12.  
  13. </html>
  14.  
2. Being able to retrieve the checkboxes values

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. echo "<html><head></head><body>";
  4.  
  5. // retrieve number of checkboxes to process
  6. $fieldcount = (int) $_POST['fieldcount'];
  7. echo "Number of checkboxes to process: $fieldcount </br>";
  8.  
  9. // set the array to N by default
  10. for ( $count = 1; $count <= $fieldcount; $count++ ) {
  11.    $field[$count] = "N";
  12. }
  13.  
  14. // retrieve the values that are ON, i.e. TRUE
  15. $checked = $_POST['field'];
  16.  
  17. // update the array with the TRUE
  18. if (sizeof($checked) > 0) {
  19.    foreach($checked as $item) {
  20.        $field[$item] = "Y";
  21.    }
  22. }
  23.  
  24.  
  25. // at this moment you have Y or Ns in your result array
  26. for ( $count = 1; $count <= $fieldcount; $count++ ) {
  27.    echo "field[" .$count . "] = $field[$count] </br>";
  28. }
  29.  
  30. echo "</body></html>";
  31.  
  32. ?>
  33.  

OUTPUT:

Number of checkboxes to process: 6
field[1] = Y
field[2] = N
field[3] = Y
field[4] = Y
field[5] = N
field[6] = N

So you should be able to retrieve specific values and update your table

Let me know how it goes,

Hope it helps,
phpNerd01
Sep 13 '08 #2
ddtpmyra
333 100+
phpNerd01,

I can't have assigned field because I can't tell how many check box should I display I depends on the user how many files they will upload. That's why I have check boxes for each rows. And when they check the box I wanted it to be captured and update the records.

So there's only two options equivalent to my check box, Yes and No.

DM
Sep 15 '08 #3
ddtpmyra
333 100+
anybody can help? I really need to finished this code now :(
Sep 16 '08 #4
pbmods
5,821 Expert 4TB
How are you generating the inputs? Do you have a fixed number, or can the User add additional inputs using Javascript?
Sep 16 '08 #5
ddtpmyra
333 100+
i am not knowledgeable on java.
but the script purpose is to display the each data (row) and im placing a check box to update a column name "approved" inside mysql.

this how it works:
the users will upload a file on the database after which the approving person will check the check box if it's approved or not. and here where I get confuse on how will i capture the row id that the approving person click (check) and for my script to execute the update query.

I hope I explain in very well, let me know if you have questions

thanks!
DM
Sep 17 '08 #6
Atli
5,058 Expert 4TB
i am not knowledgeable on java.
Knowing that Java is not JavaScript would be a good start ;)

But, as to you problem.

All you would have to do to print the boxes would be to fetch them from your database and echo an <input> element for each of them.
Somewhat like:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $result = mysqli_query("SELECT `boxID` FROM `boxTable` WHERE `whatever`");
  3. while($row = mysqli_fetch_assoc($result)) 
  4. {
  5.     echo '<br /><input type="checkbox" name="boxList[]" value="'. $row['boxID'] .'" />'. $row['boxID'];
  6. }
  7. ?>
  8.  
Then, once that is submitted, all the boxes that were checked would be sent as an array named 'boxList' into the $_POST super-global, which you could use to update your database.

You could use the IN clause to update them all at once.
Like:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['boxList'])) 
  3. {
  4.     $inString = implode(", ", $_POST['boxList']);
  5.     $sql = "UPDATE boxTable SET `approved` = TRUE WHERE `boxID` IN($inString)";
  6.  
  7.     // etc...
  8. }
  9. ?>
  10.  
This will obviously have to be adapted to fit you data and you other code, but it's the general idea.
Sep 17 '08 #7

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

Similar topics

4
by: Karaoke Prince | last post by:
Hi There, I have an update statement to update a field of a table (~15,000,000 records). It took me around 3 hours to finish 2 weeks ago. After that no one touched the server and no...
2
by: joo | last post by:
Hi! I need to implement something similar to "Automatic Update" feature which we see in windows 2000. We need this support for our software, basically to provide the software update. How can I...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
2
by: aaj | last post by:
Hi all I have a continuous bound form and on each record is a tick box. The user ticks the boxes and these boxes define the batch. for future operations before they leave the page I count...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
15
by: graham | last post by:
Hi all, <bitching and moaning section> I am asking for any help I can get here... I am at the end of my tether... I don;t consider myself a genius in any way whatsoever, but I do believe I have...
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
5
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
60
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?...
6
by: Suresh | last post by:
Hi All, I am fetching a dataset from the database under some condition. After this I create a data table. Traverse in the original dataset & add each row to created data table as it is through...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.