PHP - Search Mysql With Checkbox Array
Similar TutorialsHello, 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. So I've spent 2 days now searching the web on how to make my checkbox array on my form insert the value selected by the user into my database. Here is the code that I've written. All fields except for the checkbox array works fine. <?php virtual('/budgets/Connections/connAdmin.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['submit'])) { $workStyle = $_POST['art_photos']; // Setting up a blank variable to be used in the coming loop. $allStyles = ""; // For every checkbox value sent to the form. foreach ($workStyle as $style) { // Append a string called $allStyles with the current array element, and then add a comma and a space at the end. $allStyles .= $style . ", "; } // Delete the last two characters from the string. $allStyles = substr($allStyles, 0, -2); echo "<p>The resulting string is: <strong>$allStyles</strong></p>\r\n"; } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO daily_budget (rundate, slug, reporter, budgetInfo, notes, `section`, deadline, art_photos sidebar, sBudget) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['rundate'], "text"), GetSQLValueString($_POST['slug'], "text"), GetSQLValueString($_POST['reporter'], "text"), GetSQLValueString($_POST['budgetInfo'], "text"), GetSQLValueString($_POST['notes'], "text"), GetSQLValueString($_POST['section'], "text"), GetSQLValueString($_POST['deadline'], "text"), GetSQLValueString($_POST['art_photos'], "text"), GetSQLValueString($_POST['sidebar'], "text"), GetSQLValueString($_POST['sBudget'], "text")); mysql_select_db($database_connAdmin, $connAdmin); $Result1 = mysql_query($insertSQL, $connAdmin) or die(mysql_error()); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Budget Record</title> </head> <body> <?php if (isset($error)) { echo '<ul>'; foreach($error as $alert) { echo "<li class='warning'>$alert</li>\n"; } echo '</ul>'; } ?> <form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1"> <table align="center" width="60%" border="2" bgcolor="#FFFFFF"> <tr valign="baseline"> <td width="14%" align="right" nowrap="nowrap"><STRONG>Rundate:</STRONG></td> <td width="86%"> <input type="text" name="rundate" size="30" value="" id="jQueryUICalendar2"/> <script type="text/javascript"> // BeginWebWidget jQuery_UI_Calendar: jQueryUICalendar2 jQuery("#jQueryUICalendar2").datepicker(); // EndWebWidget jQuery_UI_Calendar: jQueryUICalendar2 </script></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><STRONG>Section:</STRONG></td> <td> <select name="section"> <option value=""></option> <option value="A1">A1</option> <option value="Pickup All">Pickup All</option> <option value="Region">Region</option> <option value="Atlantic">Atlantic</option> <option value="Business">Business</option> <option value="Features">Features</option> <option value="Sports">Sports</option> </select> </td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><strong>Slug:</strong></td> <td><span id="sprytextfield2"> <input type="text" name="slug" value="" size="32" /> <span class="textfieldRequiredMsg">REQUIRED</span></span><span style="color: #F00; font-weight: bold; font-size: 10px;"></span></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><strong>Budget Information:</strong></td> <td><span id="sprytextarea1"> <textarea name="budgetInfo" cols="50" rows="4"></textarea> <span class="textareaRequiredMsg">Required.</span></span><span style="color: #F00; font-weight: bold; font-size: 11px;"></span></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><strong>Notes:</strong></td> <td><input type="text" name="notes" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><strong>Reporter:</strong></td> <td><span id="sprytextfield3"> <input type="text" name="reporter" value="" size="32" /> <span class="textfieldRequiredMsg">Required.</span></span><span style="color: #F00; font-weight: bold; font-size: 10px;"></span></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><strong>Deadline:</strong></td> <td><input type="text" name="deadline" size="30" value="Enter date" id="jQueryUICalendar1"/><script type="text/javascript"> // BeginWebWidget jQuery_UI_Calendar: jQueryUICalendar2 jQuery("#jQueryUICalendar1").datepicker(); // EndWebWidget jQuery_UI_Calendar: jQueryUICalendar2 </script> </td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><strong>Artwork:</strong></td> <td><label> <input type="checkbox" name="art_photos[]" value="factbox" id="art_photos_0" /> Factbox</label> <label> <input type="checkbox" name="art_photos[]" value="graphic" id="art_photos_1" /> Graphic</label> <label> <input type="checkbox" name="art_photos[]" value="photo" id="art_photos_2" /> Photo</label> <label> <input type="checkbox" name="art_photos[]" value="video" id="art_photos_3" /> Video</label> <br /></td> </tr> <tr> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> <strong>Sidebar:</strong></td> <td valign="baseline"><span id="spryradio2"> <label> <input type="radio" name="sidebar" value="y" id="sidebar_0" /> Yes</label> <br /> <label> <input type="radio" name="sidebar" value="n" id="sidebar_1" /> No</label> <br /> <span class="radioRequiredMsg"><strong style="font-size: 11px">REQUIRED.</strong></span></span> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><strong>Sidebar Information:</strong></td> <td><input type="text" name="sBudget" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Insert record" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> <p> </p> <h3><a href="/new_budget/admin/manage_budgets.php"><strong>View your budget entry, make changes or delete your budget.</strong></a></h3> <script type="text/javascript"> <!-- jQuery("#jQueryUICalendar1").datepicker(); jQuery("#jQueryUICalendar2").datepicker(); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "none", {maxChars:15, validateOn:["change"]}); var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1", {validateOn:["change"]}); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3"); var spryradio2 = new Spry.Widget.ValidationRadio("spryradio2"); //--> </script> </body> </html> Need some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! After a few days of searching and running across a problem what is almost like mine on these forums (cant seem to find the link now) where the person was looking to search a database using checkboxes. What I am trying to do is use a list of checkboxes (http://www.animeseason.com/anime-list/categories/) exactly like this link and search my table which has the genres as columns. I am new to PHP and don't really have a starting point. I have taken a bunch of examples and came up with this. My HTML form with a list of all my checkboxes. Code: [Select] <form method="post" ACTION = "php/do_search.php"> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="1"> <a href="#Action">Action</a></li> <li><input type="checkbox" name="cat_check[]" value="2"> <a href="#Adventure">Adventure</a></li> <li><input type="checkbox" name="cat_check[]" value="3"> <a href="#Comedy">Comedy</a></li> <li><input type="checkbox" name="cat_check[]" value="4"> <a href="#Demons">Demons</a></li> <li><input type="checkbox" name="cat_check[]" value="5"> <a href="#Drama">Drama</a></li> <li><input type="checkbox" name="cat_check[]" value="6"> <a href="#Ecchi">Ecchi</a></li> <li><input type="checkbox" name="cat_check[]" value="7"> <a href="#Fantasy">Fantasy</a></li> <li><input type="checkbox" name="cat_check[]" value="8"> <a href="#Harem">Harem</a></li> <li><input type="checkbox" name="cat_check[]" value="9"> <a href="#Horror">Horror</a></li> <li><input type="checkbox" name="cat_check[]" value="10"> <a href="#Magic">Magic</a></li> <li><input type="checkbox" name="cat_check[]" value="11"> <a href="#Martial Arts">Martial Arts</a></li> <li><input type="checkbox" name="cat_check[]" value="12"> <a href="#Mecha">Mecha</a></li> <li><input type="checkbox" name="cat_check[]" value="13"> <a href="#Music">Music</a></li> </ul> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="14"> <a href="#Mystery">Mystery</a></li> <li><input type="checkbox" name="cat_check[]" value="15"> <a href="#Ninja">Ninja</a></li> <li><input type="checkbox" name="cat_check[]" value="16"> <a href="#Parody">Parody</a></li> <li><input type="checkbox" name="cat_check[]" value="17"> <a href="#Psychological">Psychological</a></li> <li><input type="checkbox" name="cat_check[]" value="18"> <a href="#Reverse Harem">Reverse Harem</a></li> <li><input type="checkbox" name="cat_check[]" value="19"> <a href="#Romance">Romance</a></li> <li><input type="checkbox" name="cat_check[]" value="20"> <a href="#Samurai">Samurai</a></li> <li><input type="checkbox" name="cat_check[]" value="21"> <a href="#School Life">School Life</a></li> <li><input type="checkbox" name="cat_check[]" value="22"> <a href="#Science Fiction">Science Fiction</a></li> <li><input type="checkbox" name="cat_check[]" value="23"> <a href="#Seinen">Seinen</a></li> <li><input type="checkbox" name="cat_check[]" value="24"> <a href="#Shoujo">Shoujo</a></li> <li><input type="checkbox" name="cat_check[]" value="25"> <a href="#Shounen">Shounen</a></li> <li><input type="checkbox" name="cat_check[]" value="26"> <a href="#Slapstick">Slapstick</a></li> </ul> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="27"> <a href="#Slice of Life">Slice of Life</a></li> <li><input type="checkbox" name="cat_check[]" value="28"> <a href="#Sports">Sports</a></li> <li><input type="checkbox" name="cat_check[]" value="29"> <a href="#Supernatural">Supernatural</a></li> <li><input type="checkbox" name="cat_check[]" value="30"> <a href="#Thriller">Thriller</a></li> <li><input type="checkbox" name="cat_check[]" value="31"> <a href="#Tragedy">Tragedy</a></li> <li><input type="checkbox" name="cat_check[]" value="32"> <a href="#Vampire">Vampire</a></li> </ul> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="33"> <a href="#Movie">Movie</a></li> <li><input type="checkbox" name="cat_check[]" value="34"> <a href="#OVA">OVA</a></li> <li><input type="checkbox" name="cat_check[]" value="35"> <a href="#Top Rated">Top Rated</a></li> <li><input type="checkbox" name="cat_check[]" value="36"> <a href="#Currently Airing">Currently Airing</a></li> <li><input type="checkbox" name="cat_check[]" value="37"> <a href="#Ended">Ended</a></li> <li><input type="checkbox" name="cat_check[]" value="38"> <a href="#Ongoing">Ongoing</a></li> </ul> <div id="submit_btn_pos"> <input type="submit" name="search" value="Lets Make Magic" class="submit_btn"> <> </form> My PHP script that right now seems to do nothing. Code: [Select] <?php //if we got something through $_POST if (isset($_POST['cat_check'])) { $con = mysql_connect("localhost","USERNAME","PASSWORD") or die("Connection error"); mysql_select_db("DATABASENAME")or die("database doesn't exist"); // sanitize user input $cleanData = array(); foreach($_POST['cat_check'] as $_comp) { //$cleanData = mysql_real_escape_query($_comp); } // Build query $compStr = implode("'), ('", $cleanData); $sql = "SELECT anime_name WHERE $_comp='1'"; } ?> My database has a layout of "Name of show, (every genere listed above)". Thanks for any help. Hi gang, new to posting but I've read the forum on and off. I'm coding a small community and will have a lot of questions for you over time. The first one is about a search function. We'll have users of different nationalities and languages and you will be able to search, only I was thinking there could be a better way. They'll enter those posts through a dropdown list and when you search it you will use checkboxes. I just don't see the results I want when I pick the array for info. Like I have this right now as the form (which is sent to the php page itself as POST): Nationality: <br /> <input type="checkbox"" name="natBox[]" size="30" value="all"/> All<br /> <input type="checkbox"" name="natBox[]" size="30" value="weuro"/> W Europe<br /> <input type="checkbox"" name="natBox[]" size="30" value="eeuro"/> E Europe<br /> <input type="checkbox"" name="natBox[]" size="30" value="wafrica"/> W Africa<br /> And the thing I was doing was to check the boxes with if (isset) and then make the query longer and longer, butI figure there could be a smarter way. Like if I was going to enter 200 countries I can't really check for all can I? After the check (now deleted) it sets the query to this: $query = "SELECT * FROM user_criteria WHERE (age BETWEEN '$ageFr' AND '$ageTo') AND nationality='$nationality'"; ...and the part I don't have now is to pick the array natBox and add every value so @nationality becomes for instance weuro OR wafrica etc. Got a more elegant approach? The result pages is supposed to have pagination like google help me please
Hi all How do I modify the below code to search multiple tables in mySQL database? $query = "select * from store_items where description like \"%$trimmed%\" or title like \"%$trimmed%\" or dimensions like \"%$trimmed%\" order by id ASC"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); It is for a search function and I need it to search another table called 'about_text' and 'faq_text' Thanks Pete 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! 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? 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 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 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. 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 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 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. 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 hello i need some help with my script and check boxes, i want it so if the user dosent click public it adds in the database 0 and public 1 i dont know how to submit that part, this is my script so far to add recipie <?php // Start_session, check if user is logged in or not, and connect to the database all in one included file include_once("scripts/checkuserlog.php"); // Include the class files for auto making links out of full URLs and for Time Ago date formatting include_once("wi_class_files/autoMakeLinks.php"); include_once ("wi_class_files/agoTimeFormat.php"); // Create the two objects before we can use them below in this script $activeLinkObject = new autoActiveLink; $myObject = new convertToAgo; ?> <?php // Include this script for random member display on home page include_once "scripts/homePage_randomMembers.php"; ?> <?php $sql_blabs = mysql_query("SELECT id, mem_id, the_blab, blab_date FROM blabbing ORDER BY blab_date DESC LIMIT 30"); $blabberDisplayList = ""; // Initialize the variable here while($row = mysql_fetch_array($sql_blabs)){ $blabid = $row["id"]; $uid = $row["mem_id"]; $the_blab = $row["the_blab"]; $notokinarray = array("fag", "gay", "shit", "fuck", "stupid", "idiot", "asshole", "cunt", "douche"); $okinarray = array("sorcerer", "grey", "shug", "farg", "smart", "awesome guy", "asshole", "cake", "dude"); $the_blab = str_replace($notokinarray, $okinarray, $the_blab); $the_blab = ($activeLinkObject -> makeActiveLink($the_blab)); $blab_date = $row["blab_date"]; $convertedTime = ($myObject -> convert_datetime($blab_date)); $whenBlab = ($myObject -> makeAgo($convertedTime)); //$blab_date = strftime("%b %d, %Y %I:%M:%S %p", strtotime($blab_date)); // Inner sql query $sql_mem_data = mysql_query("SELECT id, username, firstname, lastname FROM myMembers WHERE id='$uid' LIMIT 1"); while($row = mysql_fetch_array($sql_mem_data)){ $uid = $row["id"]; $username = $row["username"]; $firstname = $row["firstname"]; if ($firstname != "") {$username = $firstname; } // (I added usernames late in my system, this line is not needed for you) /////// Mechanism to Display Pic. See if they have uploaded a pic or not ////////////////////////// $ucheck_pic = "members/$uid/image01.jpg"; $udefault_pic = "members/0/image01.jpg"; if (file_exists($ucheck_pic)) { $blabber_pic = '<div style="overflow:hidden; width:40px; height:40px;"><img src="' . $ucheck_pic . '" width="40px" border="0" /></div>'; // forces picture to be 100px wide and no more } else { $blabber_pic = "<img src=\"$udefault_pic\" width=\"40px\" height=\"40px\" border=\"0\" />"; // forces default picture to be 100px wide and no more } $blabberDisplayList .= ' <table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC"> <tr> <td width="7%" bgcolor="#FFFFFF" valign="top"><a href="profile.php?id=' . $uid . '">' . $blabber_pic . '</a> </td> <td width="93%" bgcolor="#EFEFEF" style="line-height:1.5em;" valign="top"><span class="greenColor textsize10">' . $whenBlab . ' <a href="profile.php?id=' . $uid . '">' . $username . '</a> said: </span><br /> ' . $the_blab . '</td> </tr> </table>'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta name="Description" content="Web Intersect is a deft combination of powerful free open source software for social networking, mixed with insider guidance and tutorials as to how it is made at its core for maximum adaptability. The goal is to give you a free website system that has a network or community integrated into it to allow people to join and interact with your website when you have the need." /> <meta name="Keywords" content="web intersect, how to build community, build social network, how to build website, learn free online, php and mysql, internet crossroads, directory, friend, business, update, profile, connect, all, website, blog, social network, connecting people, youtube, myspace, facebook, twitter, dynamic, portal, community, technical, expert, professional, personal, find, school, build, join, combine, marketing, optimization, spider, search, engine, seo, script" /> <title>CookBookers</title> <link href="style/main.css" rel="stylesheet" type="text/css" /> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <style type="text/css"> #Layer1 { height:210px; } .style3 {font-size: 24px} body { background-color: #3c60a4; } </style> </head> <body> <p> <?php include_once "header_template.php"; ?> </head> <body style="margin:0px;"> <center> </p> <table border="0" align="center" cellpadding="0" cellspacing="0" class="mainBodyTable"> <tr> <td width="235" valign="top"> <td width="665" colspan="2" align="left" valign="top" style="background-color:#EFEFEF; border:#999 0px; padding:10px;"> <table border="0" cellpadding="6"> <tr> <td> <form method="POST" action="include/recipe.php"> <table cellpadding="0px" border="0" align="left" cellspacing="5px" style="font-size:14px;"> <tr> <td><span class="style3">Add New Recipie:</span><br /></td> <tr> <td><h4 style="margin-bottom:5px; color:brown;">Public: <input name="Pub" type="checkbox" id="Pub" value="checkbox" /> </h4> </td> </tr> <tr> <td><h4 style="margin-bottom:5px; color:brown;">Title: </h4> <input type="text" name="title"></td> </tr> <tr> <td><h4 style="margin-bottom:5px; color:brown;">Makes: </h4> <input type="text" name="make"></td> </tr> <tr> <td><h4 style="margin-bottom:5px; color:brown;">Ingrediants: </h4> <textarea rows="10" name="ingr" cols="40"></textarea><br></td> </tr> <tr> <td><h4 style="margin-bottom:5px; color:brown;">Method: </h4> <textarea rows="10" name="desc" cols="40"></textarea></td> </tr> <tr> <td><h4 style="margin-bottom:5px; color:brown;">Notes: </h4> <textarea rows="10" name="note" cols="40"></textarea></td> </tr> <tr> <td><input type="submit" value="Submit" style="padding:5px 10px;"></td> </tr> </table> </form> </td> </tr> </table> </tr> </table> </td> </tr> </table> <?php include_once "footer_template.php"; ?> </body> process the recipie <?php //include("session.php"); include("database.php"); @session_start(); $user = $_SESSION['username']; } //die($user); $pub=$_POST['pub']; $title=$_POST['title']; $make=$_POST['make']; $ingr=$_POST['ingr']; $desc=$_POST['desc']; $note=$_POST['note']; //if($user=="Guest"||$user==""){ //header("Location: ../index.php"); //} //else{ $database->AddRecipe($user,$title,$make,$ingr,$desc,$note); header("Location: ../add_recipie.php"); //} ?> anyones help would be appriceated thank-you Hey Guys,
I'm really struggling to find whats wrong with this code. The form before submit has several checkboxes as part of an array which is below
The next page then goes to this and I get the error "Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /homepages/39/d837976904/htdocs/Scheduler/add_job3.php:10 Stack trace: #0 {main} thrown in /homepages/39/d837976904/htdocs/Scheduler/add_job3.php on line 10"
<?php $process = $_GET["process"];
include "Includes/config.php";
$checkBox = implode(',', $_POST['engineers']);
if(isset($_POST['submit'])) mysql_query($query1) or die (mysql_error() ); echo "Complete"; }
?> Can anyone help with the code please |