Kay1021 Posted May 2, 2008 Share Posted May 2, 2008 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 More sharing options...
blackcell Posted May 2, 2008 Share Posted May 2, 2008 <?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 More sharing options...
Kay1021 Posted May 2, 2008 Author Share Posted May 2, 2008 thank you so much for the help. that looks like what i need... but i do need help with sset $_POST['submit] and forms...i'm having a little trouble getting it to work. Thanks again. Link to comment https://forums.phpfreaks.com/topic/103816-searchinghelp-please/#findComment-531499 Share on other sites More sharing options...
blackcell Posted May 2, 2008 Share Posted May 2, 2008 Post what you got. Link to comment https://forums.phpfreaks.com/topic/103816-searchinghelp-please/#findComment-531682 Share on other sites More sharing options...
Kay1021 Posted May 2, 2008 Author Share Posted May 2, 2008 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 More sharing options...
blackcell Posted May 2, 2008 Share Posted May 2, 2008 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 More sharing options...
Kay1021 Posted May 2, 2008 Author Share Posted May 2, 2008 I still can't seem to get this working.. what's the best way to connect to your database? Link to comment https://forums.phpfreaks.com/topic/103816-searchinghelp-please/#findComment-531962 Share on other sites More sharing options...
DarkWater Posted May 2, 2008 Share Posted May 2, 2008 Read more on PHP's MySQL Support. Check it out. And use mysql_connect, by the way. Link to comment https://forums.phpfreaks.com/topic/103816-searchinghelp-please/#findComment-531980 Share on other sites More sharing options...
Kay1021 Posted May 5, 2008 Author Share Posted May 5, 2008 I think i've connected properly but it still won't produce results. Im basically wanting to create something similar to a catalog ... very simple...does anyone know of any tutorials maybe? Thank you for any help Link to comment https://forums.phpfreaks.com/topic/103816-searchinghelp-please/#findComment-533157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.