PHP - Checkbox
hallo everybody,
i have column in my guestbook table mysql database names vis.
i want make it possible for user to make theier comments invisible.
if user checked yes, the comment will be viewd. if he did not checked, the comment will not be viewed.
in my visibility.php the user can later change the value from yes to no or from no to yes.
i do not know how to make this possible in update.php file.
thank you very much for your help.
Rafal
here is my code which not work in visibility.php
<form action="update.php" method="post"> <input type="hidden" name="inp_id" value="<?php echo $row[id) ?>"> visible: <input type="checkbox" name="inp_vis" <?php if ($row[vis] == "yes") { echo "value='yes' checked"; } else { echo "value='no'"; } ?>> <br> <input type="submit" value="Save"> </form> Edited by rafal, 25 September 2014 - 08:54 AM. Similar TutorialsHi, This is part of my table code echo "<td align=\"center\"><font color=\"{$colors[$row['presenter1status']]}\">{$row['presenter1']}</font> <input type='checkbox' /></td>"; Now what I was hoping to do is write some code to check what is selected and what isnt to be then able to write some queries to the database. Can anyone give any pointers Thanks Here is the 'want' right now: I have a database with a table for customers and another one for projects. I want the user to have the ability to select which customer they want to be associated with their project. I understand how to do this logically (set up of the tables relationships) but I cant seem to figure out how to do this via checkbox arrays. For example, there should be a list of checkboxes with the values being pulled from the customer database. Whichever customers are selected, their IDs should get placed into a row in the project table called cust id. So the project table would read like the following: ID: 1 Project ID: 3-002-055 Customer ID: Whatever the ID number is in the customers table (I have customer IDs being pulled from the URL) ID: 2 Project ID: 3-002-055 (same as above) Customer ID: Whatever the ID number is So in this case, both customers are working on the same project. With that being said, I know for a fact that this is possible via some kind of checkbox statement. Something that pretty much says the following (I already started my lame attempt at coding this....I am no expert to bare with me!): Code: [Select] <?php $staff_id = $_SESSION['sid']; $company_id = $_GET['cid']; $company_id = mysql_real_escape_string($company_id ); $company_id = eregi_replace("`", "", $company_id); $sql = mysql_query("SELECT contact_fname, contact_lname FROM contact_info WHERE company_id='$company_id'"); while($row = mysql_fetch_array($sql)){ $contact_fname = $row["contact_fname"]; $contact_lname = $row["contact_lname"]; $select_contacts .= " <input name=\"contacts[]\" type=\"checkbox\" value=\"' . $contact_fname . ' ' . $contact_lname . '\" /><br /><br /> <input name=\"submit_contacts\" type=\"submit\"> "; } ?> This is where I am lost at. How do I say that whenever anything is checked, grab the value and store it into the database but in a separate record??? Bl4ck Maj1k okay so i have like 7 checkboxes and it all works fine but when i check "other" it gives me a value of "ON" when i check all 6 previous boxes it gives me the correct value. i am not sure why this happens function get_checked($variable, $status){ if($variable == $status){ return 'checked="checked"'; }else{ return ''; } } <input type=\"checkbox\" name=\"emailNewsletter\" value=\"Yes\" ".get_checked($emailNewsletter, 'Yes')."> <input type=\"checkbox\" name=\"emailInbox\" value=\"Yes\" ".get_checked($emailInbox, 'Yes')."> $emailNewsletter = isset($_POST['emailNewsletter']) ? filter_input(INPUT_POST, 'emailNewsletter') : 'No'; $emailInbox = isset($_POST['emailInbox']) ? filter_input(INPUT_POST, 'emailInbox') : 'No';If no submit button clicked display mysql information $userInfo['emailInbox'] instead of 'NO' . How to do that? :confused:Hi I have a problem with check box in jquery directory tree... I can't get value from it !!! :S The value of $file show's as "array" in the echo"$files"; not as the real value of the file that is show'n in the directory tree. Can someone help mee with this ? <input type='checkbox' name='del[]' id='del' value='$file'/><a href=\"".$path.$file."\"><img src='slike_izgled/file.png'> $file</a> if(isset($_POST['filedel'])) { $id = $_POST[del]; $count = count($id); for ($i=0; $i<$count; $i++){ $files = $_POST['del']; echo"$files.$count"; } I'm having a problem on how to get the values of those that are checked in my table.. so that i can insert them in my database. Someone help get those values pls. Heres my code Code: [Select] <?php $host="localhost"; $username="root"; $password=""; $db_name="dbprof"; $tbl_name="teacher"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); echo '<form name="formupload" method="post" action="val3.php">'; echo "<table border=\"5\" >"; echo "<tr><th>List of Instructor</th>"; if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { echo "<tr><td>"; echo "<input type='checkbox' name='list' 'value='" .$row['fullname']. "'> " .$row['fullname']. "<br/></td>"; echo "</tr>"; } } else { echo "<tr><td>No one to Approve</td></tr>"; } echo '<input type="image" src="images/reject.png" name="test" width="170" height="35" border="0" value="reject">'; echo '</form>'; ?> I dont know what to put in my val3.php' so that it can the values of the Checked data. thanks for those who can help. hello, i have table that store p_id , p_name , p_visible. in my form code i put this : $sql = "select * from pages"; $rslt = connect($sql); print "<form name='links' method='GET' action='checks/check_links.php'>"; while ($links = mysql_fetch_array($rslt)) { print "<input type='checkbox' name='pagename' value='1'>$links[p_name]<br>"; } print "<input type='submit' value='update'></form>"; my question is.... how to pass the query string that hold: 1. if checkbox checked, then pass value 1 to my sql query 2. i have to define witch value has need to go to the right p_name please help. Hi All, I'm very new to PHP so please bear with me. I have created a form with 3 fields. One field is a multi select / checkbox with the name 'tenCode'. How do I get all of the values selected from this box and add them to my database? My submission code (submit.php) Code: [Select] <?php $con = mysql_connect("localhost","dbname","dbpassword"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbname", $con); $sql="INSERT INTO tablename (tenFirst,tenPhone,tenID) VALUES ('$_POST[tenFirst]','$_POST[tenPhone]','$_POST[tenID]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Adding Ten. The page will refresh in 5 seconds."; echo "<meta http-equiv='Refresh' content='5; URL=nextpage.php'/>"; mysql_close($con) ?> Thanks dvent Hi.. I have form for leave and now I need to add checkbox for halfday. if checkbox is checked the HOURS_LEAVE = HOURS_LEAVE * 4 because his leave is halfday only. then if checkbox is not check the HOURS_LEAVE = HOURS_LEAVE * 8 . and also if checkbox is check the value is H else W then it also save to database here is my code for LeaveEmp.php <?php include 'config.php'; date_default_timezone_set('Asia/Singapore'); session_start(); $currentEmpID = $_SESSION['empID']; $EMP_NO = $_GET['EMP_NO']; $NAME = $_GET['NAME']; $DATE_LEAVE_FROM = $_GET['DATE_LEAVE_FROM']; $DATE_LEAVE_TO = $_GET['DATE_LEAVE_TO']; $HOURS_LEAVE = $_GET['HOURS_LEAVE']; $Approve = $_GET['Approve']; $TYPE =$_GET['TYPE']; $dateprocess = $_GET['dateprocess']; $DATE_LEAVE = $_GET['DATE_LEAVE']; $EMPNO = $_GET['EMPNO']; function GetDays($StartDate, $EndDate){ $StartDate = date("Y-m-d", strtotime($StartDate)); $EndDate = date("Y-m-d", strtotime($EndDate)); $Days[] = $StartDate; $CurrentDate = $StartDate; while($CurrentDate < $EndDate){ $CurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($CurrentDate))); if(date("w",strtotime($CurrentDate))>0){ $Days[] = $CurrentDate; } } return count($Days); } $HOURS_LEAVE = GetDays($DATE_LEAVE_FROM, $DATE_LEAVE_TO); $smarty->assign('LeaveStatus', array(SickLeave=>'Sick Leave',VacationLeave=>'Vacation Leave',BirthdayLeave=>'Birthday Leave',MaternityLeave=>'Maternity Leave', PaternityLeave=>'Paternity Leave', UnionLeave=>'Union Leave', Holiday=>'Holiday')); $smarty->assign('TYPE', $TYPE); $sql = "SELECT l.EMP_NO, l.DATE_LEAVE_FROM, l.DATE_LEAVE_TO, l.HOURS_LEAVE, l.TYPE_LEAVE, l.STATUS_LEAVE FROM $ADODB_DB.employment em, $PAYROLL.leave_data l WHERE em.EMP_NO = l.EMP_NO AND em.EMP_ID = '$currentEmpID' AND l.DATE_LEAVE_FROM = '$DATE_LEAVE_FROM'"; $result_edit = $conn2->Execute($sql); $DATE_LEAVE_FROM = $result_edit->fields['DATE_LEAVE_FROM']; $DATE_LEAVE_TO = $result_edit->fields['DATE_LEAVE_TO']; $smarty->assign('DATE_LEAVE_FROM', $DATE_LEAVE_FROM); $smarty->assign('DATE_LEAVE_TO', $DATE_LEAVE_TO); $sql = "SELECT l.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME, l.DATE_LEAVE_FROM, l.DATE_LEAVE_TO, l.HOURS_LEAVE, l.TYPE_LEAVE, l.STATUS_LEAVE FROM $ADODB_DB.PERSONAL p, $ADODB_DB.employment em, $PAYROLL.leave_data l WHERE em.EMP_NO = l.EMP_NO AND p.EMP_ID = em.EMP_ID ORDER BY FULLNAME"; $rs = $conn2->GetAll($sql); $smarty->assign('getleave', $rs); $smarty->display('header_att.tpl'); $smarty->display('LeaveForm.tpl'); $smarty->display('footer.tpl'); ?> here is my code for saving leave: <?php include 'config.php'; date_default_timezone_set('Asia/Singapore'); $currentEmpID = $_SESSION["empID"]; $EMP_NO = $_GET['EMP_NO']; $NAME = $_GET['NAME']; $DATE_LEAVE_FROM = $_GET['DATE_LEAVE_FROM']; $DATE_LEAVE_TO = $_GET['DATE_LEAVE_TO']; $HOURS_LEAVE = $_GET['HOURS_LEAVE']; $TYPE =$_GET['TYPE']; $Approve = $_GET['Approve']; $dateprocess = $_GET['dateprocess']; $today = date("Y-m-d"); function GetDays($StartDate, $EndDate){ $StartDate = date("Y-m-d", strtotime($StartDate)); $EndDate = date("Y-m-d", strtotime($EndDate)); $Days[] = $StartDate; $CurrentDate = $StartDate; while($CurrentDate < $EndDate){ $CurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($CurrentDate))); if(date("w",strtotime($CurrentDate))>0){ $Days[] = $CurrentDate; } } return count($Days); } $HOURS_LEAVE = GetDays($DATE_LEAVE_FROM, $DATE_LEAVE_TO); $HOURS_LEAVE = $HOURS_LEAVE * 8; $smarty->assign('LeaveStatus', array(SickLeave=>'Sick Leave',VacationLeave=>'Vacation Leave',BirthdayLeave=>'Birthday Leave',MaternityLeave=>'Maternity Leave', PaternityLeave=>'Paternity Leave', UnionLeave=>'Union Leave', Holiday=>'Holiday')); $smarty->assign('TYPE', $TYPE); $smarty->assign('DATE_LEAVE_FROM', $DATE_LEAVE_FROM); $smarty->assign('DATE_LEAVE_TO', $DATE_LEAVE_TO); $smarty->assign('EMP_NO', $EMP_NO); $smarty->assign('NAME', $NAME); $smarty->assign('HOURS_LEAVE', $HOURS_LEAVE); $smarty->assign('TYPE', $TYPE); $smarty->assign('dateprocess', $today); $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_data WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeave = $conn2->Execute($sql); $numrowsRsLeave = $RsLeave->RecordCount(); if($numrowsRsLeave > 0){ echo "<script>alert('Transaction has already been process')</script>"; echo "<script>navigate('LeaveEmp.php')</script>"; } else { $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_data WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeave = $conn2->Execute($sql); $saverec['EMP_NO'] = $EMP_NO; $saverec['DATE_LEAVE_FROM'] = $DATE_LEAVE_FROM; $saverec['DATE_LEAVE_TO'] = $DATE_LEAVE_TO; $saverec['HOURS_LEAVE'] = $HOURS_LEAVE; $saverec['TYPE_LEAVE'] = $TYPE; $saverec['STATUS_LEAVE'] = $Approve; $saverec['DATE_PROCESS'] = $today; $insertSQL = $conn2->GetInsertSQL($RsLeave, $saverec); $conn2->Execute($insertSQL); } $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_log WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeaveLog = $conn2->Execute($sql); $numrowsRsLeave = $RsLeaveLog->RecordCount(); if($numrowsRsLeave > 0){ echo "<script>alert('Transaction has already been process')</script>"; echo "<script>navigate('LeaveEmp.php')</script>"; } else{ $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_log WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeaveLog = $conn2->Execute($sql); $saverec['EMP_NO'] = $EMP_NO; $saverec['DATE_LEAVE_FROM'] = $DATE_LEAVE_FROM; $saverec['DATE_LEAVE_TO'] = $DATE_LEAVE_TO; $saverec['HOURS_LEAVE'] = $HOURS_LEAVE; $saverec['TYPE_LEAVE'] = $TYPE; $saverec['STATUS_LEAVE'] = $Approve; $saverec['DATE_PROCESS'] = $today; $insertSQL = $conn2->GetInsertSQL($RsLeaveLog, $saverec); $conn2->Execute($insertSQL); } session_write_close(); header("Location:LeaveEmp.php"); exit(); ?> And here is the LeaveForm.tpl <script> window.onload = function() { var ul = document.getElementById('searchpayroll'); var links = ul.getElementsByTagName('a'); var i = 0; document.onkeyup = function(e){ e = window.event || e; var key = e.charCode || e.keyCode; if (key == 40) { if (i < links.length - 1) i++; links[i].focus(); } else if (key == 38) { if (i > 0) i--; links[i].focus(); } } } function ApproveLeaveOP(){ var EMP_NO = document.getElementById('EMP_NO').value; var DATE_LEAVE_FROM = document.getElementById('DATE_LEAVE_FROM').value; var DATE_LEAVE_TO = document.getElementById('DATE_LEAVE_TO').value; var NAME = document.getElementById('NAME').value; var HOURS_LEAVE = document.getElementById('HOURS_LEAVE').value; var Approve = document.getElementById('Approve').value; var TYPE = document.getElementById('TYPE').value; var dateprocess = document.getElementById('dateprocess').value; var H = document.getElementById('H').value; document.sampleform.action="AddLeave.php?EMP_NO="+EMP_NO+"&DATE_LEAVE_FROM="+DATE_LEAVE_FROM+"&DATE_LEAVE_TO="+DATE_LEAVE_TO+"&NAME="+NAME+"&HOURS_LEAVE="+HOURS_LEAVE+"&Approve="+Approve+"&TYPE="+TYPE+"&dateprocess="+dateprocess+"&H="+H; document.sampleform.submit(); } </script> <script type="text/javascript" src="op_from_date_leave.js"> </script> <script type="text/javascript" src="op_from_date_leave_conf2.js"></script> <div id="Search"> <form> <p class="serif"><b>Search Lastname:</b></p> <input type="text" name="search_" size="20" onkeyup="searchEmpLeaveOP(this.value);"> <div> <hr /> <ul id="searchpayroll" style="overflow:auto; height:380px; width:100%; margin-left:2px;"> {section name=co_emp loop=$personalAll} <li><a href="LeaveData.php?queryEmpID={$personalAll[co_emp].EMP_ID}">{$personalAll[co_emp].FULLNAME}</a></li> <hr /> {sectionelse} <li>No records found</li> {/section} </ul> </div> <div id="EmpOTForm"> <fieldset> <legend>Overtime and Leave Form</legend> <input type="button" name="OTbtn" value="Overtime" onclick="OtFrmOP()")> <input type="button" name="Leavebtn" value="Leave" onClick="LeaveOP()"> <p class="serif"> <label id="LeaveEmpIDLabel">EMP ID</label><label id="LeaveNameLabel">NAME</label><label id="FromLeave"><a href="Javascript:showCal('RegCalendar1')">FROM DATE </a></label><label id="DaysLabel"><a href="Javascript:showCal('RegCalendar2')">TO DATE</a></label><label id="TypeLeave">LEAVE TYPE</label><label id="HLeave">H</label> <input type="text" name="EMP_NO" id="EMP_NO" value="{$empno}" size="8" > <input type="text" name="NAME" id="NAME" value="{$fullname}" size="35" > <input type="text" name="DATE_LEAVE_FROM" id="DATE_LEAVE_FROM" value="{$DATE_LEAVE_FROM}" size="9"> <input type="text" name="DATE_LEAVE_TO" id="DATE_LEAVE_TO" value="{$DATE_LEAVE_TO}" size="9"> {html_options id=TYPE name=TYPE options=$LeaveStatus selected=$TYPE style="width:140px;"} <input type="checkbox" name="H" id="H" value=""> <input type="button" name="Approve" value="Approve" id="Approve" onclick="ApproveLeaveOP()"> <input type="button" name="Edit" value="Edit" id="Edit" onclick="EditLeaveOP()"> <input type="hidden" name="dateprocess" id="dateprocess" value="{$dateprocess}"> </p> <input type="hidden" id="HOURS_LEAVE"> </fieldset> <div> <p> <table border="1" class="stat" width="auto"> <tr> <th>EMP ID</th> <th>NAME</th> <th>FROM DATE</th> <th>TO DATE</th> <th># of HOURS</th> <th>TYPE</th> <th>STATUS</th> </tr> {section name=att loop=$getleave} <tr> <td id = "EMPNO">{$getleave[att].EMP_NO}</td> <td >{$getleave[att].FULLNAME}</td> <td id = "DATE_LEAVE" onclick="opleave_edit('{$getleave[att].DATE_LEAVE_FROM}')">{$getleave[att].DATE_LEAVE_FROM}</td> <td >{$getleave[att].DATE_LEAVE_TO}</td> <td >{$getleave[att].HOURS_LEAVE}</td> <td >{$getleave[att].TYPE_LEAVE}</td> <td >{$getleave[att].STATUS_LEAVE}</td> </tr> {/section} </table> </p> </form> </div> </div> </div> I attach the sample form. Thank you I have this. <input name="delete[]" type="checkbox" id="delete" value="1" /> What I want to is get the value from this which is the "1" AND Get the id which would be "delete" I can get the value but i cant seem to get the id This is what I have been using foreach($_REQUEST['delete'] as $index=>$val){ echo $index; echo $val; } echo $index just gives me the num of array I am on and the $val gives the actually value. Can anyone help me out with getting the id or how I can specify a id. THanks Does anyone no a way to post a unchecked checkbox value? I have been having a bit of difficultly understanding how to submit a single checkbox values for a list of names and saving it in a MySQL database. The way it is meant to work is that a list of names from a table (Table1) is produced on the screen through a query. I have a checkbox that appears beside each individual name and if I tick the box I want it to save the value '1' to the database, otherwise the value remains as zero. When I tick the necessary boxes I wish to save it to another table (Table2, it is separate from Table1). The name and value needs to be saved to it. The problems that arises is how do I save the checkbox value for each individual name? Will I need to use a checkbox array or can I treat each name as independent? Hopefully you understand what I mean. Hello again, I have a form that has several options to select features of a computer (vga, dvi, ethernet, modem, zip, etc.) through checkboxes. In the database, it is stored as a 0/1 (false/true). What I am working on is an edit form to make changes if necessary, but I am having trouble populating the checkboxes that are marked as true already. Code: [Select] while($cmp = $_SESSION['DB']->fetch_array($cmpQ)){ $chkbxs = array('vga', 'ps2', 'usb', 'firewire', 'ethernet', 'cddvd', 'fdd', 'zip', 'dvi', 'serial', 'sound', 'wireless', 'modem', 'smartm'); foreach ($chkbxs as $value) { $check=""; if ($cmp[$value] == 1) { $check = "checked"; echo ''.$value.' <br/>'; } ...more code, form below This does it it should. I have an entry with vga, firewire, smartm, and zip selected, and $value returns that properly. In the form, this is how I have it set up. Code: [Select] echo '<input type="checkbox" name="hardware[]" value="vga" '.$check.'>'; Right now, every checkbox is selected, meaning that for some reason, $cmp[$value] == 1 is affecting all checkboxes in the form, even though it is only returning the 4 that are marked as selected when I echo $value. Am I missing something minor or am I going about this the wrong way? i have a form with multiple checkboxes, with the same name. so i put them in an array like this. Code: [Select] <input type='checkbox' name='test[]' value='' /> <input type='checkbox' name='test[]' value='' /> <input type='checkbox' name='test[]' value='' /> <input type='checkbox' name='test[]' value='' /> Now when i do print_r($_POST['test']; , it should display an array and if each checkbox has been ticked or not. it just comes up blank. Any idea? Hi guys! im new to phpfreaks *waving*
im trying to delete row from a table that is populated by data from database using checkbox(and it doesnt matter if its just one checkbox or multiple) but its not working, as in nothing happens. no delete, no errors or warnings, just a refresh.
table:
<form class="event-button-wrap" method="post" action="event.php"> <div class="button-wrap"> <input type="submit" id="del_event" name="del_event" value="Delete Event"/> </div> <div class="event-list-table2" > <table class="event-table"> <thead> <tr> <th>Event Name</th> <th class="head">Event Date</th> <th class="head">Venue</th> </tr> </thead> <tbody class="tbody-event-list-table2"> <?php require "connection.php"; $check = mysql_query("SELECT * FROM event"); if(mysql_num_rows($check) > 0) { while($row = mysql_fetch_array($check)) { $id = $row['event_id']; $name = $row['event_name']; $dstart = $row['start_date']; $venue = $row['event_venue']; echo "<tr> <td> <input type='checkbox' name='check[]' class='check' value='$id'>$name </td> </tr>"; } } else { echo "<tr> <td colspan='4'>There Are No Events.</td> </tr>"; } ?> </tbody> </table> </div> </form>process is before <!DOCTYPE html>: <?php if(isset($_POST['del_event'])) { if(isset($_POST['check'])) { foreach($_POST['check'] as $del_id) { $del_id = (int)$del_id; require "connection.php"; $sqlqueer = mysql_query("DELETE FROM event WHERE event_id = $del_id"); if($sqlqueer) { echo "<meta http-equiv=\"refresh\" content=\"0;URL=event.php\">"; } } } ?>thanks in advance! i have this in a loop and a form Code: [Select] <input type='checkbox' name='$topic' value='No' /> on the page the form directs to. How do i get each separate topic that has been checked? Let's say I have a list like this and in the parenthesis are the values: Page A (24) Page B (63) x Page C (33) Page D (22)x Page F (87)x Page E (45) The X mark the ones which are checked with a checkbox, and the values get inserted into the database in ONE row as follows: 63 22 87 (separated with spaces) And now an update to the list has been made, one x has been unchecked, the list looks as follows: Page A (24) Page B (63) x Page C (33) Page D (22) Page F (87)x Page E (45) How can I now know which checkbox exactly has been unchecked, so that I can remove that specific value from the row in the database? Once I've figured that out I'll figure out the rest. Basically what I need to know is: - that an uncheck has been done (removing) - an which value exactly has been unchecked Just FYI I need this for the admin panel of WordPress ones the user has checked a few options then the options will be saved and they'll be auto checked on the next visit. Checkbox list has the name like this: name="exclude[]" And then I simply use a foreach loop to go through all the values. Here's the code for the list: <ul> <!-- Right Section --> <?php $pages = get_pages(); $get_exclude_id = explode (' ', $get_exclude); foreach ($pages as $pagg) { ?> <li> <?php $option = '<input type="checkbox"'; if (in_array ($pagg->ID, $get_exclude_id)) { $option .= " checked "; } $option .= 'name="exclude[]" value="'. $pagg->ID .'" />'; $option .= $pagg->post_title; ?> </li> <?php echo $option; } ?> </ul> Here's the code for updating the ROW in the database. // add or update navi bar options if ($submit) { $get_exclude = get_option ('exclude_pages'); $page_id_string = $get_exclude . " "; foreach ($page_id as $value) { $page_id_string .= $value . " "; } update_option ('exclude_pages', $page_id_string); } Only works for adding values, but not for removing as of now. I hope I could explain clear enough to follow and I hope to hear some suggestions. Hi, so i have a problem. I'm using a script to enable and disable checkboxes, and i'm id-ing them fetching values from a database: while($data = mysqli_fetch_array($sql)) { if ($count % 5 == 0) { echo '</tr><tr>'; $count = 0; } echo '<td><input name="subject_level[]" class="subject_a" disabled="disabled" type="checkbox" id="subject_level_'.$data['subject_level_id'].'" value="'.$data['subject_level_id'].'"/>'; echo '<label for="subject_level_'.$data['subject_level_id'].'" class="subject_1">'.$data['subject_name'].'</label></td>'; $count++; //Increment the count } The names of the checkboxes come out fine, just that, is there any way to retrieve the values of the checkboxes into an array of some sort so that i could build a search query later? if($_POST(subject_level)) or if($_POST(subject_level[])) doesn't return true. does it make sense? im new to php so please forgive my ignorance. Help appreciated. Thanks! How do I post the values that are in a while loop and add them to mysql table? <form action="Test_Completed.php" method="post"> include '../Database/take_an_exam.php'; $intNumber = 1; while($info = mysql_fetch_array( $sql )) { echo "$intNumber, {$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; $intNumber++; } ?> <input type="submit" value="submit"/> </body> </html> </body> </html> Hey, I have checkbox and with these I am setting an exam. I want the questions to contain numbers. So for each question a number would be displayed. So far I am Only getting the question and the choices to display. <html> <?php session_start(); include '../Database/connection.php'; $Value22 = mysql_real_escape_string(trim($_POST['myselects'])); $_SESSION['myselect23'] = $Value22; //echo $_SESSION['myselect23']; ?> <body> <form action="Staff_Menu.php" method="post"> <?php include '../Database/previous_q.php'; while($info = mysql_fetch_array( $sql )) { echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; } ?> <input type="submit" value="submit"/> </body> </html> </body> </html> |