PHP - Php And Checkboxes
Okay I am working on a mail script and my only problem is, is that when you select mutiple delete boxes, it only deletes one. How do I get it to delete all of the checked boxes?
Similar TutorialsHi, my PHP code currently outputs the results from a users search by querying a backend postgresql database. As result/row is retuned to the user i would like to be able to detect whether or not they have checked a checkbox at the end of each rown in which case multiple rows can then be deleted from the database upon the user clicking a 'delete multiple records' button. I have no problem in being able to display the checkboxes on the webpage but i am a little unsure as to how to refernce them and detect which ones the user has checked. Given my database stores hostnames/IP addresses would it be best to name each checkbox to reflect the hostname or name the value it returns when checked to reflect the hostname. Given the above and that I also store the results of a users search in a $_SESSION['hosts'][][] array how can I then tie the two together? Thanks for reading. I am using php to display information from a MySQL database. It starts with three radio buttons and upon selecting one it will display some information for all items in that category. I have all this working but I need to add check boxes for each item and when submitted it will display all information for those items. Below is the bit where I need to insert check box and I'm also attaching my php (leaving out html form and database as it shouldn't be required to help). I must do this as soon as possible, please help. Thanks.. Code: [Select] while ($row = mysql_fetch_assoc ($result_set)) { $ID = $row['id']; $auth = $row['entertainerauthor']; $title = $row['title']; $media = $row['media']; $feature = $row['feature']; printf ("\nID: %s",$ID); printf ("\nEntertainer/Author: %s",$auth); printf ("\nTitle: %s",$title); printf ("\nMedia: %s",$media); printf ("\nFeatu %s",$feature); print "\n"; } Hey Everyone, been a while. I need some help with an easy one. I'm brain farting and blanking out. Someone please help. HTML form that has checkboxes: Code: [Select] <form ...> <input name="check1" type="checkbox" value="Value 1"> </form> PHP Code $post_check1= $_POST["check1"]; $body .= "check1: ".$post_check1."\n"; The form doesn't return the value when checked. What I am missing? I know it's something simple. Please help. Thanks. hi guys....i have a doubt on the checkbox use and validation in php.... how do you enable one checkbox and once it is checked the others would be disabled automatically....... is this possible in php or do we use javascript.... ur guidances and help is appreciated in advance how would i get checkboxes to work. I have tried: $JobCategories = ($_GET['JobCategories[]']) ? $_GET['JobCategories[]'] : $_POST['JobCategories[]']; html looks like: <li><input name="JobCategories[]" type="checkbox" value="Admin" /> Admin</li> <li><input name="JoCategories[]" type="checkbox" value="Campaigning" /> Campaigning</li> I'm very new to php. I'm still learning slowly. I'm currently doing a page where im showing all my patient records but there's checkboxes to tick and select a particular patient and go to next page.php to see the details of their history. Here is my codings <?php include ("includes/db.php"); ?> <table width="455" align="center" height="129" border="0" cellpadding="0" cellspacing="1"> <tr> <td width="453"><form name="form1" method="post" action="patienthistory.php"> <table width="900" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <tr> <td align="center" bgcolor="#FFFFFF">#</td> <td align="center" bgcolor="#FFFFFF" width="100"><strong>Patient ID</strong></td> <td align="center" bgcolor="#FFFFFF" width="200"><strong>Patient Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Patient I/C</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Patient Mobile</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Patient Address</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>City</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>State</strong></td> </tr> <?php $sql = "SELECT patient_id, patient_name, patient_ic, patient_mobile, patient_add, patient_city, patient_state FROM patient_healthcare ORDER by patient_id ASC"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); while(list($patient_id,$patient_name,$patient_ic,$patient_mobile,$patient_add,$patient_city,$patient_state)=mysql_fetch_row($result)){ $checked="$patient_id" ; echo '<tr><td><input name="checkbox[]" type="checkbox" value="'.$patient_id.'" '.$checked.'/></td><td>'.$patient_id.'</td><td>'.$patient_name.'</td><td>'.$patient_ic.'</td><td>'.$patient_mobile.'</td><td>'.$patient_add.'</td><td>'.$patient_city.'</td><td>'.$patient_state.'</td></tr>'."\n"; } ?> When i tick one boxes and press Select. The next page.php shows all the records. I just want a particular record show not all. Need help. Help is appreciated. for example i have a form like this Code: [Select] <form name="input" action="page2.php" method="post"> <table cellpadding="20" width="100%"> <!-- BEGIN query --> <tr> <td> <img src="../eImages/{IMAGE}.jpg" style="width:200px;height:200px;" /> </td> <td> {EVENTTYPE}</br> {DPLACE} </br> {NAME}</br> {SPEAKERS}</br> {LOC}</br> {STREET}</br> {TIME} </br> </td> <td> <input type="checkbox" name="eventlist"> </td> </tr> <!-- END query --> </table> <input type="submit" value="Submit" /> </form> this is all dynamically loaded each time from a database so it could have several trs of this formal my goal is to only select 3 of them and then submit the form this is will make a checkbox for each one including all the details but the problem is that the checkboxes will all have the same name as oneanother is there a way to increment the checkbox name value each time it goes through the while loop in the database? thanks Hey guys I am confused about using checkboxes to delete entries. Yes, just for delete. Codes for table: Code: [Select] echo "<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\"> <table> <tr> <td width=\"55\" class=\"formLabelsS2\"><input type=\"submit\" name=\"delete\" value=\"Delete\" id=\"delete\"></td> <td> Please note that entries could not be restored once they are deleted!</td> </tr> </table> </form>"; echo "<table class=\"sortable\" id=\"query_quick1\" width=\"100%\" >\r\n"; echo "<thead>"; echo "\t<tr><th></th><th></th><th>Up.dated Query</th><th>Link</th><th>Promoter</th><th> # </th><th>Up?</th> <th>Ana. Area</th><th> # </th><th>Up?</th> <th>C. Type</th><th> # </th><th>Up?</th><th>Other C. Type</th> <th> # </th><th>Up?</th><th>Gen. Back.</th><th> # </th><th>Up?</th> <th>Other Gen. Back.</th><th> # </th><th>Up?</th><th>Author</th><th> # </th><th>Up?</th> <th>Other</th><th> # </th><th>Up?</th><th>Date</th><th>Email</th> <th>F. Name</th><th>L. Name</th></tr>\r\n"; echo "</thead>"; if($result->num_rows){ while ($row = $result->fetch_array()){ $RowCount ++; $row_color = ($RowCount % 2) ? $color1 : $color2; echo "\t<tr class=\"$row_color\" > <form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\"> <td><input type =\"hidden\" name = \"id\" value=\"{$row['id']}\"></td> <td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"{$rows['id']} \"></td> <td>{$row['query']}</td><td>{$row['link']}</td> <td>{$row['pro']}</td><td>{$row['pro_count']}</td> <td>{$row['pro_update']}</td> <td>{$row['ana']}</td><td>{$row['ana_count']}</td><td>{$row['ana_update']}</td> <td>{$row['cell']}</td><td>{$row['cell_count']}</td><td>{$row['cell_update']}</td> <td>{$row['cellother']}</td><td>{$row['cellother_count']}</td><td>{$row['cellother_update']}</td> <td>{$row['gen']}</td><td>{$row['gen_count']}</td><td>{$row['gen_update']}</td> <td>{$row['genother']}</td><td>{$row['genother_count']}</td><td>{$row['genother_update']}</td> <td>{$row['author']}</td><td>{$row['author_count']}</td><td>{$row['author_update']}</td> <td>{$row['other']}</td><td>{$row['other_count']}</td><td>{$row['other_update']}</td> <td>{$row['date']}</td><td>{$row['Email']}</td> <td>{$row['First_Name']}</td><td>{$row['Last_Name']}</td> </form></tr>"; } } echo "</table>"; php for deleting entries: Code: [Select] } elseif(isset($_SESSION['user_id']) AND isset($_POST['delete'])){ $connect=db_connect_2(); foreach($_POST['checkbox'] as $check) { $delete = mysqli_query("DELETE FROM mailing_list WHERE id = '$check'"); } $body = "mailingList.php"; } Error pops up: Warning: Invalid argument supplied for foreach() Of course no entries are deleted due to this warning. Help would be greatly appreciated as always Thanks. Hey all, I am fairly new in the php world and have set myself a challenge to create a display of a database. I have the database displaying what I want but now am trying to have a 'complete' field where if ticked it will delete that field from the db. The row ['complete'] line 30 is saved in the db as '0' when ticked I want this to change to a '1' and delete that line from the db. I have tried a few things but am getting a little bit lost. Any help would be much appreciate <?php $con = mysql_connect("Host","USER","PASS"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("TABLE", $con); $result = mysql_query("SELECT * FROM Priority"); echo "<table border='1' width='100%'> <tr> <td width='5%'>Ticket Number</td> <td width='5%'>Order #</td> <td width='65%'>Ticket Info</td> <td width='15%'>Assigned by</td> <td width='5%'>Priority</td> <td width='10%'>Complete</td> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>#" . $row['ID'] . "</td>"; echo "<td>" . $row['OrderNumber'] . "</td>"; echo "<td>" . $row['TicketInfo'] . "</td>"; echo "<td>" . $row['Assignedby'] . "</td>"; echo "<td>" . $row['Priority'] . "</td>"; echo "<td><input type='checkbox' name='Check' value='Check' /></td>"; //the last row, where the checkbox is is actually a row called ['complete'] } if(isset($Check) && $Check != "") { mysql_query("UPDATE Priority SET Complete = '1' WHERE $row = 'ID'"); } echo "</table>"; mysql_close($con); ?> <?php $con = mysql_connect("HOST","USER","PASS"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_query("DELETE FROM Priority WHERE Complete='1'"); mysql_close($con); ?> I am having trouble setting a checkbox to "checked" if the row "published" is set to "1" (0 being not checked). I know this involves an if published==1 then print "checked", but i just cant get it to work. Any help would be greatly apprecatied: <?php include "base.php"; $sql="SELECT * FROM project"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center"><strong>title</strong></td> <td align="center"><strong>Published</strong></td> <td align="center"><strong>Promoted</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ $pub = $rows['publised']; ?> <tr> <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td> <td align="center"><? echo $rows['title']; ?></td> <td align="center"><input name="published[]" type="checkbox" id="published" value="<? echo $rows['published']; ?>"></td> <td align="center"><input name="promoted[]" type="text" id="promoted" value="<? echo $rows['promoted']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE project SET published='$published[$i]', promoted='$promoted[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update_multiple.php"); } mysql_close(); ?> i am currently developing a voting system for a school project using dreamweaver.. on my vote page, i use checkboxes to select/vote a number of candidates. i want to automatically add/count the total tally and update my database upon submission of votes. since im new to php, all my codes are generated by dreamweaver..and dreamweaver doesn't have a function for handling multiple row update on database. can anyone please help with editing this code to make it work for my system? thanks in advance Code: [Select] <?php require_once('Connections/organizazone_db.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE tbl_candidates SET votecount=%s WHERE user_id=%s", GetSQLValueString(isset($_POST['vote[]']) ? "true" : "", "defined","1","0"), GetSQLValueString($_POST['user[]'], "text")); mysql_select_db($database_organizazone_db, $organizazone_db); $Result1 = mysql_query($updateSQL, $organizazone_db) or die(mysql_error()); } mysql_select_db($database_organizazone_db, $organizazone_db); $query_rs_candi = "SELECT * FROM tbl_candidates"; $rs_candi = mysql_query($query_rs_candi, $organizazone_db) or die(mysql_error()); $row_rs_candi = mysql_fetch_assoc($rs_candi); $totalRows_rs_candi = mysql_num_rows($rs_candi); $query_rs_candi = "SELECT * FROM tbl_candidates"; $rs_candi = mysql_query($query_rs_candi, $organizazone_db) or die(mysql_error()); $row_rs_candi = mysql_fetch_assoc($rs_candi); $totalRows_rs_candi = mysql_num_rows($rs_candi); ?> <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <table border="1"> <tr> <td> </td> <td>user_id</td> <td>votecount</td> </tr> <?php do { ?> <tr> <td><input name="vote[]" type="checkbox" id="vote[]" value="1" /> <label for="vote[]"></label></td> <td><label for="user[]"></label> <input name="user[]" type="text" id="user[]" value="<?php echo $row_rs_candi['user_id']; ?>" /></td> <td><?php echo $row_rs_candi['votecount']; ?></td> </tr> <?php } while ($row_rs_candi = mysql_fetch_assoc($rs_candi)); ?> </table> <br /> <br /> <input type="submit" name="submit" id="submit" value="Submit" /> <input type="hidden" name="MM_update" value="form1" /> </form> <?php mysql_free_result($rs_candi); ?> Hi all, Hi have a bit of a problem that I am completely stuck on. I have a form on a website that needs checkboxes to be processed by PHP, but i have no idea how to implement them. I have found examples, but my knowledge of php is exactly zero, so its confusing the hell out of me. The website is: http://www.geelongnannies.com.au/test/employment.html http://www.geelongnannies.com.au/test/freecontactformprocess3.php http://www.geelongnannies.com.au/test/freecontactformsettings.php if anyone can have a look and give me an example of how to change the php to process the checkboxes when submitted, I will be very grateful cheers! I am trying to prepopulate some checkboxes from two tables, the first one holds the already chosen items, the second holds ALL existing items available. Now, the first tables items consist of values such as 1,2,3,7,22 which is also the ID numbers of the second table, so I need it to show ALL available options and have a check in the ones already chosen so they can be UNchecked if need be. Any help would be greatly appreciated. Code is as follows: function my_features_checkboxesLand($features){ $feature2 = explode(",", $features); $feature3 = implode(',', $feature2); echo ' <div class="clear"></div> <div class="title">Please select the Additional features.</div> '; $result = mysql_query("SELECT * FROM features WHERE f_id IN ( $feature3 ) || f_status='1' AND land_option='1'") or die("Sql error : " . mysql_error()); $f_id = $row['f_id']; $f_name=$row['f_name']; echo $feature3. '<br><br>'; while($row = mysql_fetch_assoc ($result)){ $feature3 = array($row['f_id']); foreach($feature3 as $var) echo '<div class="cbwrapper"><label><input type="checkbox" '; if($feature3){echo $feature3. ' checked ';}elseif($feature3 !=$row['f_id']){echo ''; }; echo 'name="features[]" value="'.$row["f_id"].'">'.$row["f_name"].', '.$row['f_id'].'</label></div>'; $i++; if(($i%4) == 0){ echo '<div class="clearboth"></div>'; } } } Hi, I was wondering if anyone knows how I might do a search in a database from a form using checkboxes, where the code is like this below please? I want to do a database query like this, if firstname is checked, and gender is checked. I want to find someone in the database with that gender and first name only. If all of them are checked, find all matches to that criteria. I think this might be a lot harder than I describe, but that is what I need to do. like this Code: [Select] mysql_query("SELECT users WHERE gender LIKE '%gender%, OR firstname LIKE....." Code: [Select] Search the database by: <form action="search.php" method="post"> <p> <input type="checkbox" name="firstname2" size="20" id="firstname2" value="firstname2" /> First Name<br/> <input type="checkbox" name="lastname2" size="20" id="lastname2" value="lastname2" /> Last Name<br/> <input type="checkbox" name="dob2" size="20" id="dob2" value="dob2" /> Date of Birth<br/> <input type="checkbox" name="gender2" size="20" id="gender2" value="gender2" /> Gender<br/> <input type="submit" name="search" value="Search" /> <input type="reset" name="reset" value="reset" /> </form> Hi, I'm completely new to anything that is not html but I'm wondering if in something like php I can get a checkbox to permanently save through reloads and different machines. My idea was just to have a page with only a checkbox on it, and then load that through and iframe in html. If anybody could give me the code for that checkbox page (complete if possible as I don't really know anything about that type of programming) I would be very grateful. Thank You Hi All!! I am a little confused. I have a form where I want around 15 different checkboxes, all or some of these can be checked. When the form is sent I insert the fields into a database. I am wondering how I can have only the fields checked saved into the database, without having to have a row for each field. Thanks Chris So everything works except for the capture of whether or not the checkbox was checked. It works for the "Tour" variable, however I can only get it to work for one of the the other ones. Everything from tour to the end is a checkbox. Any idea on what I'm doing wrong? I think it has to do with "<td>" versus the "<tc>" but I really have no clue. Thanks Code: [Select] while ($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>".$row['Timestamp']."</td>"; echo "<td>".$row['First_Name']."</td>"; echo "<td>".$row['Last_Name']."</td>"; echo "<td>".$row['Prefer']."</td>"; echo "<td>".$row['Home']."</td>"; echo "<td>".$row['Phone']."</td>"; echo "<td>".$row['Email']."</td>"; echo "<td>".$row['Affiliation']."</td>"; echo "<td>".$row['Hear']."</td>"; echo "<td>".$row['Tour']."</tc>"; echo "<td>".$row['Dday']."</tc>"; echo "<td>".$row['SMS']."</tc>"; echo "<td>".$row['Annual']."</tc>"; echo "<td>".$row['OSS']."</tc>"; //echo "<td>".$row['Class']."</td>"; echo "</tr>"; } //end while ($row = // Free the resources associated with the result set // This is done automatically at the end of the script mysql_free_result($result); }//end if($result) }//end else if(!$db) ?> </form> </table></body></html> Hey I'm trying to send my check-boxes with PHP. Before i added them to my script everything worked fine, i tested the form and i received the answers in my inbox. when i tried to let the checkboxes work, it stopped working. Please help me out! ! I've added this to check my check-boxes: Code: [Select] if ($_POST['Keukens'] == 'on') { $Keukens = "Ja"; } else { $Keukens = "Nee"; } if ($_POST['Badkamers'] == 'on') { $Badkamers = "Ja"; } else { $Badkamers = "Nee"; } if ($_POST['Kasten'] == 'on') { $Kasten = "Ja"; } else { $Kasten = "Nee"; } if ($_POST['Kantoormeubels'] == 'on') { $Kantoormeubels = "Ja"; } else { $Kantoormeubels = "Nee"; } if ($_POST['Tafels'] == 'on') { $Tafels = "Ja"; } else { $Tafels = "Nee"; } if ($_POST['Overige'] == 'on') { $Overige = "Ja"; } else { $Overige = "Nee"; } This is the delivery part: Code: [Select] else { $recipient = "sven@hotmail.com"; //Het email adres van de Ontvanger. $subject = $_POST['sub']; //Onderwerp van de mail. $header = "From: " . $_POST['uwemail'] . "\n"; $mail_body = "Het Contact formulier werd op " . date("d-m-Y") . " om " . date("H:i") . " uur uitgevoerd.\n"; $mail_body .= "De volgende persoon vulde het contact formulier in:\n\n"; $mail_body .= "Voorletters: " . $_POST['voorletters'] . "\n"; $mail_body .= "Achternaam: " . $_POST['naam'] . "\n\n"; $mail_body .= "Adres: " . $_POST['adres'] . "\n"; $mail_body .= "Postcode: " . $_POST['postcode'] . "\n"; $mail_body .= "Woonplaats: " . $_POST['plaats'] . "\n\n"; $mail_body .= "Telefoonnummer: " . $_POST['tel'] . "\n"; $mail_body .= "E-mailadres: " . $_POST['uwemail'] . "\n\n"; $mail_body .= "Onderwerp: " . $_POST['sub']. "\n"; $mail_body .= "Vraag: " . $_POST['field']. "\n\n"; $mail_body .= "Interesses:\n\n"; $mail_body .= "Keukens: ".$Keukens."\n"; $mail_body .= "Badkamermeubels: ".$Badkamermeubels."\n"; $mail_body .= "Kasten: ".$Kasten."\n"; $mail_body .= "Kantoormeubels: ".$Kantoormeubels."\n"; $mail_body .= "Tafels: ".$Tafels."\n"; $mail_body .= "Overige: ".$Overige."\n"; $mail_body .= "\n\n -- Einde van het formulier--"; mail($recipient, $subject, $mail_body, $header); echo "<font color=\"#FFFFFF\"><center><b>Bedankt voor uw reactie.</b><br><br>Wij zullen zo snel mogelijk contact met u opnemen.<br> Met vriendelijke groet,<br>Sven</b><br><br><br>"; echo "Terug naar het <a class=\"main\" href='javascript:history.back(1)'>formulier</a></center></font>"; } } else { ?> This the HTML part: Code: [Select] <font face="Verdana, Arial, Helvetica, sans-serif"> <label> <input type="checkbox" name="Keukens" id="keuze1" value="Keukens"/> <font color="#FFFF00" size="2"> <font size="1">Keukens</font></font></label> <font color="#FFFF00" size="1"><br /> <label> <input type="checkbox" name="Badkamers" id="keuze2" value="Badkamers"/> Badkamermeubels</label> <br /> <label> <input name="Kasten" type="checkbox" id="keuze3" value="Kasten" /> Kasten</label> <br /> <label> <input type="checkbox" name="Kantoormeubels" id="keuze4" value="Kantoormeubels"/> Kantoormeubels</label> <br /> <label> <input type="checkbox" name="Tafels" id="keuze5" value="Tafels"/> Tafels</label> <br /> <label> <input type="checkbox" name="Overige" id="keuze6" value="Overige"/> Overige</label> </font><br /> </font></div> I have encountered a brick wall trying to use checkboxes. I am attempting to create a small form where I can record if a customer's item has been sent. The way I intend it to work is that the name and ID of the customer (stored in the 'customer' table) are retrieved through a query and displayed in two columns. In the third column is a checkbox beside the name and ID of each customer which, when ticked, sends a value to a second table called 'sentorders' for that particular person. As I am just trying to understand the basics of this for now, a list of all customers will be shown for the time being. The default value of the checkbox needs to be 'No' and if the checkbox is ticked the value should become 'Yes'. When a checkbox is ticked, the customer name, ID and current date are sent to the 'sentorders' table. Only if the box is ticked will the details be stored in the table. The problem I having is how do I set up the checkbox to work as described above. I have had a look at other questions online, but don't understand how it works. Any help would be appreciated. My current code is as follows. <?php $query = mysqli_query ($connect, "SELECT name, id FROM customer"); // Create Table echo '<table align="left"> <tr> <td align="left"><b>Name</b></td> <td align="left"><b>ID</b></td> <td align="left"><b>Order Sent</b></td> </tr>'; // Show Name/ID while ($row = mysqli_fetch_array($query)) { echo '<tr><form action="order_sent.php" method="post"><td align="left"> <td align="left">' . $row['name'] . '</a></td> <td align="left">' . $row['id'] . '</td> <input type="checkbox" name="order[];" value=''></tr>'; } echo '</table><p align="left"><input type="submit" name="enter" value="Update"/><input type="hidden" name="enter" value="TRUE" /></form>'; } ?> Hopefully someone can help me before I run to the top of a bell tower Okay, so aside from the dramatics, total noob here, playing around with PHP/Jquery/mySQL. I'm trying to search a database using three checkboxes, these are keywords that are sent via Jquery to a php file where i'll do a search against the database and throw back any articles that match the keyword. The Jquery/Form part is working, i'm just a little lost (to say the least) on where to go in the PHP end of things. I'm following Learning PHP and MySQL by O'Reilly but I'm stuck here. So the form looks like this: Code: [Select] <form id="findkeywords"> <ul> <li><input type="checkbox" name="keywords[]" value="keyword1" title="keyword1" /></li> <li><input type="checkbox" name="keywords[]" value="keyword2" title="keyword2" /></li> <li><input type="checkbox" name="keywords[]" value="keyword3" title="keyword3" /></li> <li><input type="submit" name="submit" class="search" /></li> </ul> </form> The jQuery that passes the checkboxes to the php file is as follows: Code: [Select] <script type="text/javascript"> $(document).ready(function(){ $(".search").click(function() { $.post("parser2.php", $("form#findkeywords").serialize(), function(data) { $.each(data, function() { $("div#result").append("<li class='arrow'><a href='parser2.php?id=" + this.id + "'>" + this.title + "</a></li>"); }); $("div#jsonContent").show(); }); }); }); </script> Ok, so the trouble comes here, I want to take the checked boxes into the PHP file through $_POST, check for articles with the keywords and return them to the jQuery to be displayed, works fine with a simple 'type in and search', but I just can't get my head around the checkboxes. The (horrid) code: Code: [Select] $link = mysql_connect("localhost","root","root"); mysql_select_db("keyworddb", $link); foreach($_POST['keywords'] as $keyword => $value) { $query = mysql_query("SELECT * FROM articles WHERE keyword LIKE '%". $value ."%' "); $arr = array(); while( $row = mysql_fetch_array ( $query ) ) { $arr[] = array( "id" => $row["id"], "title" => $row["title"] ); } echo json_encode($arr); } Any ideas? What am I doing so horribly wrong (apart from everything in parser2.php ) Thanks! |