PHP - Sql Search Functionality
Hi gents,
This will be an easy one for you all! I have a sql select statement and everything functions fine as is, BUT I would like to give users more freedom. Using this sql statement the results only return if the user types the Botanical Name or Common Name of a particular plant exactly as it is spelled in the database: $sql = mysql_query("SELECT PlantID, CommonName FROM plants WHERE BotanicalName='$BotanicalName' OR CommonName='$CommonName' OR Use1='$Use' OR Use2='$Use' OR Use3='$Use' OR Use4='$Use' OR Use5='$Use' ORDER BY CommonName"); What if the user doesn't know the species of a plant and only it's genus or the user only knows Maple tree and not which particular one they are looking for: For example: Plant in Database = Brandywine Red Maple User Search would have to be exactly that "Brandywine Red Maple" for a result to return Ideally I would like the user to be able to type in "Maple" and ALL Maples return Let me know if you need more info Similar TutorialsThe result pages is supposed to have pagination like google help me please
I am a newbie trying to build a quiz system. I have all of the questions and answer choices in a mysql table. My code below selects the question and answers. They appear exactly how I want them to....but I'm stuck on the form functionality. I was trying to use something like this: Code: [Select] <input type='radio' name='Q1Choice' value='$answer1' /> I need to be able to insert the choice into my table. I know how to do the insert part but not sure how to take the radio choice as the insert data. Code: [Select] <? //Connect to database mysql_connect($host, $dbusername, $password); mysql_select_db($TxQuizdb); //Retrieve Quiz Questions $qquery = mysql_query("SELECT * FROM Module_1_Quiz"); while ($m1questions = mysql_fetch_array($qquery)) { echo "<table width=600 border=1><tr><td>"; echo $m1questions['Question']; echo "</td></tr><br><tr><td>"; echo $m1questions['Choice1']; echo "<br>"; echo $m1questions['Choice2']; echo "<br>"; echo $m1questions['Choice3']; echo "</td></tr></table>"; } thanks for any help. hello, I am running php locally on my machine but it seems that when I try to call mail () function, I get error messages. I believe that I need to set up a mail server on my machine. Is that an accurate statement? whats the easiest way to do this? Is having OUTLOOK installed on the machine sufficient? I am working on a REST application which is intended to be used with various CMS’s (Drupal, WordPress, etc). Each CMS installation passes a unique GUID in the header to identify the organization so that the organization's individual data is utilized. I’ve since realized I need some basic way to identify the individual user for at least two reasons: The API provides a help desk where individual users can ask questions and get responses (not real time). There is some need for user access/privileges (I suppose this could be CMS side if necessary).Instead of inputting users both into the API as well as the CMS, the organization should be responsible for entry only through the CMS. They will add users as appropriate for the given CMS and then another page on the CMS will list all the CMS users and provide a way to set whether they are authorized to access the API as well as their access level. The remaining of this post is kind of what I am thinking, but I am open to change. When the CMS gives a user access to the API for the first time, a cURL request is made to the API and a unique key is returned and the CMS will save it as being associated with the given user. Note sure if this should be an incrementing number on a per organization basis or another GUID, and if a GUID whether it should be passed along with the organization’s GUID or replace it. Also, not positive, but thinking that user data (name, email, etc) should not be given to the API as it might be difficult to keep them synchronized. If a user’s access level is changed on the CMS or their access is removed, the user’s GUID is passed to the API and the work is done on the API. If the user is removed, they are not deleted from the API’s database but just tagged as deleted. Before performing step 1, the CMS should first perform a query requesting all users who are tagged as deleted and is responsible to determine whether a new user should be added or an existing user should be reinstated. Alternatively, I can make the API responsible for doing so, but then it would need to have stored various data to identify whether the user was previously instated which might result in the synchronization issue I described in step 1.Any comments, potential pitfalls, or recommendations would be appreciated. My code about filterable audio searching, here how can i add Add-To-Cart functionality?
code : <?php //index.php include('database_connection.php'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <title>Voice Repository</title> <script src="js/jquery-1.10.2.min.js"></script> <script src="js/jquery-ui.js"></script> <script src="js/bootstrap.min.js"></script> <link rel="stylesheet" href="css/bootstrap.min.css"> <link href = "css/jquery-ui.css" rel = "stylesheet"> <!-- Custom CSS --> <link href="css/style.css" rel="stylesheet"> </head> <body> <!-- Page Content --> <div class="container"> <div class="row"> <br /> <div class="col-md-12"> <h2 align="center">Voice Repository Bank</h2> </div> <div class="col-md-3"> <!-- Price --> <!-- <div class="list-group"> <h3>Price</h3> <input type="hidden" id="hidden_minimum_price" value="0" /> <input type="hidden" id="hidden_maximum_price" value="65000" /> <p id="price_show">1000 - 65000</p> <div id="price_range"></div> </div> --> <!-- Languages --> <div class="list-group"> <h3>Languages</h3> <?php $query = " SELECT DISTINCT(voice_languages) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_languages DESC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector languages" value="<?php echo $row['voice_languages']; ?>" > <?php echo $row['voice_languages']; ?> </label> </div> <?php } ?> </div> <!-- Genres --> <div class="list-group"> <h3>Genres</h3> <?php $query = " SELECT DISTINCT(voice_genres) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_genres DESC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector genres" value="<?php echo $row['voice_genres']; ?>" > <?php echo $row['voice_genres']; ?> </label> </div> <?php } ?> </div> <!-- Voice Modulation --> <div class="list-group"> <h3>Voice Modulation</h3> <?php $query = " SELECT DISTINCT(voice_voice_modulation) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_voice_modulation DESC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector voice_modulation" value="<?php echo $row['voice_voice_modulation']; ?>" > <?php echo $row['voice_voice_modulation']; ?> </label> </div> <?php } ?> </div> <!-- Gender --> <div class="list-group"> <h3>Gender</h3> <div style="height: 180px; overflow-y: auto; overflow-x: hidden;"> <?php $query = "SELECT DISTINCT(voice_gender) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_id DESC"; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector gender" value="<?php echo $row['voice_gender']; ?>" > <?php echo $row['voice_gender']; ?></label> </div> <?php } ?> </div> </div> <!-- Jingle Moods --> <div class="list-group"> <h3>Jingle Moods</h3> <?php $query = " SELECT DISTINCT(voice_jingle_moods) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_jingle_moods DESC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector jingle_moods" value="<?php echo $row['voice_jingle_moods']; ?>" > <?php echo $row['voice_jingle_moods']; ?> </label> </div> <?php } ?> </div> <!-- IVR --> <div class="list-group"> <h3>Ivr</h3> <?php $query = " SELECT DISTINCT(voice_ivr) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_ivr DESC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector ivr" value="<?php echo $row['voice_ivr']; ?>" > <?php echo $row['voice_ivr']; ?> </label> </div> <?php } ?> </div> </div> <div class="col-md-9"> <br /> <div class="row filter_data"> </div> </div> </div> </div> <style> #loading { text-align:center; background: url('loader.gif') no-repeat center; height: 150px; } </style> <script> $(document).ready(function(){ filter_data(); function filter_data() { $('.filter_data').html('<div id="loading" style="" ></div>'); var action = 'fetch_data'; // var minimum_price = $('#hidden_minimum_price').val(); // var maximum_price = $('#hidden_maximum_price').val(); var gender = get_filter('gender'); var genres = get_filter('genres'); var voice_modulation = get_filter('voice_modulation'); var languages = get_filter('languages'); var jingle_moods = get_filter('jingle_moods'); var ivr = get_filter('ivr'); $.ajax({ url:"fetch_data.php", method:"POST", data: { action:action, // minimum_price:minimum_price, // maximum_price:maximum_price, gender:gender, genres:genres, voice_modulation:voice_modulation, languages:languages, jingle_moods:jingle_moods, ivr:ivr }, success:function(data) { $('.filter_data').html(data); } }); } function get_filter(class_name) { var filter = []; $('.'+class_name+':checked').each(function(){ filter.push($(this).val()); }); return filter; } $('.common_selector').click(function(){ filter_data(); }); // $('#price_range').slider({ // range:true, // min:1000, // max:65000, // values:[1000, 65000], // step:500, // stop:function(event, ui) // { // $('#price_show').html(ui.values[0] + ' - ' + ui.values[1]); // $('#hidden_minimum_price').val(ui.values[0]); // $('#hidden_maximum_price').val(ui.values[1]); // filter_data(); // } // }); }); </script> </body> </html>
and my
<?php //fetch_data.php include('database_connection.php'); if(isset($_POST["action"])) { $query = " SELECT * FROM voice_bank_data WHERE voice_status = '1' "; // if(isset($_POST["minimum_price"], $_POST["maximum_price"]) && !empty($_POST["minimum_price"]) && !empty($_POST["maximum_price"])) // { // $query .= " // AND product_price BETWEEN '".$_POST["minimum_price"]."' AND '".$_POST["maximum_price"]."' // "; // } // Gender if(isset($_POST["gender"])) { $gender_filter = implode("','", $_POST["gender"]); $query .= " AND voice_gender IN('".$gender_filter."') "; } // Genres if(isset($_POST["genres"])) { $genres_filter = implode("','", $_POST["genres"]); $query .= " AND voice_genres IN('".$genres_filter."') "; } // Voice Modulation if(isset($_POST["voice_modulation"])) { $voice_modulation_filter = implode("','", $_POST["voice_modulation"]); $query .= " AND voice_voice_modulation IN('".$voice_modulation_filter."') "; } // Languages if(isset($_POST["languages"])) { $languages_filter = implode("','", $_POST["languages"]); $query .= " AND voice_languages IN('".$languages_filter."') "; } // Jingle Moods if(isset($_POST["jingle_moods"])) { $jingle_moods_filter = implode("','", $_POST["jingle_moods"]); $query .= " AND voice_jingle_moods IN('".$jingle_moods_filter."') "; } // IVR if(isset($_POST["ivr"])) { $ivr_filter = implode("','", $_POST["ivr"]); $query .= " AND voice_ivr IN('".$ivr_filter."') "; } $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $total_row = $statement->rowCount(); $output = ''; if($total_row > 0) { foreach($result as $row) { $output .= ' <div class="col-sm-3 col-lg-4 col-md-3"> <div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;"> <audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;"> <source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive"> </audio> <p align="center"><strong> '. $row['voice_name'] .'</strong></p> <p style="font-size: 12px;"> Gender : '. $row['voice_gender'].' <br /> Genres : '. $row['voice_genres'].' <br /> Voice Modulation : '. $row['voice_voice_modulation'].' <br /> Languages : '. $row['voice_languages'].' <br /> Jingle Moods : '. $row['voice_jingle_moods'].' <br /> Ivr : '. $row['voice_ivr'].' <br /> </p> <button class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;"> Add to PlayList </button> </div> </div> '; } } else { $output = '<h3>No Data Found</h3>'; } echo $output; } ?>
How can i add add-to-cart functionality? https://snag.gy/xQ8TXP.jpg Edited June 10, 2019 by aveevaHello all, My question is about a custom-coded latest-news plugin written by someone else. I don't know if it is generic, a copy of something else or what. It works good! but when I go to add a new news item to the list under Settings, it adds the item to the bottom of the list. The news is displayed on my homepage in short form and in full format on the primary news page. I need new items to be added to the TOP of the list instead or in reverse, so that in all the containers where it resides, the latest news item added is always at the top of the list. I know nothing about php but I am looking to learn. I plan on taking some basic classes on css and php to upgrade my archaic html skills, but I'm currently studying other subjects. Regardless, if this has a simple fix, I would be very interested in knowing what is needed and where/why. Here is the core of the php that I am finding in the plugin: There are three php files, This one says active, the other two say inactive so I get the impression they are not in use. Let me know if I should post their contents as well. Appreciate any help with this! My sincere thanks in advance. Labeled active: latest_news.php */ob_start();register_activation_hook(__file__, latest_news_install);function latest_news_install() { global $wpdb; $table_name = $wpdb->prefix . "latest_news"; if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS " . $table_name . " ( `id` int(10) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` text NOT NULL, `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) );"; mysql_query($sql) or die(mysql_error()); }}if( !function_exists('wp_latest_news_init') ) { function wp_latest_news_init() { add_shortcode( 'wp_latest_news', 'shortcode_latest_news'); }}if( !function_exists('shortcode_latest_news') ) { function shortcode_latest_news() { // extract(shortcode_atts(array('limit' => '5', ), $atts)); global $wpdb; $user_count = $wpdb->get_results("SELECT * FROM wp_latest_news ORDER BY date ASC LIMIT 4"); foreach ($user_count as $output) { $htmlOutput[] = "<li><b><a href='". get_permalink(287)."?news_id=".$output->id."'>" . $output->title . "</a></b></li>"; } //echo $htmlOutput; //echo "<pre>"; print_r($user_count); echo "</pre>"; foreach ($htmlOutput as $out) { echo $out; } return $htmlOutput; }}/* add_action('init', 'wp_latest_news_init' ) is used for call init function for create shortcode */add_action('init', 'wp_latest_news_init' );add_action('admin_menu', 'wp_latestnews_links' );function wp_latestnews_links() { add_submenu_page( 'options-general.php', __( 'Latest News ' ), __( 'Latest News ' ), 5 , 'latest_news_settings', 'latest_news_settings' );}// function latest_news_settings() {// global $wpdb;// if (isset($_POST["submit"])) {// $sql="INSERT INTO ".$wpdb->prefix . "latest_news(`title`,`description`) VALUES ('".$_POST['news_title']."','".$_POST['description']."') ";// //$sql=$wpdb->insert( $wpdb->latest_news, array( 'title' => $_POST['news_title'] ,'description' => $_POST['description'] ) );// mysql_query($sql) or die(mysql_error());// }// include 'Latest_news_setting.php';function latest_news_settings() { global $wpdb; $action = $_REQUEST["action"]; $id = $_REQUEST['id']; $sql = "SELECT * from ".$wpdb->prefix."latest_news "; $results = $wpdb->get_results($sql); //echo "<pre>";print_r($results); //$post_arr = query_posts(""); //echo "<pre>";print_r($post_arr);exit; switch ($action) { case 'add' : include('news_form.php'); break; case 'save' : if(isset($_POST['cancel'])) { include('latest_news_list.php'); } else if(isset($_POST['add'])) { $wpdb->query("insert into ".$wpdb->prefix."latest_news (`title`,`description`) VALUES ('".$_REQUEST['news_title']."','".$_REQUEST['description']."')"); //header("Location: http://localhost:81/Bravo/wp-admin/edit.php?page=slider_images"); header("location:?page=latest_news_settings"); } break; case 'edit' : $sql = "SELECT * from ".$wpdb->prefix."latest_news where id = '".$id."' "; $results_arr = $wpdb->get_results($sql); //echo "<pre>";print_r($results_arr); include('news_form.php'); break; case 'update' : if(isset($_POST['cancel'])) { include('news_form.php'); } else if(isset($_POST['edit'])) { //echo $id; $wpdb->query("update ".$wpdb->prefix."latest_news set title = '".$_REQUEST['news_title']."', description = '".$_REQUEST['description']."' where id='".$id."'"); header("location:?page=latest_news_settings"); } break; case 'delete' : $wpdb->query("delete from ".$wpdb->prefix."latest_news where id='".$id."'"); header("location:?page=latest_news_settings"); break; default: include('latest_news_list.php'); break; }}?>() I have Win 7 home premium, Apache 2.2 (installed using the .msi) and PHP 5.2.14 (downloaded as "php-5.2.14-Win32-VC6-x86.zip", installed manually, it works) on both machines. The other is 32-bit and the other is 64-bit, both Windows 7 Home Premium. When I run the exactly same script on one machine, it does what it is supposed to (32-bit), but on the 64-bit it does not. Basically this appears in two situations (so far): I have a script that reads a (xml) file into a simplexml object, and if this is not successful, it prints an error message. On the 32-bit machine I can import (read) another xml file at once once the first one is processed (into a sqlite database), but on the 64-bit machine it gives me an error originating from the fact that the script did not manage to create the simplexml object. The other situation is when I want to open a specific PDF - file in a browser window (Firefox, the newest one, on the 32-bit machine, IE something newish on the 64-bit). The file exists, the path to the folder is in the Path environment variable, I can open it normally etc on the 64-bit machine, but when I click on a link that is supposed to open the file in a browser window I only get an error message saying that the file does not start with "%PDF.... Needless to say, the precisely same script works just fine on the 32 bit machine. $path_to_image="D:\\path_to_folder\\"; $file_name=$_GET['file_name']; header("Content-disposition: inline; filename=".$path_to_image.$file_name); header("Content-type: application/pdf"); readfile($path_to_image.$file_name); The above code is from the part that receives the file name from a form (other file). Anyone noticed anything like this? Any suggestions? Have been trying to figure this out for days, now... Oh, forgot: In both cases the thing is accessed as/from "localhost". Hi all. I'm using a cron job to pull the XML feed of my last five tweets, and using simplexml to parse and display the feed on my website. Here's the PHP I'm using--it works just fine, and displays exactly as I want it to: <?php $xml = simplexml_load_file('crontwitter.xml'); foreach ($xml->status as $status) { print "<p><span class=\"twittertext\">{$status->text}</span><br />"; print "<a class=\"twittertime\" href=\"http://twitter.com/#!/eaners/status/{$status->id}\" target=\"_blank\">"; echo date("j M Y, g:i A",strtotime($status->created_at)); print "</a></span></p>"; } ?> I'd like to add a touch more "intelligence" to this script, though. Namely, there are three things I'd also like to have this script do: I'd like to append "I" to any tweets that include the #fb hashtag, so that things display correctly (e.g., "I did such and such today" instead of just "did such and such today") I'd like to link to any other Twitter users mentioned (they would always be mentioned using the @username format) I'd like to link to a search for any other hash tag mentioned aside from #fb (they would always be included using the #tag format) I guess I'm not sure how exactly to further parse the XML file. I'll admit to being a relative newbie when it comes to PHP, so any assistance would be greatly appreciated! I am trying to make a login which works perfectly until I try and add remember me functionality into the User class. Hello Freaks, I am currently working on a status report web application. A user inputs what they are planning on accomplishing that week. Afterwords realizes that they made a mistake and need to correct it. The way I want to go about this is sql the database and return * where the username and report date are current. With the results of this query I insert them into the form as the value. This yields a populated form. From here I want the user to be able to change any line and submit the whole form. However, the post array is only populated with one row of data. I thought this might have to do with the names of the inputs all being the same so i tried to index those through the while loop with no luck. Any help would be appreciated! here's the code Code: [Select] <? // renaming sess var $UAID = $_SESSION['UAID']; $WEND = $_SESSION['WEEK_ENDING2']; //have we submitted our changes? if($EDIT == TRUE){ //how many task are there this week $results = mysql_query("Select COUNT(UAID) FROM `WPFTW` where UAID ='$UAID' and Rend = '$WEND'"); $row = mysql_fetch_row($results); //clean $_POST print_r($_POST); unset($_POST['Report']); echo "<br>"; print_r($_POST); } //what do we plan on editing $results = mysql_query("Select * FROM `WPFTW` where UAID ='$UAID' and Rend = '$WEND'"); //while there are results while($row = mysql_fetch_array($results)){ //increment for input name $k = 1; //date formatting list($year,$month,$day) = explode("-",$row['Target']); $row['Target'] = $month."-".$day."-".$year; //empty string to uncheck checkboxes $checked = ""; //populate checkboxes if($row['MS'] == "on"){ $checked = "yes"; } //select the correct drop down menu option if(isset($row['Status'])){ if($row['Status'] == " "){ $selected = "selected"; $selected1 = ""; $selected2 = ""; $selected3 = ""; } elseif($row['Status'] == "P"){ $selected = ""; $selected1 = "selected"; $selected2 = ""; $selected3 = ""; } elseif($row['Status'] == "C"){ $selected = ""; $selected1 = ""; $selected2 = "selected"; $selected3 = ""; } elseif($row['Status'] == "CL"){ $selected = ""; $selected1 = ""; $selected2 = ""; $selected3 = "selected"; } } //select the correct drop down menu option if(isset($row['OT'])){ if($row['OT'] == "Y"){ $selected4 = "selected"; $selected5 = ""; } elseif($row['OT'] == "N"){ $selected4 = ""; $selected5 = "selected"; } } //var to send form to self $cani = htmlentities($_SERVER['PHP_SELF']); //concatenate html & php for form $test = "<form id =\"2bigform\" action=$cani method = \"post\">" . "<tr>" . "<td><input id=\"hidden\" name=\"UAID$k\" type=\"hidden\" value=" . $_SESSION['UAID'] ."></td>". "<td width=\"7%\"> <input id=\"SR\#$k\" name=\"SR#\" type=\"text\" size=\"10%\" maxlength=\"10\" value=" . $row['SRNUM'] . "></td>" . "<td width=\"63%\"> <input id=\"Task$k\" name=\"Task\" type=\"textarea\" size=\"63%\" value=" . $row['Task'] . "></td>" . "<td width=\"7%\"> <select id=\"Status$k\" name=\"Status\">". " <option value=\" \" $selected></option>". " <option value=\"P\" $selected1>P</option>". " <option value=\"C\" $selected2>C</option>". " <option value=\"CL\" $selected3>CL</option>". "</select></td>". "<td width=\"7%\"> <input id=\"MS$k\" name=\"MS\" type=\"checkbox\" size=\"7%\" value=" . $row['MS'] . " checked = $checked></td>". "<td width=\"7%\"> <select id=\"OT$k\" name=\"OT\">". " <option value=\"Y\" $selected4>Y</option>". " <option value=\"N\" $selected5>N</option>". "</select></td>". "<td width=\"9%\"> <input id=\"Target$k\" name=\"Target\" type=\"text\" size=\"9%\" value=" . $row['Target'] . "></td>". "<input id=\"hidden\" name=\"RDate$k\" type=\"hidden\" value=" . $_SESSION['WEEK_ENDING'] ."></td></tr>"; echo $test; $k++; echo $k; } echo "</table>". "<input id=\"Sub\" type= \"Submit\" name=\"Report\" value= \"Submit\"/>". "</form>". "</body>". "</html>"; //<td width="7%"> <input id="SR#" name="SR#" type="text" size="10%" maxlength="10"/></td> //<td width="63%"> <input id="Task" name="Task" type="textarea" size= "63%"/></td> } ?> Hi There I am trying to create a page that edit mysql database from a php page. I can get the edit page to show the orginal information but it wont update the data in the mysql database. I am sure I have entered everything right. If anyone could help with this I would greatly appreciated <?php include("dbconnect.php"); if(isset($_POST['submit'])) { // Set global variables to easier names // and prevent sql injection and apostrophe to break the db. $ProductName = mysql_escape_string($_POST['ProductName']); $ProductText = mysql_escape_string($_POST['ProductText']); $ProductImage = mysql_escape_string($_POST['ProductImage']); $ProductPrice = mysql_escape_string($_POST['ProductPrice']); $result = mysql_query("UPDATE Product SET ProductName='$ProductName', ProductText='$ProductText', ProductImage='$ProductImage', ProductPrice='$ProductPrice' WHERE ID='$ID' ",$dbconnect); echo "<b>Thank you! Product UPDATED Successfully!<br>You'll be redirected to View Page after (2) Seconds"; echo "<meta http-equiv=Refresh content=2;url=view.php>"; echo "$ProductName <br> $ProductText <br> $ProductImage <br> $ProductPrice"; } elseif(isset($_GET['ID'])) { $result = mysql_query("SELECT * FROM Product WHERE ID='$_GET[ID]' ",$dbconnect); while($myrow = mysql_fetch_assoc($result)) { $ProductName = $myrow["ProductName"]; $ProductText= $myrow["ProductText"]; $ProductImage = $myrow["ProductImage"]; $ProductPrice = $myrow["ProductPrice"]; ?> <br> <h3>::Edit Product</h3> <form method="post" action="<?php echo $PHP_SELF ?>"> <input type="hidden" name="ID" value="<? echo $myrow['ID']?>"> Product Name: <input name="ProductName" size="40" maxlength="255" value="<? echo $ProductName; ?>"><br> Product Text: <textarea name="ProductText" rows="7" cols="30"><? echo $ProductText; ?></textarea><br> Product Image: <textarea name="ProductImage" rows="7" cols="30"><? echo $ProductImage; ?></textarea><br> Product Price: <textarea name="ProductPrice" rows="7" cols="30"><? echo $ProductPrice; ?></textarea><br> <input type="submit" name="submit" value="Update Product"> </form> <? }//end of while loop }//end else ?> Hi All, The Problem: I'm trying to learn how to take records from the NAME row of one table (i.e. Tom, Jim, Chris, Mike) and put them into a SELECT (drop down menu) box, then select a name and save it to a DIFFERENT table where the row is also called NAME, and THEN have that selection I just saved show in the SELECT box as SELECTED when the page refreshes. I have found a hundred websites showing how to bind a SELECT box to a table and put them into a SELECT box via $key => $val and even how to save it to ANOTHER textbox on the page, which is a lot easier, but never a step further as described in the first paragraph above. Seems unbelievable to me since it's so common. Maybe I'm just not using the proper search terms/keywords. Here's an example: Let's say you wanted to notify 3 people of your birthday. So, on the notification page, you would enter three names of people you would want notified all in separate input textboxes with [keys]. So, you enter John, Chris, and Tom into three text boxes and save the page. Done. Now, on another page, I have -- say .... five select boxes. For arguments sake, let's just say I click on all of them one at a time. In each of them, I would only see three names (John, Chris, and Tom). Now, in the first SELECT box I click on John. In the second select box I click on Chris, and on the third I click on Tom. Then save the form. I would like to see John, Chris, and Tom in the first three boxes after refreshing and I would like to see SELECT A NAME on the last two Select boxes that we never did anything with. Remember, there are NO default names in the first table with row called NAMES. They are populated by the user and saved to the row. I'm attaching an image of what the page looks like that I want to see the names and be able to select them. Does anyone have a link to a site that shows how to do this... or maybe have something very basic that would show me the process? Or, if not too difficult, maybe you could show me? Thanks in advance for any help! Attached Files Untitled.jpg 24.97KB 0 downloads I am using the dragdrop functionality on a page which also updates the database.Drag and drop is working fine But i am having difficulty to determine which events to use to update the database. Here is my code
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Sortable - Portlets</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script> <!--<link rel="stylesheet" href="/resources/demos/style.css">--> <style> body { min-width: 520px; } .interview-questions-column { width: 400px; float: left; padding-bottom: 100px; } .question-bank { width: 500px; float: left; padding-bottom: 100px; } .portlet { margin: 0 1em 1em 0; padding: 0.3em; } .portlet-header { padding: 0.2em 0.3em; margin-bottom: 0.5em; position: relative; } .portlet-toggle { position: absolute; top: 50%; right: 0; margin-top: -8px; } .portlet-content { padding: 0.4em; } .portlet-placeholder { border: 1px dotted black; margin: 0 1em 1em 0; height: 50px; } .sortable { border: 1px solid #eee; width: 95%; min-height: 20px; list-style-type: none; margin: 0; padding: 5px 0 0 0; float: left; margin-right: 10px; } .sortable li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 95%; } .bank-quertion-sotrable { border: 1px solid #eee; width: 150px; min-height: 20px; list-style-type: none; margin: 0; padding: 5px 0 0 0; float: left; margin-right: 10px; } .bank-quertion-sotrable li{ margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 200px; } .ui-state-default { height: 1.5em; line-height: 1.2em; } </style> <script> $(function() { $( ".interview-questions-column" ).sortable({ connectWith: ".interview-questions-column", handle: ".portlet-header", cancel: ".portlet-toggle", placeholder: "portlet-placeholder ui-corner-all" }); $( ".portlet" ) .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ) .find( ".portlet-header" ) .addClass( "ui-widget-header ui-corner-all" ) .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>"); $( ".portlet-toggle" ).click(function() { var icon = $( this ); icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" ); icon.closest( ".portlet" ).find( ".portlet-content" ).toggle(); }); }); $(function() { $( ".sortable" ).sortable({ placeholder: "ui-state-default", connectWith: ".connectedSortable", /*receive: function(event, ui) { // only perform for sub drop downs if($(this).hasClass('question_bank')) { // if the item doesn't have the matching sub class if (!$(this).hasClass($(ui.item).attr('class'))) { // cancel the sortable $(ui.sender).sortable('cancel'); } } alert('receive'); alert(ui.sender.attr("dataid")); alert(ui.sender.toSource()); // alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); },*/ update: function (event, ui) { //serial = $('#sortableF').sortable('serialize'); var data = $(this).sortable('serialize'); alert(data); //alert('update sortable'); //alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); // POST to server using $.post or $.ajax /*$.ajax({ data: 'test', type: 'POST', url: '/your/url/here' });*/ } }).disableSelection(); }); $(function() { $( ".draggable" ).draggable({ connectToSortable: ".sortable", helper: "clone", /*revert: function(valid) { if(valid) { alert("drop is valid"); //Dropped in a valid location } else { alert("drop is invalid"); //Dropped in an invalid location } // return !valid; return false; }*/ stop: function( event, ui ) { // alert(ui); // alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); } }); }); $( "ul, li" ).disableSelection(); </script> </head> <body> <div class="interview-questions-column"> <div class="portlet"> <div class="portlet-header">Feeds</div> <div class="portlet-content"> <ul id="sortableF" class="connectedSortable sortable"> <li class="ui-state-default" id="item-1">Item 1</li> <li class="ui-state-default" id="item-2">Item 2</li> <li class="ui-state-default" id="item-3">Item 3</li> <li class="ui-state-default" id="item-4">Item 4</li> <li class="ui-state-default" id="item-5">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">News</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-6">Item 1</li> <li class="ui-state-default" id="item-7">Item 2</li> <li class="ui-state-default" id="item-8">Item 3</li> <li class="ui-state-default" id="item-9">Item 4</li> <li class="ui-state-default" id="item-10">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Shopping</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-11">Item 1</li> <li class="ui-state-default" id="item-12">Item 2</li> <li class="ui-state-default" id="item-13">Item 3</li> <li class="ui-state-default" id="item-14">Item 4</li> <li class="ui-state-default" id="item-15">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Links</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-16">Item 1</li> <li class="ui-state-default" id="item-17">Item 2</li> <li class="ui-state-default" id="item-18">Item 3</li> <li class="ui-state-default" id="item-19">Item 4</li> <li class="ui-state-default" id="item-20">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Images</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-21">Item 1</li> <li class="ui-state-default" id="item-22">Item 2</li> <li class="ui-state-default" id="item-23">Item 3</li> <li class="ui-state-default" id="item-24">Item 4</li> <li class="ui-state-default" id="item-25">Item 5</li> </ul> </div> </div> </div> <div class="question-bank"> <div class="portlet"> <div class="portlet-header">Question bank</div> <div class="portlet-content"> <ul id="question_back" class="connectedSortable bank-quertion-sotrable"> <li class="ui-state-default draggable" id="item-26">Item 1</li> <li class="ui-state-default draggable" id="item-27">Item 2</li> <li class="ui-state-default draggable" id="item-28">Item 3</li> <li class="ui-state-default draggable" id="item-29">Item 4</li> <li class="ui-state-default draggable" id="item-30">Item 5</li> </ul> </div> </div> </div> </body> </html>Basically above code will form few boxes with items(which are actually questions) in it. There is one box on the right side with heading "Question Bank". From the "Question Bank" we can drag the questions to other boxes but can't do the reverse(this is also working). Also we can sort the questions within the box or drag the questions from one box to another. Box heading are the categories and items are questions associated to that categories. What i need is : Event that updates the database when we drag the questions from "Question Bank" to any box on the left side. Please note Questions in the "Question Bank" are pre created coming from database. Event that updates the database when we sort the questions within the box. Event that updates the database when we drag the question from one box to another box. it should also do the sorting for that two boxes. Event that updates the database when we sort the boxes. Here is the JS Fiddle link jsfiddle.net/6o30rrzx Question Bank is comming on the bottom of the page instead of on the right side any advice and suggestions will be greatly appreciated Thank you for reading this post. I require a page to be added to my website. This page will facilitate a refined search via Google, Bing and Yahoo search engine simultaneously , show the top 5 of each engine. Is this possible using php ? Thank's Hello, Does anyone know a tutorial I can follow to create my own search engine over the items I have in my SQL database? I find a lot of tutorials but they are all 'one word searches' which means if you type two words you will get all results that contain either word (too many hits). If the search engine tutorial displays result with AJAX even better. Thanks for help. df 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 am working on a php script for searching a database table. I am really new to this, so I used the this tutorial http://www.phpfreaks.com/tutorial/simple-sql-search I managed to get all the things working the way I wanted, except one important and crucial thing. Let me explain. My table consist of three columns, like this: ID(bigint20) title(text) link (varchar255) ============================= ID1 title1 link-1 ID2 title2 link-2 etc... Like I said, I managed to make the script display results for a search query based on the title. Want I want it to do more, but I can't seem to find the right resource to learn how, is to place a "Download" button under each search result with its corresponding link from the table. Here is the code I used. <?php $dbHost = 'localhost'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = 'user'; $dbPass = 'pass'; $dbDatabase = 'db'; // 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 title, link FROM db WHERE title LIKE '%{$searchTermDB}%'"; $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[] = "{$row['title']}<br /> Download - this is the button I want to link to the title results - and maybe other links too - <br /> "; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="search?" name="searchForm"> Search for title: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /> <input type="submit" name="submit" value="Search" /> </form> <?php echo (count($results) > 0)?"Rezultate lucrari de licenta sau disertatie pentru {$searchTerms} :<br /><br />" . implode("", $results):""; ?> $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$row['title']}<br /> Download - this is the button I want to link to the title results - and maybe other links too - <br /> "; $i++; I would like the results to be displayed like this Results for SearchItem: Result 1 Download | Other link Result 2 Download | Other link etc.... or something like this. So, how do I add the data from the link row into a text(Dowload), within an <a href> tag (well, at least I guess it would go this way) ? My first tries (fueled by my lack of knowledge) where things like $results[] = "{$row['title']}<br /> <a href="{$row['link']}">Download</a> <br /> "; but I keep getting lots of errors, and then I don't know much about arrays and stuff (except basic notions); So there it is. I am really stuck and can't seem to find any workaround for this. Any suggestions? (examples, documentation, anything would do, really) Thanks, Radu Hello, I'm developing a website that asks the user to submit a keyword for a search. The results should display matches for this keyword, but also show matches for related keywords (in order of relevenace!). I'm planning on building up a library of which search terms users use in the same sessions (e.g. if someone searches for "it jobs" and "php jobs", I'll know the terms are correlated), and I'll also measure the click-through rates of the items on the results list. I've been spending all weekend trying to map out the design for this but it's proving incredibly complicated and I think the solution is likely to be on the internet somewhere already?! Please could someone point me in the right direction if you've come accross this problem before? Thanks a million, Stu Friends, I want to extract the Search Keyword from the URL, a visitor came from. I am using a PHP CMS and want to show the Keyword on my Blog. So if they search "abcd" from google, i want to extract "abcd" and echo on my blog. Here is the coding i could got hold of, but its not working, not echoing anything <?php function pk_stt2_function_get_delimiter($ref) { $search_engines = array('google.com' => 'q', 'go.google.com' => 'q', 'images.google.com' => 'q', 'video.google.com' => 'q', 'news.google.com' => 'q', 'blogsearch.google.com' => 'q', 'maps.google.com' => 'q', 'local.google.com' => 'q', 'search.yahoo.com' => 'p', 'search.msn.com' => 'q', 'bing.com' => 'q', 'msxml.excite.com' => 'qkw', 'search.lycos.com' => 'query', 'alltheweb.com' => 'q', 'search.aol.com' => 'query', 'search.iwon.com' => 'searchfor', 'ask.com' => 'q', 'ask.co.uk' => 'ask', 'search.cometsystems.com' => 'qry', 'hotbot.com' => 'query', 'overture.com' => 'Keywords', 'metacrawler.com' => 'qkw', 'search.netscape.com' => 'query', 'looksmart.com' => 'key', 'dpxml.webcrawler.com' => 'qkw', 'search.earthlink.net' => 'q', 'search.viewpoint.com' => 'k', 'mamma.com' => 'query'); $delim = false; if (isset($search_engines[$ref])) { $delim = $search_engines[$ref]; } else { if (strpos('ref:'.$ref,'google')) $delim = "q"; elseif (strpos('ref:'.$ref,'search.atomz.')) $delim = "sp-q"; elseif (strpos('ref:'.$ref,'search.msn.')) $delim = "q"; elseif (strpos('ref:'.$ref,'search.yahoo.')) $delim = "p"; elseif (preg_match('/home\.bellsouth\.net\/s\/s\.dll/i', $ref)) $delim = "bellsouth"; } return $delim; } /** * retrieve the search terms from search engine query * */ function pk_stt2_function_get_terms($d) { $terms = null; $query_array = array(); $query_terms = null; $query = explode($d.'=', $_SERVER['HTTP_REFERER']); $query = explode('&', $query[1]); $query = urldecode($query[0]); $query = str_replace("'", '', $query); $query = str_replace('"', '', $query); $query_array = preg_split('/[\s,\+\.]+/',$query); $query_terms = implode(' ', $query_array); $terms = htmlspecialchars(urldecode(trim($query_terms))); return $terms; } /** * get the referer * */ function pk_stt2_function_get_referer() { if (!isset($_SERVER['HTTP_REFERER']) || ($_SERVER['HTTP_REFERER'] == '')) return false; $referer_info = parse_url($_SERVER['HTTP_REFERER']); $referer = $referer_info['host']; if(substr($referer, 0, 4) == 'www.') $referer = substr($referer, 4); return $referer; } $referer = pk_stt2_function_get_referer(); if (!$referer) return false; $delimiter = pk_stt2_function_get_delimiter($referer); if( $delimiter ){ $term = pk_stt2_function_get_terms($delimiter); } echo $term; ?> May someone help? Natasha T |