PHP - Php Array Error Checkbox
database.php
________________________________________________________________________________________
$res = pg_query ($conn, "SELECT artist, composer, genre, title, album, label, price, description FROM music");
echo "<table border='1'>";
while($a = pg_fetch_array($res)){ echo "<td>" . $a['1'] . "</td>"; echo "<td>" . $a['2'] . "</td>"; echo "<td>" . $a['3'] . "</td>"; echo "<td>" . $a['4'] . "</td>"; echo "<td>" . $a['5'] . "</td>"; echo "<td>" . $a['6'] . "</td>"; echo "<td>" . $a['7'] . "</td>"; echo '<td><input type="checkbox" name="music[]" value="$ref"' . $row['0'] . $row['1'] . $row['2'] . $row['3'] . $row['4'] . $row['5'] . $row['6'] . $row['7'] . '"/></td>'; echo"</tr>"; } echo "</table>\n"; ?> _____________________________________________________________________________- shoppingbasket.php _____________________________________________________________________________- <form action="shoppingbasket.php" method="POST"> Send To Basket: <name="music"> <input type="submit" value="submit"> </form> cant get it to send data from database to this page shoppingbasket.php Similar TutorialsI 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 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? hello.... I'm stuck... I'm trying to populate a check box with a 2d array. I have made three arrays within one array, but when i run it, nothing appears.. here is the code i have used so far: Code: [Select] <legend>Optional extras</legend> <optgroup label="Entertainment"> <?php foreach($car_extras as $car_extras_id => $extras) { echo '.$car_extras_id.'; { foreach($extras as $entertainment) $i++; echo '<input type=checkbox name="options" value="'.$extras.'" id="entertainment'.$num[$i].'"/>'; echo '<label for ="entertainment'.$num[$i].'">'.$entertainment.'</label><br/>'; } } ?> This is the array code Code: [Select] $car_extras = array ("Entertainment"=>array("6 disc DVD changer", "TV function", "DAB digital radio", "Loudspeaker system - professional", "Multimedia navigation system"), "Communication"=>array("Universal remote control", "Voice control", "Navigation system","Head-up display"), "Safety & Security"=>array("Adaptive headlights", "Night vision with pedestrian recognition", "Run-flat tyres")); Thanks for the help! well i got a few checbox (look below for code) i want to make it so that if i click the checkbox's it sends all the check box value to one column with "," in between them Code: [Select] <input type="checkbox" name="genre" value="fighting" id="genre"/>fighting <input type="checkbox" name="genre" value="school life" id="genre" />school life <input name="genre" type="checkbox" id="genre" value="king" id="genre" />king <input name="genre" type="checkbox" id="genre" value="him" />him Hello, I have been spending over 6 hours trying to square this away and I have looked at some tutorials from PHPFreaks... Maybe I'm missing something. Basically I rebuilding the form from bottom up and I thought some check boxes would be easier for some part of the form instead of drop-down menu. Basically this form is submitting query to MySQL: article_add.php (Basically has the form) article_insert.php (Basically insert the data to MySQL) Here is one part of the form where the check box is located: Here is article_add.php <form action="article_insert.php" method="post"> <-- OTHER INPUT BOXES --> <div class="inputfieldtb"><label for="news_cat">News Categories:</label> <? echo "<table>"; echo "<tr>"; $counter = 1; while ($nc = mysql_fetch_array($news_cats)) { $ncat_id = $nc['ncat_id']; $ncat_name = $nc['ncat_label']; echo "<td><div><input type=\"checkbox\" name=\"category[]\" value=\"$ncat_id\" ''/>$ncat_name</div></td>\n"; if (($counter % 4) == 0) { echo "</tr><tr>"; } $counter ++; } echo "</tr></table>"; echo "<br />"; ?> </div> <-- MORE FORMS --> </form> Here is article_insert.php // CONNECT TO DATABASE include("../mods/connect.php"); <--- OTHER DATA INSERT IN MYSQL --> $news_cat = mysql_real_escape_string(implode(',', $_POST['category'])); // <-- Checkbox Data <--- MORE DATA INSERT IN MYSQL --> $query = "INSERT INTO news_articles VALUES ('<--- MORE CONTENT BEING INSERT INTO MYSQL -->,'$news_cat','$news_content',<--- MORE CONTENT BEING INSERT INTO MYSQL -->'')"; mysql_query($query) or die ('Error inserting new data into the data to the database: ' . mysql_error() . ''); The error I'm getting is "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '','','3','0','','','')' at line 1"; So what am I doing wrong? Once I get this resolved, I would like to learn how to display the checkbox / updated the checkbox as well. Thank you in advance for your time and your help with this problem. Why is it grouping the checked boxes instead of keeping them in order like area is? if(isset($_POST['submit'])){ for($i=0; $i<10; $i++){ echo "<br />Ignore = [".$_POST['ignore'][$i]."]"; if($_POST['ignore'][$i]!="true") echo ", Area = ".$_POST['area'][$i]; } } else { echo "<form method='post'><table>"; for($i=0; $i<10; $i++){ echo " <tr> <td><input type='checkbox' name='ignore[]' value='true' /></td> <td><input type='text' name='area[]' /></td> </tr>\n"; } echo " </table> <input type='submit' name='submit' value='Submit' /> </form>"; } Input: Quote Checked - ignored Unchecked - a Checked - ignored2 Unchecked - b Checked - ignored3 Unchecked - c Unchecked - d Checked - ignored4 Unchecked - e Checked - ignored5 Output: Quote Ignore = [true] Ignore = [true] Ignore = [true] Ignore = [true] Ignore = [true] Ignore = [], Area = c Ignore = [], Area = d Ignore = [], Area = ignored4 Ignore = [], Area = e Ignore = [], Area = ignored5 Hi. I have a form with a selection of checkboxes. I am trying to use an array to store the results in a single column of a mysql database. The problem is, instead of the values, it just stores 'array'. Each checkbox is like so: <input name="previous_diseases[]" value="Tuberculosis"/> Here is my code: Code: [Select] <?php try{ $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $database = new PDO('mysql:host=localhost;dbname=db', 'username', 'password', $pdo_options); $execution=$database->prepare('INSERT INTO form(title, forename, surname, address_1, address_2, address_city, address_county, address_country, address_postcode, email, previous_diseases, hear) VALUES(:title, :forename, :surname, :address_1, :address_2, :address_city, :address_county, :address_country, :address_postcode, :email, :previous_diseases, :hear)'); $execution->execute(array('title' => $_POST['title'], 'forename' => $_POST['forename'], 'surname' => $_POST['surname'], 'address_1' => $_POST['address_1'], 'address_2' => $_POST['address_2'], 'address_city' => $_POST['address_city'], 'address_county' => $_POST['address_county'], 'address_country' => $_POST['address_country'], 'address_postcode' => $_POST['address_postcode'], 'email' => $_POST['email'], 'previous_diseases' => $_POST['previous_diseases'], 'hear' => $_POST['hear'])); Can anyone please show me what I need to change to get the values inserted into the database. Thank you Script:
<?php // For example, the entries in the table. $entry1 = "text1"; $entry2 = "text2"; $entry3 = "text3"; // For example, the ID numbers in the table. $value1 = "140"; $value2 = "141"; $value3 = "142"; echo "<form method='POST' action='" . $_SERVER['PHP_SELF'] . "'>"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value1 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry1 . "' />"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value2 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry2 . "' />"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value3 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry3 . "' />"; echo "<input type='submit' name='submit' />"; echo "</form>"; // Here, only store those hashtag names where the "modify" checkbox is checked. ?>This is used for the admin panel. It is a form where the input fields hold the text ("hashtags") already inside of them. Basically, one would have to check the "modify checkbox" to modify a hashtag, then only the modified hashtags should get stored into an array. How to have those hashtags stored in the array with the checked checkbox as the factor? The suggestions are much appreciated. Edited by glassfish, 23 October 2014 - 10:06 AM. Problem: my checkbox array chkBrand[] is not saving data when I click the save button called cmdSave. Each checkbox specifies a brand connected to a model number. Multiple brands can be connected to each model number. (Don't ask, it's what the customer wants.) So, if I check the checkbox in row 0 and row 3, only row 0 shows up. If I check the boxes in row 0, 1, 5, only rows 0, 1 show up in chkBrand and $newchkbrandarr. First, my routine to see which button is checked is at the top of the php file. Here it is. else if (isset($_POST['cmdSave'])) //Try to save items first. { $newchkbrandarr=$_POST['chkBrand']; //Checkbox for each brand. $oldchkbrandarr=$_SESSION['oldchkbrandarr']; $olddata=$_SESSION['olddata']; //Non-brand Fields strung together. $brandlist=$_SESSION['brandlist']; //List of brands displayed. crPrintarr('chkBrand raw',$_POST['chkBrand']); //DEBUG. Prints array to screen. //===At this point chkBrand[] contains: 1 //Turn nulls in checkboxes to zeros. $cnt=count($newchkbrandarr); for ($j=0; $j<$cnt; $j++) { $newchkbrandarr[$j]=$newchkbrandarr[$j]+0; } //for j //Make sure that at least one brand is checked. $cnt=count($newchkbrandarr); crPrintarr('newchkbrandarr',$newchkbrandarr); //DEBUG //===At this point, $newchkbrandarr contains: 1, 0 $s='Elements in newchkbrandarr cnt='.$cnt; $s.=', count brandlist='.count($brandlist); crDebug($s); //DEBUG $cnt2=0; $cnt=count($newchkbrandarr); //Find number of elements. for ($j=0; $j<$cnt; $j++) { $cnt2=$cnt2+$newchkbrandarr[$j]+0; //$s='arrpos '.$j.': newchkbrandarr='.($newchkbrandarr[$j]+0).', cnt2='.$cnt2; //crDebug($s); //DEBUG } # for j Here is my code to construct the array of checkboxes, one per table row. Each checkbox has its array position explicitly defined as $x. $x starts at zero, and is incremented by 1 for each table row (each check box). $x=0; while ($row = mysqli_fetch_array($result)) { $br=trim($row['brand']); //Brand name to display $brandvar=$br; $brandlist[]=$br; //Save every found brand for later. //First find if brand is checked on table "brands". $query2 = "SELECT brand ". "FROM brands ". "WHERE ". "(partid=".$partidvar.") ". "AND (brand='".$br."') ". "ORDER BY brand ". ";"; $cntchk=crqryCount($query2,false); //If $cntchk>0 then brand is checked. //$s="Is brand stored already? <br/>$query2"; //crDebug($s); //DEBUG $query2 = "SELECT brand ". "FROM zzbrands ". "WHERE (brand='".$br."') ". "AND (prodnameoverride=1) ". "ORDER BY brand ". ";"; $override=crqryCount($query2,false); //Can this brand override product name? $s="\n"; $s.='<tr><td>'. '<input type="text" value="'.$br.'" id="txtBrand[]" name="txtBrand[]" '. 'size="20" readonly class="mydisabled" />'; $s.='<td align="center">'; $s.='<input type="checkbox" name="chkBrand['.$x.']" '. 'id="chkBrand['.$x.']" value="1" '; if ($cntchk>0) { $s.='checked="checked" '; $oldchkbrandarr[$x]=1; } else { $oldchkbrandarr[$x]=0; } $s.='/>'; Any ideas what I might be missing? Hi all, I have a set of checkboxes which I need to be able to send into a session, which can be picked up later but exploded (it could be a possible maximum 7 options, may be only be 1). I've been experimenting with foreach, but I can't get that into a session to be able to reuse, only $_POST which can't be carried over different pages. Also, once I have them inside a session, how do I print what's been selected (rather than having to pick out manually). IE - so if six have been selected, it prints those six options, or if it's two then it prints just those two choices. Thanks! Jason Hi there. I have a page that lists the records of a table. On this page I want to be able to edit/update two attributes of these records by a checkbox - e.g., being able to update multiple records at once. I thought the smartest way to achieve this would be by using arrays. I've implemented one checkbox array and have two fields. Currently when I change both fields and hit submit, the height value changes and the name value is changed to the last record displayed in the table. E.g. Height - 170 -> 160 -> UPDATED TO 160 Name - Test1 -> Test2 -> UPDATED TO VICTORY (last record listed in table; displayed alphabetically) My code is as follows: <?php include("connection.php"); $conn = oci_connect($UName,$PWord,$DB) or die("Database Error - Contact Admin - sjrei5@student.monash.edu"); if (empty($_POST["check"])) { $query = "SELECT * FROM HORSE ORDER BY HORSE_NAME"; $stmt = oci_parse($conn,$query); oci_execute($stmt); $Horses = oci_fetch_array ($stmt); ?> <form method="post" action="horse_multi.php"> <table border="1" id="customers"> <tr> <th>ID</th> <th>EDIT</th> <th>NAME</th> <th>HEIGHT</th> </tr> <?php while ($Horses = oci_fetch_array ($stmt)) { ?> <tr> <td><?php echo $Horses["HORSE_ID"]; ?></td> <td align="center"><input type="checkbox" name="check[]" value="<?php echo $Horses["HORSE_ID"]; ?>"></td> <td align="center"><input type="text" size="5" name="<?php echo $Horses["HORSE_ID"]; ?>" value="<?php echo $Horses["HORSE_HEIGHT"]; ?>"></td> <td align="center"><input type="text" size="20" name="HORSE_NAME" value="<?php echo $Horses['HORSE_NAME']; ?>"></td> </tr> <?php } ?> </table><p /> <h4><input type="submit" value="Update Selected Horses"></h4> </form> <?php oci_free_statement($stmt); } else { foreach($_POST["check"] as $horse_id) { $query = "UPDATE HORSE SET HORSE_NAME= '$_POST[HORSE_NAME]', HORSE_HEIGHT = ".$_POST[$horse_id]." WHERE HORSE_ID ='".$horse_id."'"; $stmt = oci_parse($conn,$query); oci_execute($stmt); } } ?> </body> </html> Any ideas? Hey basically i'm working on a multi checkbox way to delete messages stored in "crew_messages", i'm getting the error message "Unknown column 'Array' in 'where clause'" from the following code and i'm unsure as to why Code: [Select] if (isset($_POST["submit2"]) == "DELETE SELECTED") { for($i=0;$i<count($_POST["chkColor"]);$i++) { if(trim($_POST["chkColor"][$i]) != "") { $rawr = $_POST['chkColor']; $sql = "DELETE FROM crew_messages WHERE id = $rawr"; mysql_query($sql) or die(mysql_error()); } } } the check box itself Code: [Select] <input type="checkbox" name="chkColor[]" value="27"> any clues? cheers So I got help from here earlier with one problem and a few more have arisen, the biggest is for some reason my checkbox and dropdown array won't store the data and when it's supposed to check to verify there is at least 1 selected of each nothing happens... To be honest the ideal thing would be to have it check to see if the drop down size selection below the checkbox was selected, but I'll do whatever as long as it works. Thanks ahead of time for the help. Here's my page code: Code: [Select] <html> <HEAD> </head> <body> <?php require_once "formvalidator.php"; $error_hash = 'no'; $show_form = true; class MyValidator extends CustomValidator { function DoValidate(&$formars,&$error_hash) { if(stristr($formars['comments'],'http://')) { $error_hash['comments']="No URLs allowed in comments"; return false; } return true; } } if ($_SERVER['REQUEST_METHOD'] == "POST") { $validator = new FormValidator(); $validator->addValidation("email", "email", "<B>Email address is invalid.</B>"); $validator->addValidation("first", "req", "<B>Please provide your First name for invoice.</B>"); $validator->addValidation("last", "req", "<B>Please provide your Last name for invoice.</B>"); $validator->addValidation("addr", "req", "<B>Please provide your address for invoice.</B>"); $validator->addValidation("city", "req", "<B>Please provide your city name for invoice.</B>"); $validator->addValidation("state", "req", "<B>Please provide your State for invoice.</B>"); $validator->addValidation("zip", "num", "req", "<B>Please provide your zip for invoice.</B>"); $validator->addValidation("phone", "num", "<B>Numbers only in phone number.</B>"); if ($validator->ValidateForm()) { $show_form = false; } else { echo "<center><font color='#CC0000'><B>Validation Errors:</B></font></center>"; $error_hash = $validator->GetErrors(); foreach ($error_hash as $inpname => $inp_err) { echo "<center><p>$inpname : $inp_err</p></center>\n"; $show_form = true; } } $pic = $_POST['pic']; if(empty($pic)) { echo "<center><font color='#CC0000'><B>Please Select a picture.</B></font></center>"; } else { $r = count($pic); for($i=0; $i < $r; $i++) { echo "picture(s) requested $i was: " . $pic[$i] . "\r\n"; } } $size = $_POST['size']; if(empty($size)) { echo "<center><font color='#CC0000'><B>Please Select a picture size.</B></font></center>"; } else { $r = count($size); for($i=0; $i < $r; $i++) { echo "Sizes(s) requested $i was: " . $size[$i] . "\r\n"; } } if ($show_form === false){ // Grab the form vars $Pic = $_POST['pic'] ; $Size = $_POST['size'] ; $Email = $_POST['email']; $Name = $_POST['first'. 'last']; $Addr = $_POST['addr']; $City = $_POST['city']; $State = $_POST['state']; $Zip = $_POST['zip']; $comments = $_POST['comments'] ; //message body $mail_body .= "$Pic"."\r\n"; $mail_body .= "$Size"."\r\n"; $mail_body .= "$Email"."\r\n"; $mail_body .= "$Name"."\r\n"; $mail_body .= "$Addr"."\r\n"; $mail_body .= "$City,". " $State". " $Zip"."\r\n"; $mail_body .= "$Comments"."\r\n"; //sending to $recipient = "hakarune@gmail.com"; $subject = "Order Form"; //Headerfields $header = "From: " . $Email . " <" . $Email . ">\r\n"; //mail command mail($recipient, $subject, $mail_body, $header); echo "<div style='width:400px; margin:0 auto; border:1px solid #1e1e1e'>Your order has been sent successfully. <br>An Invoice will be either emailed or mailed to you, thank you for your order.<br>You will be redirected to the home page in 10 seconds...</div>"; //page redirect to home echo "<META HTTP-EQUIV=\"refresh\" content=\"10;URL=buttontest3.php\">"; } } if (true == $show_form) { ?> <form name="ordering" action="" method="POST"> <img src="1.jpg" /> <input type="checkbox" name="pic[]" value="1"> <br /> <select name="Type" size="1" name="size[]"> <option value="">Select Type</option> <option value="Original">Original $Price</option> <option value="Print Small">300x500 Print $Price</option> <option value="Print Medium">800x600 Print $Price</option> <option value="Print Large">1200x1280 Print $Price</option> <option value="Print XLarge">1282x1400 Print $Price</option> </select> <br /> <img src="2.jpg" /> <input type="checkbox" name="pic[]" value="2"> <br /> <select name="Type" size="1" name="size[]"> <option value="">Select Type</option> <option value="Original">Original $Price</option> <option value="Print Small">300x500 Print $Price</option> <option value="Print Medium">800x600 Print $Price</option> <option value="Print Large">1200x1280 Print $Price</option> <option value="Print XLarge">1282x1400 Print $Price</option> </select> <br /> <img src="3.jpg" /> <input type="checkbox" name="pic[]" Value="3"> <br /> <select name="Type" size="1" name="size[]"> <option value="">Select Type</option> <option value="Original">Original $Price</option> <option value="Print Small">300x500 Print $Price</option> <option value="Print Medium">800x600 Print $Price</option> <option value="Print Large">1200x1280 Print $Price</option> <option value="Print XLarge">1282x1400 Print $Price</option> </select> <br /> <img src="4.jpg" /> <input type="checkbox" name="pic[]" value="4"> <br /> <select name="Type" size="1" name="size[]"> <option value="">Select Type</option> <option value="Original">Original $Price</option> <option value="Print Small">300x500 Print $Price</option> <option value="Print Medium">800x600 Print $Price</option> <option value="Print Large">1200x1280 Print $Price</option> <option value="Print XLarge">1282x1400 Print $Price</option> </select> <br /> <img src="5.jpg" /> <input type="checkbox" name="pic[]" value="5"> <br /> <select name="Type" size="1" name="size[]"> <option value="">Select Type</option> <option value="Original">Original $Price</option> <option value="Print Small">300x500 Print $Price</option> <option value="Print Medium">800x600 Print $Price</option> <option value="Print Large">1200x1280 Print $Price</option> <option value="Print XLarge">1282x1400 Print $Price</option> </select> <br /> <br /> <br /> Information For Invoice: <font color="red">(Required Info = *)</font> <br /> <input type="text" name="first" Value="First Name" size="25" onfocus="value=''"><font color="red">*</font> <input type="text" name="last" Value="Last Name" size="25" onfocus="value=''"><font color="red">*</font> <br /> <input type="text" name="phone" Value="phone Number" size="25" onfocus="value=''"> <br /> <input type="text" name="email" Value="E-mail" size="30" onfocus="value=''"> <br /> <input type="text" name="addr" Value="Street Address" size="50" onfocus="value=''"><font color="red">*</font> <br /> <input type="text" name="city" Value="city" size="30" onfocus="value=''"><font color="red">*</font> <br /> <select name="state" size="1"> <option value="">Select State</option> <option value="AK">AK</option> <option value="AL">AL</option> <option value="AR">AR</option> <option value="AZ">AZ</option> <option value="CA">CA</option> <option value="CO">CO</option> <option value="CT">CT</option> <option value="DC">DC</option> <option value="DE">DE</option> <option value="FL">FL</option> <option value="GA">GA</option> <option value="HI">HI</option> <option value="IA">IA</option> <option value="ID">ID</option> <option value="IL">IL</option> <option value="IN">IN</option> <option value="KS">KS</option> <option value="KY">KY</option> <option value="LA">LA</option> <option value="MA">MA</option> <option value="MD">MD</option> <option value="ME">ME</option> <option value="MI">MI</option> <option value="MN">MN</option> <option value="MO">MO</option> <option value="MS">MS</option> <option value="MT">MT</option> <option value="NC">NC</option> <option value="ND">ND</option> <option value="NE">NE</option> <option value="NH">NH</option> <option value="NJ">NJ</option> <option value="NM">NM</option> <option value="NV">NV</option> <option value="NY">NY</option> <option value="OH">OH</option> <option value="OK">OK</option> <option value="OR">OR</option> <option value="PA">PA</option> <option value="RI">RI</option> <option value="SC">SC</option> <option value="SD">SD</option> <option value="TN">TN</option> <option value="TX">TX</option> <option value="UT">UT</option> <option value="VA">VA</option> <option value="VT">VT</option> <option value="WA">WA</option> <option value="WI">WI</option> <option value="WV">WV</option> <option value="WY">WY</option> </select> <br /> <input type="text" name="zip" Value="Zipcode" size="5" onfocus="value=''"><font color="red">*</font> <br /> <textarea name="comments" rows="5" cols="20" value="comments" onfocus="value=''"> </textarea> <br /> <input type="Submit" value="Submit"> <input type="reset" value="Clear Form"> </form> <?php }//true == $show_form ?> </body> </html> Hi all, Im creating a simple quiz where some of the questions are checkbox because there is more than one correct answer. What I would like to be able to do, is run an if statement to check if, say for example, options 1 and 5 out of 6 have been selected, then award the point. However the point is only awarded is both options are selected. Any suggestions? Thank you in advance i have this code: foreach($product_names as $product_row) { ?> <tr> <td > </td><td width='200px'><?php echo $product_row->getName(); ?></td> <td width='200px'><input type="checkbox" name="graphic[]" value="<?php echo $product_row->getId();?>" /></td> <td width='200px'><input type="checkbox" name="text[]" value="<?php echo $product_row->getId();?>" /></td> </tr> <?php } ?> </table> <table> <tr> <td> <input type='hidden' name='submit' value='Submit'> <?php if ( (isset($graphic)) || (isset($text) )) { echo "checkboxes checked"; //show submit button } else { //hide submit botton and echo "no boxes check"; } ?> </td> </tr> </table> so if i want to loop through grapic[] with the code: line 36 $graphics_selected = $_POST['graphic']; line 37 foreach($graphics_selected as $val) { if there is something in array(thus any checkbox is checked) enable submit button else if no checkboxes are checked disable submit button } i get errors: Notice: Undefined index: graphic in /home/helloises/svn_wappool/apps/lpmanager/modules/doc/templates/productSuccess.php on line 36 Warning: Invalid argument supplied for foreach() in /home/helloises/svn_wappool/apps/lpmanager/modules/doc/templates/productSuccess.php on line 37 please help???? Hello, I want to create an order form where people can order shirts with sizes and quantities. So in 1 form you have a column where people can check the size and after that the quantities. (see below the form) As result i want after pressing submit and selecting for example 3 shirts Large and 1 small: S=1, M=0, L=3, XL=0, XXL=0 Code: [Select] echo "<form method=\"post\" action=".$PHP_SELF."> <label>aantal <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\"> <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"S\">S<br /> <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\"> <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"m\">m<br /> <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\"> <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"l\">l<br /> <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\"> <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"XL\">XL<br /> <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\"> <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"XXL\">XXL<br /> </label> <input type=submit value=Select></form>"; i hope you can help me with it. thanks in regard! Hi all, I have been trying to figure this out for a few days already and can't seem to figure it out. I want to display a few images with a checkbox next to it so I can delete multiple images at once when I press the delete button. My problem is that I can't seem to figure out how to check if the checkbox is checked. if I uncheck one of them and click the delete button it deletes one from the array but I don't know which one was unchecked. For example if I uncheck the second one the array shows: Array ( => on [1] => on ) but I don't know which of the three was unchecked? Here is the code I have been testing with: Code: [Select] <?php // if submit button is clicked if(isset($_POST['submit'])) { // do delete function(); } // display deletethis[] array if (isset($_POST['deletethis'])) { echo "<pre>"; print_r ($_POST['deletethis']); echo "</pre>"; } $separate = array("http://funnypicturesimages.com/images/image/funny-dog-pictures.jpg", "http://1.bp.blogspot.com/-35wQMpYtNZc/TXWNx8y2xCI/AAAAAAAB_2o/9vZYNfWrGn8/s400/funny_demotivational_posters_01.jpg", "http://3.bp.blogspot.com/-TFnzZ8zFtgg/TXWNpodBkGI/AAAAAAAB_2Q/O_fOOSqFM6w/s400/funny_demotivational_posters_04.jpg"); echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; // display each image from array foreach ($separate as $value) { echo "<img src=".$value.">"; if ($_POST['deletethis'] = "on") { $checked="checked"; } else { $checked=""; } if ($_POST['deletethis'] != "") { echo "checked"; } else{ echo "unchecked"; } // if checkbox currently checked display it checked else display unchecked if ($checked == "checked") { echo '<input type="checkbox" name="deletethis[]" checked="checked"/><br /><br />'; } else { echo '<input type="checkbox" name="deletethis[]"/><br /><br />'; } } ?> <center><input type="submit" name="submit" value="Delete Checked"></center> </form> database.php Here's my second go at this since the pros in here seem to have given up on the standard methods. On a WordPress site running PHP 5.0.3 (or something like that) I have multiple checkboxes that return an array of values depending on which ones are checked. In the source code the checkboxes load up this way--- I will include the OUTPUT source code seen in the browser for two different multiple checkboxes -- one named "cp_checkbox_help" and the next named "cp_checkbox_charley" <div id="checkboxes"><table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <th colspan="2" scope="col">help checkbox</th> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_help[]" class="checkbox" id="" value="Sunday" checked="yes"/></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" >Sunday</td> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_help[]" class="checkbox" id="" value=" Monday" checked="yes"/></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" > Monday</td> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_help[]" class="checkbox" id="" value=" Tuesday" checked="yes"/></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" > Tuesday</td> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_help[]" class="checkbox" id="" value=" Wednesday" /></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" > Wednesday</td> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_help[]" class="checkbox" id="" value=" Thursday" /></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" > Thursday</td> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_help[]" class="checkbox" id="" value=" Friday" /></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" > Friday</td> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_help[]" class="checkbox" id="" value=" Saturday" /></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" > Saturday</td> </tr> </tr> </table></div><div class="clr"></div> <div id="checkboxes"><table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <th colspan="2" scope="col">Staff Provided</th> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_charley[]" class="checkbox" id="" value="Cook" checked="yes"/></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" >Cook</td> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_charley[]" class="checkbox" id="" value=" Housekeeper / Maid" checked="yes"/></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" > Housekeeper / Maid</td> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_charley[]" class="checkbox" id="" value=" Gardener" checked="yes"/></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" > Gardener</td> </tr> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="checkbox" name="cp_checkbox_charley[]" class="checkbox" id="" value=" Watchman" checked="yes"/></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" > Watchman</td> </tr> </tr> </table></div><div class="clr"></div> This code is on an EDIT page that allows a user identified by their post_id to just edit the Classified Ad they "own" and created. They are not given access to the WordPress Dashboard--just to this Edit function page. Here they can click on a list of their own ads and change things. As long as they select or unselect individual checkboxes within "cp_checkbox_help" or "cp_checkbox_charley" or "cp_checkbox_hello" and Submit the form the page returns with the new checked values showing correctly. HOWEVER, if they UNSELECT ALL associated checkboxes in one or both or all three of these multiple checkboxes when the ad is updated the former values return for checkboxes. The previous saved array does not get overwritten. I need help in modifying this code so that it detects the change if all checkboxes within a specific name are UNSELECTED and THEN overwrites that darned array! As my code shows-- JUST for the multiple checkbox arrays I IMPLODE and put a comma between each value and it is saved that way. Each array will have a different number of values inside and so I cannot just stick an UNSET in front of it. Finally, I need to confine the overwriting of the $meta_value array to JUST the $meta_key identified as 'cp_checkbox_charley'...otherwise in some tests of different way to write this I get the $meta_value wiped out for everything. And I must find a way to EXCLUDE these checkbox arrays so that the OTHER custom fields that start with "cp_" have their $meta_value's retained and updated either before or after running through the checkboxes. // update the ad and return the ad id $post_id = wp_update_post($update_ad); if($post_id) { // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) if (cp_str_starts_with($meta_key, 'cp_checkbox_charley') && is_array($_POST['cp_checkbox_help'])) $meta_value= implode(',', $_POST['cp_checkbox_charley']); else if (cp_str_starts_with($meta_key, 'cp_checkbox_charley') && is_null($_POST['cp_checkbox_help']))$meta_value= NULL ; if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) $meta_value = implode(',', $_POST['cp_checkbox_help']); if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) $meta_value= implode(',', $_POST['cp_checkbox_hello']); //echo $meta_key . ' <--metakey <br/>' . $meta_value . ' <--metavalue<br/><br/>'; // for debugging update_post_meta($post_id, $meta_key, $meta_value); } $errmsg = '<div class="box-yellow"><b>' . __('Your ad has been successfully updated.','cp') . '</b> <a href="' . CP_DASHBOARD_URL . '">' . __('Return to my dashboard','cp') . '</a></div>'; } else { // the ad wasn't updated so throw an error $errmsg = '<div class="box-red"><b>' . __('There was an error trying to update your ad.','cp') . '</b></div>'; } return $errmsg; } I know SOME PHP GENIUS has got a great solution! |