Jump to content

Query form


Codi

Recommended Posts

I have created a small MySQL database named test with FirstName, LastName & Age as the fields.  What I have been trying to do very unsuccessfully is to create a query file that will be the back end of the following:-

 

<html>

<body>

 

 

<form action="results.php" method="post">

First Name: <input type="text" name="FirstName" />

Last Name: <input type="text" name="LastName" />

Age: <input type="text" name="Age" />

<input type="submit" />

</form>

 

</body>

</html>

 

I can get the results.php file to return results when I enter a first name, last name or age in the entry form, but the results.php form only retrieves the the one that I requested (first, last or age).  What I have been trying to do is to get it to retrieve all the information from that record if I only enter the first name or last name or age etc or if I enter any combination of the three.  But regardless of which one or combination I enter, those in particular are all I can get it to return.  I must apologize for being so stupid.  You see I use to be a top notch programmer, then I had a great heart attack and lost most of my long term memory (my coding ability must have been at the top of the list) so now I am trying to get some of it back.  I have been working on this problem for over a week, digging through my books but I haven't come up with a solution so if it isn't too much trouble, possibly you could give me a hand?

Link to comment
Share on other sites

The config file contains

<?php

$dbhost = 'localhost';

$dbname = '****_db';

$dbuser = '****_user';

$dbpass = '*****';

?>

 

[code}<?php

include ("includes/config.php")

 

?>

 

<?php

if (isset($_POST))

{

 

if (isset ($_POST['FirstName']))

{

  $FirstName = addslashes($_POST['FirstName']);

}

if (isset ($_POST['LastName']))

{

  $LastName= addslashes($_POST['LastName']);

}

if (isset ($_POST['Age']))

{

  $Age = addslashes($_POST['Age']);

}

}

?>

 

<?php

 

// Connects to your Database

include 'includes/opendb.php';

mysql_select_db("$dbname") or die(mysql_error());

 

 

 

 

 

 

$result = mysql_query("SELECT * FROM test WHERE FirstName LIKE '$FirstName' AND LastName LIKE '$LastName' AND Age LIKE '$Age'");

 

//And then.....

mysql_query($query, $conn); //And sometimes you have to use your link code in here

 

 

 

 

 

 

?>

 

<html>

<body>

 

<div align="center">

  <center>

  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="274" height="114">

    <tr>

      <td width="274" height="114" align="center" valign="top">

      <p align="left"><?php echo $_POST["FirstName"]; ?> <?php echo $_POST["LastName"]; ?>, You are welcome to join others on this quest.</p>

      <p align="left">Providing that you are at least <?php echo $_POST["Age"]; ?> years old.

</td>

    </tr>

  </table>

  </center>

</div>

 

</body>

</html>

{/code}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.