Jump to content

blahaha

New Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by blahaha

  1. this is the sql code to create and load the database CREATE DATABASE recipes; USE recipes; CREATE TABLE recipe2 ( name varchar(20), country varchar(20) ); INSERT INTO recipe2 (name,country) VALUES ('palaak paneer','India'); INSERT INTO recipe2 (name,country) VALUES ('gulyas leves','Hungary'); INSERT INTO recipe2 (name,country) VALUES ('fajita','Mexico'); INSERT INTO recipe2 (name,country) VALUES ('peanut butter and jelly','United States');
  2. sorry, this is my first post, and for some reason I did not have rights to modify my old one, there was an error in what I posted due to a typeo, this is the code that you should look at: <!doctype html> <?php // php script that should get the ajax post // and run the sql query //host, username, password $connection = mysql_connect('localhost','root',''); mysql_select_db('recipes'); //run query if post successful $data = ''; if(isset($_POST['countrySelected'])) { $var = $_POST['countrySelected']; if($query = mysql_query("SELECT name FROM recipes2 WHERE country='%$var%'")) { while($d = mysql_fetch_array($query)) { $data .= $data . '<div>' . $d['name'] . '</div>'; //incrementation .= } echo $data; } // if not successful print, echo report } else{ echo "<html><br /> <br /> <br /> ***POST NOT SET**** <br /> <br /> <br /></html>"; } ?> <!-- html code for display --> <html lang="en"> <head> <meta charset="utf-8"> <title>change demo</title> <style> div { color: red; } </style> <script src="//code.jquery.com/jquery-1.10.2.js"></script> </head> <body> <!-- code for drop down menu --> <select name="countries" id = "countries"> <option>Hungary</option> <option>United States</option> <option>Mexico</option> <option >India</option> </select> <div> </div> <script> //javascript that detects when the button has been updated and retrieves the button option text value. $( "select" ) .change(function () { var str = ""; var countrySelectedStr = ""; $( "#countries option:selected" ).each(function() { str += $( this ).text(); }); countrySelectedStr += "countrySelected=" + str; $( "div" ).text( countrySelectedStr ); // ajax post jQuery.ajax({ type: "POST", url: "filterRecipes.php", data: countrySelectedStr, dataType: "text" , cache: false }); }) .change(); </script> </body> </html>
  3. Here there, This is a post for all of you ajax/php pimps who don't mind helping a beginner. I have been working on a little ajax script to filter a table called "recipes2" in a database called "recipes" using a dropdown menu. Once I get this script to work, I can run queries without having to refresh the page. The problem, something is not right, the php script does not seem to be getting the posted data. even though the ajax script returns success when i check for it. What am I doing wrong? Also please note that, if possible, I'd like all the code to stay on one page. This is the SQL script if you want to create the database and table: Here is the code, the file should be named 'filterRecipes.php'.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.