472,348 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 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 7725
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...
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,...
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...
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...
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) ...
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...
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,...
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 ...
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...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.