Page 1 of 1

php mysql search form

Posted: Tue Oct 14, 2008 1:26 pm
by hakmir
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 :lol: ). 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)

Code: Select all

<!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 recipe ' . '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)

Code: Select all

<!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.
I just prepared this on html just to show you what I am trying to do. It is not working of course. But I don't know how to make this reciperesult.php form.
I just prepared this on html just to show you what I am trying to do. It is not working of course. But I don't know how to make this reciperesult.php form.
reciperesults.jpg (67.45 KiB) Viewed 103 times
This is submitrecipe.php, I don't have any problem with this file.
This is submitrecipe.php, I don't have any problem with this file.
submitrecipe.jpg (14.39 KiB) Viewed 102 times