Jump to content

hakmir

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Everything posted by hakmir

  1. Hi guys, I have two files "searchrecipe.php" and "reciperesults.php" (with the help of MadTechie and Andy17) Both files are working perfect (almost) (almost): I don't want all the results in one page. I want 10 results (just and example) per page. I've been trying to do and I was so close but I couldn't. Can anybody help me? Thanks in advance. Here are the files searchrecipe.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $dbcnx = @mysql_connect('localhost', 'root', ''); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('recipetime')) { exit('<p>Unable to locate the recipe ' . 'database at this time.</p>'); } ?> <form id="form1" name="form1" method="post" action="reciperesults.php"> <label><strong>SEARCH RECIPE</strong><br /> <br /> </label> <p>Country<br /> <label> <select name="country" id="country"> <option>USA</option> <option>CANADA</option> <option>ENGLAND</option> </select> </label> </p> <p>Type of Food <br /> <label> <select name="typeoffood" id="typeoffood"> <option>DESERT</option> <option>ENTREE</option> <option>SPICY</option> </select> </label> </p> <p> <label> <input type="submit" name="Search" id="Search" value="Search" /> </label> </p> </form> </body> </html> reciperesults.php <?php if (!isset($_POST['Search'])) die("FAILED: nothing selected"); $dbcnx = @mysql_connect('localhost', 'root', ''); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('recipetime')) { exit('<p>Unable to locate the recipe' . 'database at this time.</p>'); } $typeoffood = $_POST['typeoffood']; $country = $_POST['country']; $sql = "SELECT * FROM recipeform WHERE country='$country' AND typeoffood='$typeoffood'"; $result = mysql_query($sql); echo "HERE IS ALL THE $typeoffood RECIPES FROM $country" . "<br>" . "<br>"; while ($rec = mysql_fetch_array($result)) { $recname = htmlspecialchars($rec['name']); $reccountry = htmlspecialchars($rec['country']); $rectypeoffood = htmlspecialchars($rec['typeoffood']); $recyourrecipe = htmlspecialchars($rec['yourrecipe']); echo "Name: <td>$recname</td>" . "<br>"; echo "Country: <td>$reccountry</td>" . "<br>"; echo "Typeoffood: <td>$rectypeoffood</td>" . "<br>"; echo "Your Recipe: <td>$recyourrecipe</td>" . "<br>" . "<br>"; } ?>
  2. Belive me I almost gave up learning php. But now I finished my first project with your help. Thanks a lot.
  3. I solved the problem. Here is the code: <?php if(!isset($_POST['Search'])) die("FAILED: nothing selected"); $dbcnx = @mysql_connect('localhost', 'root', ''); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('recipetime')) { exit('<p>Unable to locate the recipe' . 'database at this time.</p>'); } $typeoffood = $_POST['typeoffood']; $country = $_POST['country']; $sql = "SELECT * FROM recipeform WHERE country='$country' AND typeoffood='$typeoffood'"; $result = mysql_query($sql); echo "HERE IS ALL THE $typeoffood RECIPES FROM $country"."<br>"."<br>"; //my stuff while ($rec = mysql_fetch_array($result)) { $recname = htmlspecialchars($rec['name']); $reccountry = htmlspecialchars($rec['country']); $rectypeoffood = htmlspecialchars($rec['typeoffood']); $recyourrecipe = htmlspecialchars($rec['yourrecipe']); echo "Name: <td>$recname</td>\n"."<br>"; echo "Country: <td>$reccountry</td>\n"."<br>"; echo "Typeoffood: <td>$rectypeoffood</td>\n"."<br>"; echo "Your Recipe: <td>$recyourrecipe</td>\n"."<br>"."<br>"; echo( '<a href="searchrecipe.php">Search Recipe</a>' )."<br>"; echo( '<a href="submitrecipe.php">Submit Recipe</a>' )."<br>"."<br>"; } //mystuff ?>
  4. That's ok, I will just work on it. Thanks a lot. After I finish this project I will prepare an educational file to teach people (who are very new to php like me) how to make a simple php mysql form from A to Z. Thanks again.
  5. Last question, when I press search, it just shows one result. It doesn't show all the recipies in that criteria (form example, deserts from USA) ?? There are more than one recipe in that category but it just gives me the first one when I press search. It doesn't give me others.?
  6. Awesome. It works perfect. I just had to correct the part that you forgot to put "$" sign to "typeoffood". Thanks a lot. Do you have a paypal account that I can send money. It is not much but just to show my appreciation.
  7. Thanks a lot for the answer. I really appreciate. But when I use the code that you gave me it says: FAILED: nothing selected I don't understand. Obviously it doesn't get the values from "searchrecipe.php" page. (id=country and id=typeoffood)
  8. Hi Guys, I made 3 files: submitrecipe.php searchrecipe.php reciperesult.php I don't have any problem submitting imformation with "submitrecipe" to mysql database. I managed to make "searchrecipe.php" too (I think so ). but I don't know how to make "reciperesult.php to show the results. I just prepared an image on html form to show you what I am trying to do (reciperesults.jpg). I attached other files too which I don't have problems with them (submitrecipe.jpg and searchrecipe) Here is "submitrecipe.php" (I don't have problem with this form) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="submitrecipe.php"> <label><strong>SUBMIT YOUR RECIPE</strong><br /> <br /> Name<br /> <input type="text" name="yourname" id="yourname" /> </label> <p>Country<br /> <label> <select name="yourcountry" id="yourcountry"> <option>USA</option> <option>CANADA</option> <option>ENGLAND</option> </select> </label> </p> <p>Type of Food <br /> <label> <select name="typeoffood" id="typeoffood"> <option>DESERT</option> <option>ENTREE</option> <option>SPICY</option> </select> </label> </p> <p>Your recipe<br /> <label> <textarea name="yourrecipe" id="yourrecipe" cols="45" rows="5"></textarea> </label> </p> <p> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label></p> </form> <?php $dbcnx = @mysql_connect('localhost', 'root', ''); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('recipetime')) { exit('<p>Unable to locate the experience ' . 'database at this time.</p>'); } if (isset($_POST['yourrecipe'])): // A new recipe has been entered // using the form. $yourname = $_POST['yourname']; $yourcountry = $_POST['yourcountry']; $typeoffood = $_POST['typeoffood']; $yourrecipe = $_POST['yourrecipe']; $sql = "INSERT INTO recipeform SET name='$yourname', country='$yourcountry', typeoffood = '$typeoffood', yourrecipe='$yourrecipe'"; if (@mysql_query($sql)) { echo '<p>New recipe added</p>'; } else { exit('<p>Error adding new recipe: ' . mysql_error() . '</p>'); } ?> <?php endif; ?> </body> </html> Here is "searchrecipe.php" (I don't have problem with this one either. As far as I know) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $dbcnx = @mysql_connect('localhost', 'root', ''); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('recipetime')) { exit('<p>Unable to locate the recipe ' . 'database at this time.</p>'); } ?> <form id="form1" name="form1" method="post" action="reciperesults.php"> <label><strong>SEARCH RECIPE</strong><br /> <br /> </label> <p>Country<br /> <label> <select name="country" id="country"> <option>USA</option> <option>CANADA</option> <option>ENGLAND</option> </select> </label> </p> <p>Type of Food <br /> <label> <select name="typeoffood" id="typeoffood"> <option>DESERT</option> <option>ENTREE</option> <option>SPICY</option> </select> </label> </p> <p> <label> <input type="submit" name="Search" id="Search" value="Search" /> </label> </p> </form> </body> </html> Now I don't know how to make this file "reciperesult.php" Can anybody help. Thanks a lot. [attachment deleted by admin]
  9. This is on my computer not on the website. I solved the problem. I had to change the password in config file too. Thanks anyway.
  10. Hi Guys, (I am as new as it can get) There was no password for mysql and I changed mysql password from phpmyadmin and I made localhost root mypasswd The things is now I can not access phpmyadmin. It gives this error: Error MySQL said: Documentation #1045 - Access denied for user 'root'@'localhost' (using password: NO) Obviously phpmyadmin is still trying to use "using password: NO". But since I changed mysql password to "mypasswd" it doesn't open. How will I open Phpmyadmin window? I don't even know how to change the password from mysql console. Can you help? Thanks in advance.
×
×
  • 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.