PHP - Searching Function - How To Display The Selected Result On Its Own From The Returned List?
Hello, I have been developing a website that needs to display products online, I was originally going to hand-write the PHP code but I thought it would be more beneficial to make it database orientated as new products can easily be added and a search function becomes possible.
I have it working so far so good, but the last part I can't seem to get working. I have it so all the products that have the desired category are displayed, but I want a more detailed analysis of the product to appear when the image is clicked, which at the moment, displays a blank page. http://www.webwib.co...?p=floorpuzzles - this is the hand coded version that demonstrates how I want it to work. http://www.webwib.co...hp?floorpuzzles - this is the db version so far, it works how it is intended to apart from the last stage, which returns as a blank page rather than a dedicated page for the selected product. Here is my code, the third segment beginning with "if(isset($_GET['$ID'])){", is my attempt at the final stage. <?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); if(isset($_GET['floorpuzzles'])){ echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID#productspage\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['anothercategory'])){ $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . AnotherCategory . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<h1>Our Floor Puzzles</h1>"; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID0#productspage\"><img src=\"images/products/catalogue//$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['$ID'])){ $sql="SELECT ID, Name, Tags, Description, Peices, Size, Barcode, Category FROM products WHERE ID LIKE '%" . $ID . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode $Barcode</p>"; echo "</div>"; } } include("footer.php"); ?>Thank you in advance for any assistance given. Similar TutorialsHi all !
I have a piece of code he
$result = display_all(fcon, $var1, $var2); function display_all( // defined in another file $query = "SELECT one, two, three four, index1, index2 FROM numbers WHERE index1 = $var1 LIMIT 0, 1"; $result = mysqli_query($fcon, $query); return ($result); )and then I use the returned variable $result to display the value as follows:- while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>".$one."</td>"; echo "<td>".$two."</td>"; echo "<td>".$three. "</td>"; echo "<td>".$four. "</td>"; echo "<td>".$index1. "</td>"; echo "</tr>"; }and this displays the n rows of data returned. Now I have started using prepared statements and the function is now function display_all{ $query = "SELECT one, two, three four, index1 FROM numbers WHERE index1 = ? LIMIT 0, 10"; $stmt = $conn->prepare($query); $stmt->bind_param('i',$var) if($stmt->execute()) { $stmt->bind_result($one, $two, $three, $four, $index1); $stmt->store_result(); } return($stmt); }However the returned $stmt object is unable to display the n rows of data since it shows null values. I assume that this is not the right way to use the $stmt object to display data. I must be missing something. So I request you guys to help me with this. Thanks loads. Edited by ajoo, 23 December 2014 - 11:24 AM. Search not functioning. The drop down box to search on Club_Name and Email is blank, clicking search results unchanged ... all suggestions appreciated ... newbie at php. Thanks. <!-- Code below is not functional, trying to query search results, search box with drop down box for two fields--> <table width="50%"> <tr> <td height="30" align="left" bgcolor="#FFFFFF" class="form1" > {$letter_links} </td> <td height="30" align="right" bgcolor="#FFFFFF" class="form1" > <input type=hidden name="sorter" value="{$sorter}"> <table><tr> <form name="search_form" action="{$form.action}" method="post"> <td class="form1" ><input type="text" name="search" value="{$search}"></td> <td class="form1" ><select name="s_type" style=""> {section name=s loop=$types} <option value="{$smarty.section.s.index_next}" {if $types .sel}selected{/if}>{$types .value}</option> {/section} </select></td> <td class="form1"><input type="button" value="{$button.search}" class="button" onclick="javascript: document.search_form.submit();" name="search_submit"></td> </form> </tr></table> </td> </tr> </table> <!-- Code below successfully displays query results --> <form method="post" action="{$file_name}?sel=approve" enctype="multipart/form-data" name="form1" onsubmit="foo(); return false;"> <table cellspacing="2" cellpadding="10" border="1"> <tr align="center"><td>Num</td><td>Club Name</td><td>Login</td><td>Country</td><td>Region</td><td>City</td><td>Address</td><td>Web site</td><td>Email</td><td>Contact Name</td><td>Contact Phone</td><td>Swinging</td><td>Alcohol</td><td>Food</td><td>Entertainment</td><td>Fees</td><td>Approved/<br/>Rejected</td><td>Actions</td></tr> {foreach item=item from=$contest key=key name=foo} <tr align="center"><td><input type="hidden" name="all_approves[{$item.id}]" value="{$item.id}"/>{$key+1}</td><td>{$item.name}</td><td>{$item.login}</td><td>{$item.country_name}</td><td>{$item.region_name}</td><td>{$item.city_name}</td><td>{$item.address}</td><td>{$item.web_site}</td><td>{$item.email}</td><td>{$item.contact_name}</td><td>{$item.contact_phone}</td> <td> {math equation="x - 1" x=$item.swinging assign=index_pos} {$xml_swing[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.alcohol assign=index_pos}{$xml_alco[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.foot assign=index_pos}{$xml_foot[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.entertainment assign=index_pos}{$xml_entertainment[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.fees assign=index_pos}{$xml_fees[$index_pos].value}</td><td> <span> {if $item.is_approved eq '1'} Approved {else} Rejected {/if}</span></td><td align="center"><a href="{$file_name}?sel=edit&id_content={$item.id}">[ Edit ]</a><br/><a href="{$file_name}?sel=delete&id_content={$item.id}">[ Delete ]</a><br/><a href="{$file_name}?sel=approve&id_content={$item.id}">[ Approve ]</a><br/><a href="{$file_name}?sel=reject&id_content={$item.id}">[ Reject ]</a></tr> {/foreach} </table> </form> Need some help finding out why this is returning a null result set:
The below code is giving me a result set of an integer set to "0" (the id), a "word"and "def" both set to NULL. It's failing at my "Error #2" point. var_dumps on $id, $word, and $def all give the null output. Each $category is being shown when I var_dump($category).
I know this shouldn't be the case because when I run this straight in PHPMyAdmin I get a non-null result set.
(Not sure why my indentation is not carrying over to the forum. Sorry about that.)
<?php session_start(); if(!isset($_SESSION['loopcatch']) || $_SESSION['loopcatch']==null || !is_int($_SESSION['loopcatch'])){ $_SESSION['loopcatch']=0; } if($_SESSION['loopCatch'] > 1){ //Email error die(); } require 'dbConnect.php'; $categories=array('business', 'music', 'film', 'drum'); //Pull Quotes //Query to Pull random quote $mainQuery="SELECT `r1`.`id`, `r1`.`word`, `r1`.`def` FROM `dictionary` AS `r1` JOIN (SELECT (RAND() * (SELECT MAX(`id`) FROM `dictionary`)) AS `id`) AS `r2` WHERE `r1`.`id` >= `r2`.`id` AND `category`=? AND `checked`=0 ORDER BY `r1`.`id` ASC LIMIT 1"; //prepare quotes query if($prepareQuote=mysqli_prepare($conn, $mainQuery)){ //filter through each category foreach($categories as $category){ //Bind the variable to the quotes query mysqli_stmt_bind_param($prepareQuote, "s", $category); //execute quotes statement mysqli_stmt_execute($prepareQuote); //Store quotes result set mysqli_stmt_store_result($prepareQuote); //Check how many rows are returned if(mysqli_stmt_num_rows($prepareQuote) > 0){ //Bind results to variables mysqli_stmt_bind_result($prepareQuote, $id, $word, $def); //If $id, $word, or $def is null abort and email error if(!is_null($id) && is_numeric($id) && !is_null($word) && !is_null($def)){ while($row=mysqli_stmt_fetch($prepareQuote)){ mysqli_autocommit($conn, FALSE); //Input into second table $updateQuery="UPDATE `quotes` SET `word`=?, `def`=? WHERE `category`=?"; //prepare insert query if($updateQuote=mysqli_prepare($conn, $updateQuery)){ //Bind the variables to the insert query mysqli_stmt_bind_param($updateQuote, "sss", $word, $def, $category); //execute insert statement mysqli_stmt_execute($updateQuote); //Store insert quote result set mysqli_stmt_store_result($updateQuote); //Check how many rows are returned on insert quote query if(mysqli_stmt_affected_rows($updateQuote) > 0){ //If query run sucessfully insert and update; if not rollback. //mark quote checked $checkedQuery="UPDATE `dictionary` SET `checked`=1 WHERE `id`=?"; //prepare checked query if($checkedQuote=mysqli_prepare($conn, $checkedQuery)){ mysqli_stmt_bind_param($checkedQuote, "i", $id); //execute checked statement mysqli_stmt_execute($checkedQuote); //Store checked quote result set mysqli_stmt_store_result($checkedQuote); //Check how many rows are returned on checked quote query if(mysqli_stmt_affected_rows($checkedQuote > 0)){ mysqli_commit($conn); } else{ echo 'Error #6 '; mysqli_rollback($conn); } } else{ echo 'Error #5'; //Email error die(); } } else{ echo 'Error #4'; mysqli_rollback($conn); } } else{ echo 'Error #3'; //Email error die(); } } } else{ echo 'Error #2'; //Query returned blank result set - Email Error } } else{ //If zero rows returned, uncheck rows in table for that specific category and re-run the query. $uncheckQuery="UPDATE `dictionary` SET `checked`=0 WHERE `category`=?"; if($uncheckQuotes=mysqli_prepare($conn, $uncheckQuery)){ //Bind the variable to the query mysqli_stmt_bind_param($uncheckQuotes, "s", $category); //execute statement mysqli_stmt_execute($uncheckQuotes); //Store result set mysqli_stmt_store_result($uncheckQuotes); //Check how many rows are returned if(mysqli_stmt_affected_rows($uncheckQuotes) > 0){ $_SESSION['loopCatch']++; header("Location: ./pullDailyQuotes.php"); } else{ //Email error } } } } } else{ //Email error echo 'Error #1'; die(); } ?> Edited by HDRebel88, 01 June 2014 - 08:54 PM. friend the code display all the managers name
<?phpand the variable below displays the result $Manager= $row['Manager'] ; but how do i do it on the above dropdown list the it shows which result is in the $Manager variable? I am looking to accomplish the following but have been hitting a brick wall: * User enters a single keyword into a text field, and conducts a search keyword search. * The results are pulled from the campusbooks.com API(API docs attached) * result are then output in <div> class and includes all the book details and its corresponding url./img etc I'm trying to simplify this process but I continue to receive syntax errors. A step by step practical explanation would do me justice! Hello all, I'm writing a page with a simple database with a table called recipes in it with a series of recipes (go figure). I want to display a list of the recipe titles in ascending alphabetical order with each title linked to another page that displays all of the information about the recipe. I can't seem to get anything to display though (not even the titles) but I'm not getting any errors returned either. It seems as if there is nothing in the table to display (even though there are 40 records there). Any help would be greatly appreciated. Here is the code I have so far: Code: [Select] <?php $dbhost = 'localhost'; $dbuser = '*****'; $dbpass = '*****'; $dbname = '*******'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to database'); mysql_select_db($dbname) or die('Error selecting the database'); // select data from db to use $result = mysql_query("SELECT * FROM recipes ORDER BY title ASC LIMIT 0,50") or die('mysql_error()'.'Error: ' .mysql_errno() ); //display the data while($row = mysql_fetch_array($result)); { echo"<b><center>Healthy Lifestyle Gourmet Recipes</center></b><br /><br />"; echo "<span class=\"recipelink\"><a href=\"reciperesults.php?id=".$row['id']."\" target=\"_blank\">".$row['title']."</a></span><br/>\n"; } mysql_close(); ?> I starred out the connection variables but, they are all correct in my code (I'm not getting the "or die" errors) Hello, I am quite new in PHP. I am doing a page with list of events (seminars). The events are saved in a XML file in chronological order and their each event has its date in d-m-Y format and time in h:m format. What I need to do is find the next event (with respect to the actual date and time). I can do it using a loop (foreach) and stringtotime() and comparing obtained values. However, this seems to be quite a clumsy way. Is there any better way to do it? Maybe there is a function, package or some extension, which I don't know... I tried xpath, however it does not know how to compare the dates (I use xml 1.0). Thank you very much. $save_planet3 = "SELECT saver_id FROM save_planet WHERE saver_id = '".($_SESSION['user_id'])."' AND map = 1 ORDER BY time_saved DESC"; $save_planet2 = mysql_query($save_planet3) or trigger_error("SQL", E_USER_ERROR); while ($list = mysql_fetch_array($save_planet2)) { $saver_id = $list['saver_id']; When I echo $saver_id im getting a list of numbers 3112 3112 3112 3112 im trying to do a check if $planet_id is equal to any of these numbers So i figure the only way to do this is to put these numbers in a array with keys first. So I tried to explode it but it doesnt give each one a differant key I noticed. $check = explode(",", $saver_id); print_r($check); Array ( [0] => 3112 ) Array ( [0] => 3112 ) Array ( [0] => 3112 ) Array ( [0] => 3112 ) Once i get this in a workable array i should beable to do this right foreach($array as $key => $value) { if ($planet_id == $value) { //something happends Hello there, I am pretty new to php and I was wondering if anyone can give me some input. Basically I am creating a search engine where I can search for words in certain files. I am trying to search using two or more words for instance a file may have the sentence 'the cat ran across the road', and another file has 'the road is long'. I would like to search 'cat road', and have these two files show up with each word highlighted. At the moment 'cat road' is being searched as just one string. I have exploded the keyword, and i have broken the array into separate words but for some reason it is still not searching. Again I would appreciate any feedback. Just to show you a bit of my code to explain: if(!empty($_GET['keyword'])) { $user_input = trim($_GET['keyword']); $user_input = preg_replace("/ {2,}/", " ",$user_input); $keyword = explode(" ", $user_input); for($i=0;$i<count($keyword);$i++) { echo("$keyword[$i]\n"); } $keyword = $_GET['keyword']; } Thanks for your time, Farha I have a search page and everything works fine but I would like to add the latest 10 rows to the page so there is something to look at or click on before the user searches. The page is at: www.giantstridedives.com/locations. You can see that it's pretty boring. Hit submit and you'll see the entries so far (only 3 right now). I'd like to have the latest 10 display there by default but then when a user searches they are replaced by the search results. Make sense? Here's the code I'm using for the search: Code: [Select] <?php if (isset($_POST['submit'])) { require_once('dbconnection.php'); mysqli_select_db($conn, $dbname); $searchterm = $_POST['search']; $searchterm = strip_tags($searchterm); $searchterm = trim ($searchterm); $q ="SELECT * FROM locations WHERE loc_name LIKE '%" . $searchterm . "%' AND loc_approved != '0'"; $r = mysqli_query($conn, $q) or die(mysql_error($q)); $row = mysqli_fetch_assoc($r); $rowcount = mysqli_num_rows($r); } ?> <h1>Search for Scuba Dive Locations</h1> <form id="searchform" name="searchform" method="post" action="index.php"> <input type="text" name="search" id="search_bar" /> <input type="submit" name="submit" id="submit" value="Submit" /> </form> <span style="color: #333;">Search for the name of the location, ie: Devils Den or USS Oriskany.</span><br /> <?php if (isset($_POST['submit'])) { if ($rowcount == 0) { echo "Sorry, but we can not find an entry to match your query: <strong>$searchterm</strong>"; } else { //this tells the table below to display since $totalRows_Products_res is not 0 ?> <table style="font-size: 14px;" border="0" width="650"> <tr> <td colspan="6"><p>You searched for <strong><?php echo $searchterm; ?></strong>. Results are displayed below.</p></td> </tr> <tr> <td><strong>Location Name</strong></td> <td><strong>City</strong></td> <td><strong>State</strong></td> <td><strong>Depth (ft)</strong></td> <td><strong>Fees</strong></td> <td><strong>Gear Rentals</strong></td> <td><strong>Map</strong></td> </tr> <?php do { ?> <tr> <td><a href="loc_details.php?loc_id=<?php echo $row ['loc_id']; ?>"> <?php echo $row ['loc_name']; ?> </a></td> <td><?php echo $row ['loc_city']; ?></td> <td><?php echo $row ['loc_state']; ?></td> <td><?php echo $row ['loc_depth']; ?></td> <td>$<?php echo $row ['loc_fee']; ?></td> <td><?php if($row['loc_gear'] == 1) { echo 'Yes'; } else { echo 'No'; } ?></td> <td><a href="http://maps.google.com/maps?q=<?php echo $row ['loc_lat'];?>,<?php echo $row ['loc_lon'];?>" target="_blank">View Map</a></td> </tr> <?php } while ($row = mysqli_fetch_assoc($r)); ?> </table> <?php mysqli_free_result($r); } // this closes out results else } ?> I figure I can use the below query to get the results. Code: [Select] select * from table WHERE id > ((SELECT MAX(id) from table) - 10);I'm just not sure how I can display them by default and then have them be replaced by the search results. Anyone have any ideas for me? As always I appreciate the help as I continue to learn this beast. Hi all.
how can i make the values show like a list. I tried html line break "<br>" and php \n but all to no avail. It just show all the values in one straigth line.
example of what i want is for the values to appear like this:
1234567890
0987654345
4567890675
instead of :
1234567890 0987654345 4567890675
Thanks
<form data-abide method="post" action=""> <div> <select name=""> <option value="name"> <?php $stmt = $pdo->query("SELECT acct_num FROM table order by id desc"); while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) { echo $row['acct_num']; } ?> </option> </select> </div> <div> <label>New Password <small>required</small></label> <input type="password" name="password" id="password" required> <small class="error">New password is required and must be a string.</small> </div> <div> <label>Confirm New Password <small>required</small></label> <input type="password" name="password2" id="password2" required> <small class="error">Password must match.</small> </div> <input name="submit" type="submit" class="button small" value="Change Password"> </form> Edited by Mr-Chidi, 13 November 2014 - 01:34 AM. i have the following code: <td width='100px'>Suppliers <select name="supplier"> <?php $catcher_id = $service->getCatcherId(); $supplier_names = LpmAdnetworkPeer::getByName($catcher_id); foreach($supplier_names as $row) { ?> <option><?php echo $row->getName(); ?></option> <?php } ?> </select> </td> then on the same form i have a submit button that takes me to the next form..the problem now is how can i access the ID of the item seleted in the dropdown on the NEXT form please? i can get the name from the list by $_POST['supplier'] on the next form thanks Hi first tyvm for reading my help request me and my friend ar trying to build a order form (see png file ^^) so the main idea is some on go to order form.php
in that order form they fil in thear info like name, adress you know ^^
thean here is the treaky part at the and of the form they kan add products to there order by selecting it or search it from the drop down list the items in the dropdown list come from msql
the client can add more or delete items by clicking - or + whean the clint click send the client need to get a mail whit there a list of what theay have orderd and there unic order number wel so far we can do that but we wont to send another list to the company of order where the added products in the order ar sorted out based on the product id number
this is what we have so far http://clientconstru...sion.nl/valeri/
tyvm again voor anyone who read this ^^
Attached Files
bestel-form.png 37.78KB
0 downloads i skipped solving this the other day with an easier way but now i am stuck with this stumble again in another area and i have no way out.... so here it goes, i have an ajax dropdown box...i need to get the value that is selected by the user when it is clicked and then pass this value to a new pop window by appending to its url....any suggestions? I'm pulling data from an xml file and I'm getting a lot of duplicates. How can I remove the duplicates from the query? Code: [Select] foreach($xml->category->subcategory as $category){ echo $category[id]; }//end foreach I have a form that contains 3 text fields and 7 populated lists (that are dependent on the choice of the previous lists). When I post the information to MySQL and to my processing page, it posts the table "ids" instead of the selected option. Here's the php code for the form: <form action="gccsuccess_form.php" method="post" enctype="multipart/form-data" name="gcc" id="gcc"> <table width="700" border="0" align="center" cellpadding="3" cellspacing="3"> <tr> <td><label for="date">Today's Date:</label> <input type="text" name="date" id="date"></td> <td> </td> </tr> <tr> <td>Week Number: <select name="week" size="1" id="week"> <option value="0" selected>Week 0 - 3/26 - 4/1</option> <option value="1">Week 1 - 4/2 - 4/8</option> <option value="2">Week 2 - 4/9 - 4/15</option> <option value="3">Week 3 - 4/16 - 4/22</option> <option value="4">Week 4 - 4/23 - 4/29</option> <option value="5">Week 5 - 4/30 - 5/6</option> <option value="6">Week 6 - 5/7 - 5/13</option> </select></td> <td><label for="location"></label> </td> </tr> <tr> <td>Location: <select id='locations' name='location'> </select></td> <td> </td> </tr> <tr> <td><label for="label8">Team Name</label> <select id='team_names' name='team_name'> </select></td> <td> </td> </tr> <tr> <td><em>*Please enter each team member's first and last name:</em></td> <td> </td> </tr> <tr> <td><label for="mem_1"> Team <strong>Captain:</strong></label> <select id='team_members 1' name='capt'> </select></td> <td><label for="label4"><strong>Steps:</strong></label> <input type="text" name="steps_1" id="steps_1"></td> </tr> <tr> <td><label for="mem_2">Team Member #2 <strong>Name: <select id='team_members 2' name='mem_2'> </select> </strong></label></td> <td><label for="label5"><strong>Steps:</strong></label> <input type="text" name="steps_2" id="steps_2"></td> </tr> <tr> <td><label for="mem_3">Team Member #3 <strong>Name: <select id='team_members 3' name='mem_3'> </select> </strong></label></td> <td><label for="label6"><strong>Steps:</strong></label> <input type="text" name="steps_3" id="steps_3"></td> </tr> <tr> <td><label for="mem_4">Team Member #4<strong> Name</strong>: <select id='team_members 4' name='mem_4'> </select> </label></td> <td><label for="label7"><strong>Steps:</strong></label> <input type="text" name="steps_4" id="steps_4"></td> </tr> <tr> <td><label for="label">Team Member #5<strong> Name</strong>: <select id='team_members 5' name='mem_5'> </select> </label></td> <td><label for="label7"><strong>Steps:</strong></label> <input type="text" name="steps_5" id="steps_5"></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><em>* Maximum steps for each team member per week is <strong>105,000. </strong></em></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit Form" id="Submit Form" value="Submit"></td> </tr> </table> <label></label> <div align="center"><br> If you have questions about the competition or reporting please contact KC WELLNESS, INC toll free at <SPAN id="lw_1237248942_0">877-634-1412.</SPAN><br> <br> </div> </form> And here's the code for the page it is posted in: <?php $date = $_POST['date']; $week = $_POST['week']; $location = $_POST['location']; $team_name = $_POST['team_name']; $capt = $_POST['capt']; $mem_2 = $_POST['mem_2']; $mem_3 = $_POST['mem_3']; $mem_4 = $_POST['mem_4']; $mem_5 = $_POST['mem_5']; $steps_1= $_POST['steps_1']; $steps_2= $_POST['steps_2']; $steps_3= $_POST['steps_3']; $steps_4 = $_POST['steps_4']; $steps_5 = $_POST['steps_5']; mysql_connect("mysql1.myregisteredsite.com", "49200_kandace", "Leonardo56") or die(mysql_error()); mysql_select_db("49200_GCC") or die(mysql_error()); mysql_query("INSERT INTO `walkathon` VALUES ('$date', '$week', '$location', '$team_name', '$capt','$mem_2','$mem_3', '$mem_4', '$mem_5', '$steps_1','$steps_2', '$steps_3','$steps_4', '$steps_5' )"); Print "Thank you for your entry. <br> Report summary: <br/><br/>"; echo "<strong> Date: </strong> {$date} <br/> <br/><strong> Week: </strong> {$week} <br/> <br/><strong> Location: </strong> {$location} <br/> <br/><strong> Team Name: </strong> {$team_name} <br/> <br/><strong> Team Captain: </strong> {$capt} / <strong> Steps: </strong> {$steps_1} <br /> <br/><strong> Team Member 2 Name: </strong> {$mem_2} / <strong> Steps: </strong> {$steps_2} <br /> <br/><strong> Team Member 3 Name: </strong> {$mem_3} / <strong> Steps: </strong> {$steps_3} <br /> <br/><strong> Team Member 4 Name: </strong> {$mem_4} / <strong> Steps: </strong> {$steps_4} <br /> <br/><strong> Team Member 5 Name: </strong> {$mem_5} / <strong> Steps: </strong> {$steps_5}" ?> How do I get the processing page to echo the selected option instead of the id? Hi everyone, I am having trouble passing/displaying the values inside of a selected list. I created a add/remove list using Jquery and I tried to display the values passed using foreach and for loops but it is still not working. The values I am trying to get are $existing_mID[$j], which is inside of the option value attribute. Please kindly let me know what should I do in order to get the values and I really appreciate your help. <?php $selected = $_POST['selectto']; if(isset($selected)) { echo "something in selected<br />"; for ($i=0;$i<count($selected);$i++) echo "selected #1 : $selected[$i]"; foreach ($selected as $item) echo "selected: item: $item"; } ?>This is the form Hi all,
I am trying to validate all required fields in my contact form using php. However I am unable to retain what was selected in my country dropdown list after it is selected and submitted if the form had errror while validating. I want the form to retain the value that was selected by the user to stay in the form so that users can make necessary changes and resubmit the form all other values stay in the form except the country dropdown. Please help Below is the code. <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php // define variables and set to empty values $nameErr = $emailErr = $genderErr = $websiteErr = $countryErr = ""; $name = $email = $gender = $comment = $website = ""; $country =""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address syntax is valid if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { $emailErr = "Invalid email format"; } } if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["gender"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["gender"]); } $country = $_POST['country']; if (!in_array($country, array("AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "Gg", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "SH", "KN", "LC", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "CS", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "GS", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW" ))) { $country1 = "Please select your country";} } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>contact us</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name: <input type="text" name="name" value="<?php echo $name;?>"> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span> <br><br> <legend>Country:</legend> <select name="country"> <option value="NULL">select</option> <option value="AF">Afghanistan</option> <option value="AX">Ã…Land Islands</option> <option value="AL">Albania</option> <option value="DZ">Algeria</option> <option value="AS">American Samoa</option> <option value="AD">Andorra</option> <option value="AO">Angola</option> <option value="AI">Anguilla</option> <option value="AQ">Antarctica</option> <option value="AG">Antigua And Barbuda</option> <option value="AR">Argentina</option> <option value="AM">Armenia</option> <option value="AW">Aruba</option> <option value="AU">Australia</option> <option value="AT">Austria</option> <option value="AZ">Azerbaijan</option> <option value="BS">Bahamas</option> <option value="BH">Bahrain</option> <option value="BD">Bangladesh</option> <option value="BB">Barbados</option> <option value="BY">Belarus</option> <option value="BE">Belgium</option> <option value="BZ">Belize</option> <option value="BJ">Benin</option> <option value="BM">Bermuda</option> <option value="BT">Bhutan</option> <option value="BO">Bolivia</option> <option value="BA">Bosnia And Herzegovina</option> <option value="BW">Botswana</option> <option value="BV">Bouvet Island</option> <option value="BR">Brazil</option> <option value="IO">British Indian Ocean Territory</option> <option value="BN">Brunei Darussalam</option> <option value="BG">Bulgaria</option> <option value="BF">Burkina Faso</option> <option value="BI">Burundi</option> <option value="KH">Cambodia</option> <option value="CM">Cameroon</option> <option value="CA">Canada</option> <option value="CV">Cape Verde</option> <option value="KY">Cayman Islands</option> <option value="CF">Central African Republic</option> <option value="TD">Chad</option> <option value="CL">Chile</option> <option value="CN">China</option> <option value="CX">Christmas Island</option> <option value="CC">Cocos (Keeling) Islands</option> <option value="CO">Colombia</option> <option value="KM">Comoros</option> <option value="CG">Congo</option> <option value="CD">Congo, The Democratic Republic Of The</option> <option value="CK">Cook Islands</option> <option value="CR">Costa Rica</option> <option value="CI">Cote D'Ivoire</option> <option value="HR">Croatia</option> <option value="CU">Cuba</option> <option value="CY">Cyprus</option> <option value="CZ">Czech Republic</option> <option value="DK">Denmark</option> <option value="DJ">Djibouti</option> <option value="DM">Dominica</option> <option value="DO">Dominican Republic</option> <option value="EC">Ecuador</option> <option value="EG">Egypt</option> <option value="SV">El Salvador</option> <option value="GQ">Equatorial Guinea</option> <option value="ER">Eritrea</option> <option value="EE">Estonia</option> <option value="ET">Ethiopia</option> <option value="FK">Falkland Islands (Malvinas)</option> <option value="FO">Faroe Islands</option> <option value="FJ">Fiji</option> <option value="FI">Finland</option> <option value="FR">France</option> <option value="GF">French Guiana</option> <option value="PF">French Polynesia</option> <option value="TF">French Southern Territories</option> <option value="GA">Gabon</option> <option value="GM">Gambia</option> <option value="GE">Georgia</option> <option value="DE">Germany</option> <option value="GH">Ghana</option> <option value="GI">Gibraltar</option> <option value="GR">Greece</option> <option value="GL">Greenland</option> <option value="GD">Grenada</option> <option value="GP">Guadeloupe</option> <option value="GU">Guam</option> <option value="GT">Guatemala</option> <option value="Gg">Guernsey</option> <option value="GN">Guinea</option> <option value="GW">Guinea-Bissau</option> <option value="GY">Guyana</option> <option value="HT">Haiti</option> <option value="HM">Heard Island And Mcdonald Islands</option> <option value="VA">Holy See (Vatican City State)</option> <option value="HN">Honduras</option> <option value="HK">Hong Kong</option> <option value="HU">Hungary</option> <option value="IS">Iceland</option> <option value="IN">India</option> <option value="ID">Indonesia</option> <option value="IR">Iran, Islamic Republic Of</option> <option value="IQ">Iraq</option> <option value="IE">Ireland</option> <option value="IM">Isle Of Man</option> <option value="IL">Israel</option> <option value="IT">Italy</option> <option value="JM">Jamaica</option> <option value="JP">Japan</option> <option value="JE">Jersey</option> <option value="JO">Jordan</option> <option value="KZ">Kazakhstan</option> <option value="KE">Kenya</option> <option value="KI">Kiribati</option> <option value="KP">Korea, Democratic People'S Republic Of</option> <option value="KR">Korea, Republic Of</option> <option value="KW">Kuwait</option> <option value="KG">Kyrgyzstan</option> <option value="LA">Lao People'S Democratic Republic</option> <option value="LV">Latvia</option> <option value="LB">Lebanon</option> <option value="LS">Lesotho</option> <option value="LR">Liberia</option> <option value="LY">Libyan Arab Jamahiriya</option> <option value="LI">Liechtenstein</option> <option value="LT">Lithuania</option> <option value="LU">Luxembourg</option> <option value="MO">Macao</option> <option value="MK">Macedonia, The Former Yugoslav Republic Of</option> <option value="MG">Madagascar</option> <option value="MW">Malawi</option> <option value="MY">Malaysia</option> <option value="MV">Maldives</option> <option value="ML">Mali</option> <option value="MT">Malta</option> <option value="MH">Marshall Islands</option> <option value="MQ">Martinique</option> <option value="MR">Mauritania</option> <option value="MU">Mauritius</option> <option value="YT">Mayotte</option> <option value="MX">Mexico</option> <option value="FM">Micronesia, Federated States Of</option> <option value="MD">Moldova, Republic Of</option> <option value="MC">Monaco</option> <option value="MN">Mongolia</option> <option value="MS">Montserrat</option> <option value="MA">Morocco</option> <option value="MZ">Mozambique</option> <option value="MM">Myanmar</option> <option value="NA">Namibia</option> <option value="NR">Nauru</option> <option value="NP">Nepal</option> <option value="NL">Netherlands</option> <option value="AN">Netherlands Antilles</option> <option value="NC">New Caledonia</option> <option value="NZ">New Zealand</option> <option value="NI">Nicaragua</option> <option value="NE">Niger</option> <option value="NG">Nigeria</option> <option value="NU">Niue</option> <option value="NF">Norfolk Island</option> <option value="MP">Northern Mariana Islands</option> <option value="NO">Norway</option> <option value="OM">Oman</option> <option value="PK">Pakistan</option> <option value="PW">Palau</option> <option value="PS">Palestinian Territory, Occupied</option> <option value="PA">Panama</option> <option value="PG">Papua New Guinea</option> <option value="PY">Paraguay</option> <option value="PE">Peru</option> <option value="PH">Philippines</option> <option value="PN">Pitcairn</option> <option value="PL">Poland</option> <option value="PT">Portugal</option> <option value="PR">Puerto Rico</option> <option value="QA">Qatar</option> <option value="RE">Reunion</option> <option value="RO">Romania</option> <option value="RU">Russian Federation</option> <option value="RW">Rwanda</option> <option value="SH">Saint Helena</option> <option value="KN">Saint Kitts And Nevis</option> <option value="LC">Saint Lucia</option> <option value="PM">Saint Pierre And Miquelon</option> <option value="VC">Saint Vincent And The Grenadines</option> <option value="WS">Samoa</option> <option value="SM">San Marino</option> <option value="ST">Sao Tome And Principe</option> <option value="SA">Saudi Arabia</option> <option value="SN">Senegal</option> <option value="CS">Serbia And Montenegro</option> <option value="SC">Seychelles</option> <option value="SL">Sierra Leone</option> <option value="SG">Singapore</option> <option value="SK">Slovakia</option> <option value="SI">Slovenia</option> <option value="SB">Solomon Islands</option> <option value="SO">Somalia</option> <option value="ZA">South Africa</option> <option value="GS">South Georgia And The South Sandwich Islands</option> <option value="ES">Spain</option> <option value="LK">Sri Lanka</option> <option value="SD">Sudan</option> <option value="SR">Suriname</option> <option value="SJ">Svalbard And Jan Mayen</option> <option value="SZ">Swaziland</option> <option value="SE">Sweden</option> <option value="CH">Switzerland</option> <option value="SY">Syrian Arab Republic</option> <option value="TW">Taiwan, Province Of China</option> <option value="TJ">Tajikistan</option> <option value="TZ">Tanzania, United Republic Of</option> <option value="TH">Thailand</option> <option value="TL">Timor-Leste</option> <option value="TG">Togo</option> <option value="TK">Tokelau</option> <option value="TO">Tonga</option> <option value="TT">Trinidad And Tobago</option> <option value="TN">Tunisia</option> <option value="TR">Turkey</option> <option value="TM">Turkmenistan</option> <option value="TC">Turks And Caicos Islands</option> <option value="TV">Tuvalu</option> <option value="UG">Uganda</option> <option value="UA">Ukraine</option> <option value="AE">United Arab Emirates</option> <option value="GB">United Kingdom</option> <option value="US">United States</option> <option value="UM">United States Minor Outlying Islands</option> <option value="UY">Uruguay</option> <option value="UZ">Uzbekistan</option> <option value="VU">Vanuatu</option> <option value="VE">Venezuela</option> <option value="VN">Viet Nam</option> <option value="VG">Virgin Islands, British</option> <option value="VI">Virgin Islands, U.S.</option> <option value="WF">Wallis And Futuna</option> <option value="EH">Western Sahara</option> <option value="YE">Yemen</option> <option value="ZM">Zambia</option> <option value="ZW">Zimbabwe</option> </select> <span class="error">*<?php echo $country1;?></span> <br><br> Website: <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr;?></span> <br><br> Gender: <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male <span class="error">* <?php echo $genderErr;?></span> <br><br> Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br><br> <input type="submit" name="submit" value="Submit"> </form> </body> </html> Edited by Ch0cu3r, 15 July 2014 - 03:37 PM. Reformatted post Hey Everyone... First off, I am only a young web developer and i'm working on a school project and am making a text-based game online... Now what i'm having trouble with... I want a drop-down list that has a list of characters classes Clubber Mixer Sauceror Tamer And I want whatever is selected to be placed into the database along with the username/password (THIS ALL WORKS FINE JUST NOT THE DROP DOWN LIST) All help appreciated Yesterday, I created a topic about how I could update records and I managed to achieve that successfully. Now I have another dilemma. When I have a specific record I want to update, I want to change a category ID of an product (e.g. change it from 1 to 2) but how do I go about doing this? Here is my code thus far: Code: [Select] <?php require_once ('./includes/config.inc.php'); require_once (MYSQL); $id=$_GET['prodID']; $results = mysqli_query($dbc, "SELECT * FROM product WHERE prodID=".$_GET['prodID'].""); $row = mysqli_fetch_assoc($results); ?> <form action="" method='POST'> Product ID: <input type="text" value="<?php echo $row['prodID'];?>" name="prodID" /> <br /> Product: <input type="text" value="<?php echo $row['product'] ;?>" name="product" /> <br /> Product Description: <input type="text" value="<?php echo $row['prod_descr'] ;?>" name="prod_descr" /> <br /> Category: <select name="category"> <option value="<?php echo $row['catID'];?>"></option> </select> Price: <input type="text" value="<?php echo $row['price'] ;?>" name="price" /> <br /> In Stock: <input type="text" value="<?php echo $row['stock'] ;?>" name="stock" /> <br /> <br /><input type="submit" value="save" name="save"> </form> <?php if(isset($_POST['save'])) { $id = $_POST['prodID']; $product = $_POST['product']; $descr = $_POST['prod_descr']; $price = $_POST['price']; $stock = $_POST['stock']; // Update data $update = mysqli_query($dbc, "UPDATE product SET product='$product', prod_descr='$descr', price='$price', stock='$stock' WHERE prodID=".$_GET['prodID'].""); header( 'Location: update_save.php' ) ; } ?> |