87dave87 Posted September 21, 2006 Share Posted September 21, 2006 Hi,This is my input page:-[code]<form method="POST" action="searchresults.php"> <p> <input type="text" name="emusearch" size="20"><input type="submit" value="Submit" name="B1"></p></form>[/code]This is my results page: -[code]<?php $database="mydatabase"; mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database");$sql = mysql_query("select * from windows_atari2600 where emulator = '" print_r($_POST); "'");while ($get_info = mysql_fetch_row($sql)) { echo "<tr>"; foreach ($get_info as $field) echo "<td>$field</td>\n"; echo "</tr>\n";}?>[/code]I am trying to pass the variable entered into the text box on the first page to match the name typed to the actual name. See: select * from windows_atari2600 where emulator = '" print_r($_POST); "'"); The end part isn't working where I am trying to make the passed variable appear to match the emulator names?What is the code to include data from the previous form onto the results page?Also do I need to connect to my database on the search (first page)? Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted September 21, 2006 Share Posted September 21, 2006 now seeing as the name of the textbox is emusearch it would be $_POST['emusearch']you dont have to connect to the db on the first pagenow correct me if im wroung i havnt been doing php for a whilethe $field is the info you searching for and the $get_info is the info your searching through if so then put $field = $_POST['emusearch'];b4 the $database="mydatabas"; Quote Link to comment Share on other sites More sharing options...
php_b34st Posted September 21, 2006 Share Posted September 21, 2006 Try this[code]<?php $database="mydatabase";$emusearch = $_POST['emusearch'];mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database");$sql = mysql_query("select * from windows_atari2600 where emulator = '$emusearch'");while ($get_info = mysql_fetch_row($sql)) { echo "<tr>"; foreach ($get_info as $field) echo "<td>$field</td>\n"; echo "</tr>\n";}?>[/code] Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted September 21, 2006 Share Posted September 21, 2006 but if there is no info then it will error up so try[code]<?php $database="mydatabase";$emusearch = $_POST['emusearch'];mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database");$sql = mysql_query("select * from windows_atari2600 where emulator = '$emusearch'");if(isset($sql)){while ($get_info = mysql_fetch_row($sql)) { echo "<tr>"; foreach ($get_info as $field) echo "<td>$field</td>\n"; echo "</tr>\n";}}else{ echo "<tr>"; echo "We cannot find your infomation."; echo "</tr>\n";}?>[/code] Quote Link to comment Share on other sites More sharing options...
87dave87 Posted September 22, 2006 Author Share Posted September 22, 2006 ok, will try these when I get home.Also wondering: -How can I search every table in my database?&How can I make it so the query looks for partial matches. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.