Jump to content

Searching..Help please!!


Kay1021

Recommended Posts

I'm fairly new to php

 

i have a table with some information about people

 

their name, address, postal code, and website

 

i want the user to be able to enter the site ...and be asked to enter a postal code and then show them all the people who have that postal code

 

I've looked for just simple search to do that...and everything i've found ends up being complex

 

I was wondering if someone would be able to help me with the simplest way to perform this search and output.

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/103816-searchinghelp-please/
Share on other sites

<?php
if(isset($_POST['submit'])){ 
   $currentUser_zip = $_POST['zipcode'];
   $sqlQuery = "SELECT * FROM `table_userInfo` WHERE `userInfo_zip` = '$currentUser_zip'";
   $sqlResult = mysql_query($sqlQuery) or
      die("Could not execute query<br>:" . mysql_error());
    while($row = mysql_fetch_array($sqlResult)){
        $userInfo_Lname= $row["userInfo_Lname"];
        $userInfo_Fname= $row["userInfo_Fname"];
        echo "Found $userInfo_Fname $userInfo_Lname in your zip<br>";
    }
}
?>
Put your input box and submit button here.

If everything is in one table it will be really simple. If you need help with the isset $_POST['submit] and forms let me know. But basically this is the template for what you want to do (I think). You can just store the other information into variables out of the array using the $row["desired_field"] .

Link to comment
https://forums.phpfreaks.com/topic/103816-searchinghelp-please/#findComment-531492
Share on other sites

well from what i've seen online this is what i have

 

<form action="phpsearch.php" method="get">

<input type="text" name="postcode"><br>

<input type="submit" value="Search">

</form>

 

then i put the code you gave me in phpsearch.php

 

if(isset($_POST['submit'])){

  $currentUser_zip = $_POST['postcode'];

  $sqlQuery = "SELECT * FROM `vendor` WHERE `postcode` = '$currentUser_zip'";

  $sqlResult = mysql_query($sqlQuery) or

      die("Could not execute query<br>:" . mysql_error());

    while($row = mysql_fetch_array($sqlResult)){

        $userInfo_Lname= $row["userInfo_Lname"];

        $userInfo_Fname= $row["userInfo_Fname"];

        echo "Found $userInfo_Fname $userInfo_Lname in your zip<br>";

    }

 

}

Link to comment
https://forums.phpfreaks.com/topic/103816-searchinghelp-please/#findComment-531801
Share on other sites

Try:

<form action="phpsearch.php" method="post">
   <input type="text" name="postcode" value="">

   <input type="submit" name="submit" value="Search">
</form>

And make sure that the form action is the same name as the page with this code. You want the action to execute the same page over again.

Link to comment
https://forums.phpfreaks.com/topic/103816-searchinghelp-please/#findComment-531813
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.