PHP - Extract Saved Dropdown Answer
I have a function that creates a dropdown list in a form. The User saves their answer to the mysql table. How do I get their preselected answer back out of the table when they visit the form again?
I know how to pull it from mysql and into a variable, but how to modify the below code to display the correct answer stumps me. Here is my dropdown function: Code: [Select] function dropdown($array, $id) { echo '<select name="'.$id.'" id="'.$id.'" class="select"><option value="">Select one...</option>'; foreach($array as $key => $value) { echo '<option value="'.$value.'">'.$value.'</option>'; } echo '</select>'; } Thanks for the help! Similar TutorialsHi, I have a search form where users can search by age and country. Users can also save their search so they can go back and do it again but the problem is when they reload their saved search, I need it to select the country that has been saved in the drop down. So if someone searched the United Kingdom, I need it to show United Kingdom in the select drop down instead of (Select Country). Is there any easy and quick way around this? Many Thanks This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=321546.0 So I have been working on my website for a while which all is php&mysql based, now working on the social networking part building in similar functions like Facebook has. I encountered a difficulty with getting information back from a link. I've checked several sources how it is possible, with title 'Facebook Like URL data Extract Using jQuery PHP and Ajax' was the most popular answer, I get the scripts but all of these scripts work with html links only. My site all with php extensions and copy&paste my site links into these demos do not return anything . I checked the code and all of them using file_get_contents(), parsing through the html file so if i pass 'filename.php' it returns nothing supposing that php has not processed yet and the function gets the content of the php script with no data of course. So my question is that how it is possible to extract data from a link with php extension (on Facebook it works) or how to get php file executed for file_get_contents() to get back the html?
here is the link with code&demo iamusing: http://www.sanwebe.c...-php-and-jquery
thanks in advance.
Hi, I was in the process of making thumnails for avatars It used to work before but now the files are being saved as resource ID and not in an image format. I can not point out what the issue is and also may I add when I try to echo nothing is happening. Code: [Select] $filename = $_FILES['myfile']['tmp_name']; if ($_POST['cpic']) { // Set a maximum height and width $width = 100; $height = 100; // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; $ratio_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); $location = "cid/$myid/$filename"; imagejpeg($image_p, $location, 100); $query =mysql_query ("UPDATE clp SET avatar ='$location' WHERE cid='1'"); header ("LOCATION: editprofile.php"); } I'm building a website that uses session variables. My understanding of session variables is that they only exist as long as the browser is open -- meaning that once the browser closes, the session variables are lost. hi all, I have an array(1,2,3,4) and i make a form and make checkboxes for this array and user selects 2,3 and 4 when user submit form then i save it in table by making selected check boxes and converting selected values into bitwise equivalent value like this foreach($data['meal_types'] as $v){ $mealTypeBits += pow(2,$v-1); } Now when i have to show user his selected data how will i compare table bitwise saved record with array(1,2,3,4) to get the values that he checked while saving. 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! I have a webpage where the candidates can attach their resumes and send to the admin.These attachments are saved in the mysql db as blob datatype.In another webpage the admin needs to download all this resumes and see the content. How will i code for that. Hello. I have been following a great tutorial that I found here regarding searching a database: Tutorial: http://www.phpfreaks.com/tutorial/simple-sql-search I was very happy to find and implement this as I have been looking to understand this for some time now. When I used this and ran it from my server (doing a search of the database), I bookmarked the page; my question relates to the next step: When I return to the page via the bookmark the actual search has been saved and is displayed, not just the search form. I do not understand this. This is the search page as noted (search term is "kim"): http://bluelinedown.netau.net/new_test.php?search=Kim&body=on&title=on&desc=on&matchall=on&submit=Search! I need it to be so that each time a user goes to this search page, no prior search is displayed and it is, of course, available for a new search. Is this issue related to sessions? And if so, how? Below is the actual code I am using for this search function/page: <?php /***************************** * Simple SQL Search Tutorial by Frost * of Slunked.com ******************************/ $dbHost = 'mysql7.000webhost.com'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = '********'; $dbPass = '*******'; $dbDatabase = 'a4542527_test1'; // the database you put the table into. $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT id, name, descrip FROM people WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['id'])?"`id` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['name'])?"`name` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['descrip'])?"`descrip` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`name` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `name`"; // order by title. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['id']}<br />{$row['name']}<br />{$row['descrip']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <html> <title>My Simple Search Form</title> <style type="text/css"> #error { color: red; } </style> <body> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Search For: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /><br /> Search In:<br /> Body: <input type="checkbox" name="body" value="on" <?php echo isset($_GET['body'])?"checked":''; ?> /> | Title: <input type="checkbox" name="title" value="on" <?php echo isset($_GET['title'])?"checked":''; ?> /> | Description: <input type="checkbox" name="desc" value="on" <?php echo isset($_GET['desc'])?"checked":''; ?> /><br /> Match All Selected Fields? <input type="checkbox" name="matchall" value="on" <?php echo isset($_GET['matchall'])?"checked":''; ?><br /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> </body> </html> Thank-you in advance for any help or explanation as to what to do next. ~Matty Hi, This is currently my code that generates a mail to me with all info the user provided in the form on the site. + it sends a auto reply to the user with details in it. I'd like to keep both emails stored in a log file for future use. Is this possible ? is it hard to add ? I've got no clue Anyone could help ? Code: [Select] <?php ob_start(); include_once('verbinding.php'); $result1 = mysql_fetch_array (mysql_query("SELECT COUNT(*) FROM `Clicks` WHERE Aan = '0'")); // controleren hoeveel rijen er zijn met "Aan" op 0 $lijst1 = $result1[0]; if($lijst1=='0') { // als de lijst leeg is wil dit zeggen dat ze allemaal op 1 staan en mogen ze gereset worden. mysql_query("UPDATE `Clicks` SET `Aan`= '0' WHERE `Aan`='1'"); } // indien er ook maar 1 veld op 0 staat zal er direkt naar hier worden gesprongen $result = mysql_fetch_array(mysql_query("SELECT ID,Email FROM `Clicks` WHERE Aan = '0' ORDER BY RAND() LIMIT 1")); $naarwie = $result['Email']; $ID = $result['ID']; echo $ID; echo $naarwie; mysql_query("UPDATE `Clicks` SET `Aan`= '1' WHERE ID = '$ID'"); mysql_close($verbinding); // Sluit de verbinding. // We hebben hem nu niet meer nodig. $fromemail="No-Reply <ikwerkthuis.be>"; // change here if you want $toemail=$naarwie; // change here if you want $sub="Online info aanvraag"; // change here if you want $success_page_name="bedankt.html"; ////// do not change in following if($_SERVER['REQUEST_METHOD']=="POST") { $fieldnm_1=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_1'])); $fieldnm_2=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_2'])); $fieldnm_3=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_3'])); $fieldnm_4=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_4'])); $fieldnm_5=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_5'])); $fieldnm_6=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_6'])); $contentmsg=stripslashes("<br><b><font style=color:#CC3300>$sub</font></b><br> <table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Voornaam *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_1</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Achternaam *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_2</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>E-mail *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_3</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Telefoon *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_4</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Werkstatus *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_5</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Leeftijd *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_6</td> </tr> </table> "); //// $headers = "MIME-Version: 1.0 "; $headers .= "Content-type: text/html; charset=iso-8859-1 "; $from=$fromemail; $headers .= "From: ".$from." "; @mail($toemail,$sub,$contentmsg,$headers); $IP = $_SERVER['REMOTE_ADDR']; $DATE = date("Y-m-d"); $TIME = date("H:i:s"); $NameOfSender = $fieldnm_1; $SurnameOfSender = $fieldnm_2; //$emailadd = $naarwie; $headers2 = "MIME-Version: 1.0 "; $headers2 .= "Content-type: text/html; charset=iso-8859-1 "; $from=$naarwie; $headers2 .= "From: ".$from." "; $email = $fieldnm_3; // use their addy instead of yours $subject = 'ikwerkthuis.be inloggegevens introductie film'; // change subject $text = 'Beste '. $NameOfSender .' '. $SurnameOfSender .',<br> <br> Welkom bij <A HREF="ikwerkthuis.be" TABINDEX="4">ikwerkthuis.be</A>.<br> Hieronder vind U de logingevens voor het bekijken van de introductiefilm:<br> <br> Adres: <A HREF="http://ikwerkthuis.be/index.php/introductie" TABINDEX="4">http://ikwerkthuis.be/index.php/introductie</A><br> Gebruikersnaam: introductie<br> Paswoord: film2012<br> <br> '. $contentmsg .'<br> <br> Wij nemen spoedig contact met u op.<br> <br> Met vriendelijke groeten,<br> Het ikwerkthuis.be team<br> <br> IP: '. $IP .'<br> Date: '. $DATE .'<br> Time: '. $TIME .''; // change text mail($email, $subject, $text,$headers2); // send another one out header("Location:$success_page_name"); } ?> Hello Pros... Hi. I have a standard HTML multiform working. Inputs from here goes into a MySQL table, and is re-used in the website. I want all inputs saved in the database as capital letters, to get a more clean overview, both in the database and on the website. I would also like to know where to insert this new line of code (if any) The first form input field looks like this: <input type="text" name="artist"/> Best regards Morris linux-file-structu what needs to be saved while moving the installation
well this is one of the best place to ask joomla-related question. today i have no question regarding joomla. today i want to ask a linux-question: i am preparing a upgrade from opensuse 13.1 to 13.2 and i want to do a fresh installation. first of all - as a preliminary task i will do a saving of all the files - that are in the home of the current installation what else shoud i safe - more than the /home/my_name should i save anyting else ... http://tldp.org/LDP/...sect_03_01.html Table 3-2. Subdirectories of the root directory Directory Content /bin Common programs, shared by the system, the system administrator and the users. /boot The startup files and the kernel, vmlinuz. In some recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today. /dev Contains references to all the CPU peripheral hardware, which are represented as files with special properties. /etc Most important system configuration files are in /etc, this directory contains data similar to those in the Control Panel in Windows /home Home directories of the common users. /initrd (on some distributions) Information for booting. Do not remove! /lib Library files, includes files for all kinds of programs needed by the system and the users. /lost+found Every partition has a lost+found in its upper directory. Files that were saved during failures are here. /misc For miscellaneous purposes. /mnt Standard mount point for external file systems, e.g. a CD-ROM or a digital camera. /net Standard mount point for entire remote file systems /opt Typically contains extra and third party software. /proc A virtual file system containing information about system resources. More information about the meaning of the files in proc is obtained by entering the command man proc in a terminal window. The file proc.txt discusses the virtual file system in detail. /root The administrative user's home directory. Mind the difference between /, the root directory and /root, the home directory of the root user. /sbin Programs for use by the system and the system administrator. /tmp Temporary space for use by the system, cleaned upon reboot, so don't use this for saving any work! /usr Programs, libraries, documentation etc. for all user-related programs. /var Storage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet, or to keep an image of a CD before burning it. well - reagarding the thunderbird and other things more. note: i have thunderbird and enigmail up and running. so i need to save a. the passwords b. the mails. question: is there a need to save more than the home/my_name ?! love to hear from you greetings I'm making a login area for the hotels in a booking system, where they enter their hotels' information, policy, and room rates but I want to make the room rates when it appears for clients, it appears with a percentage (commission) added to what the Hotel representative will enter So what's better? it should be added in the admin area of the hotels and gets saved in the database with the commission or I should add it in the booking form so the code grab the rate from the database, multiply it by the percentage and echo the result? I have folder with 100's images, how to find Height and width as Excel sheet? Hi. Can someone show me the proper way to do a feedback form (like a "Contact US" form). I have read about SQL injections and would like to know I am protecting against it. And the proper way to store the submitted data in a database for a client's records. I have a basic form I use, but I am unable to store the data properly. Any help or a code idea would be appreciated. Thanks much. Hi again all, When i add text to my database through a form, it throws an error if i type 'wouldn't', but not if i type a word without an apostrophe. Is there a simple fix for this please peeps? Many Thanks Me@newbie.com.uk+vat i saw this in a php function page he http://php.net/manual/en/function.stristr.php the line is if(stristr($string, 'earth') === FALSE) { specifically this this code <?php $string = 'Hello World!'; if(stristr($string, 'earth') === FALSE) { echo '"earth" not found in string'; } // outputs: "earth" not found in string ?> what is the significance of the '===' in there does it mean something? is there any difference from the '==' or the '=' ? Hi I made a curl and don't know what to do with the string I got back, I would need the id and the name of each, should I explode, don't know how to do that, here is what I got as answer: Quote string(596) "{"data":[{"name":"Esoterik Forum","category":"Community","id":"180883525283576"},{"name":"Hellsehen und Wahrsagen","category":"Company","id":"177967172214131"},{"name":"Spirituelle Lebensberatung","category":"Website","id":"164411270264299"},{"name":"Esoterik","category":"Website","id":"164524456919432"},{"name":"Kartenlegen und Hellsehen","category":"Company","id":"173933135951523"},{"name":"Exchange","category":"Application","id":"190533567633445"},{"name":"Astrologie","category":"Website","id":"164928140213920"},{"name":"Esoterik Forum","category":"Application","id":"184577371575355"}]}" |