Jump to content

updating table values with checkbox


jacko_162

Recommended Posts

Hvaing a little trouble finding a good source code or help with my checkbox in update form.

 

i have a small form with 14x checkboxes.

 

i also have a table with an ID, Member_id, and the 14x fields to match the checkboxes.

 

i want the user to click the needed checkbox's, and upon clicking submit it adds a "1" to the database, and if unticked leaves the default value of "0"

 

i also need to form to load the already ticked and unticked boxes in correlation to the fields current data.

 

can anyone help me please :)

 

many thanks.

Link to comment
https://forums.phpfreaks.com/topic/195241-updating-table-values-with-checkbox/
Share on other sites

<input type="checkbox" name="box" value="X" />

<input type="checkbox" name="box" value="Y" />

<input type="checkbox" name="box" value="Z" />

then loop through box and update the fields

 

 

HTH

Teamatomic

 

how would i loop through and use the UPDATE query?

 

this is my non working code at the moment;

 

<form action="<? $_SERVER['PHP_SELF']; ?>" method="POST">
<?
if (isset($submit)) {
// UPDATE QUERY CODE WHEN SUBMIT IS ENTERED
$insert = "UPDATE members SET
test1view='$checkbox1',
test2view='$checkbox2',
test3view='$checkbox3',
test4view='$checkbox4',
test5view='$checkbox5',
test6view='$checkbox6',
test7view='$checkbox7',
test8view='$checkbox8',
test9view='$checkbox9',
test10view='$checkbox10',
test11view='$checkbox11',
test12view='$telephone12',
test13view='$checkbox13',
test14view='$checkbox14'
WHERE member_id=$_SESSION[sESS_MEMBER_ID]";

if (@mysql_query($insert))
{
echo ('<div class="msg msg-ok"><p>This item was added successfully</p></div>');}
else {
echo ('<div class="msg msg-ok"><p>ERROR</p></div>');}}

{
    $sql = "SELECT * FROM members WHERE member_id=$_SESSION[sESS_MEMBER_ID]";
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);
    $checkbox1 = $myrow["test1view"];
    $checkbox2 = $myrow["test2view"];
    $checkbox3 = $myrow["test3view"];
    $checkbox4 = $myrow["test4view"];
    $checkbox5 = $myrow["test5view"];
$checkbox6 = $myrow["test6view"];
    $checkbox7 = $myrow["test7view"];
    $checkbox8 = $myrow["test8view"];
    $checkbox9 = $myrow["test9view"];
    $checkbox10 = $myrow["test10view"];
    $checkbox11 = $myrow["test11view"];
    $checkbox12 = $myrow["test12view"];
    $checkbox13 = $myrow["test13view"];
    $checkbox14 = $myrow["test14view"];
  }
  ?>
<input type="checkbox" name="box[]" value="box1" />
<input type="checkbox" name="box[]" value="box2" />
<input type="checkbox" name="box[]" value="box3" />
                              <input class="button" type="submit" name="submit" value="Submit" />
				  </form>

ok from the following code;

 

<input type="checkbox" value="box1" name="checks[]" />box 1
<input type="checkbox" value="box2" name="checks[]" />box 2
<input type="checkbox" value="box3" name="checks[]" />box 3

<?php
  print_r($_POST['checks']);
?>

 

i get the array printed on screen.

 

how can i then use this array to perform an update query on my table "members"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.