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
https://forums.phpfreaks.com/topic/76082-query-form/
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
https://forums.phpfreaks.com/topic/76082-query-form/#findComment-385158
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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