Jump to content


Photo

simple question - passing data from form to results page


  • Please log in to reply
4 replies to this topic

#1 87dave87

87dave87
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 21 September 2006 - 10:16 PM

Hi,

This is my input page:-

<form method="POST" action="searchresults.php">
  <p>
  <input type="text" name="emusearch" size="20"><input type="submit" value="Submit" name="B1"></p>
</form>

This is my results page: -

<?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";
}
?>

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)?

#2 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 21 September 2006 - 10:26 PM

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 page

now correct me if im wroung i havnt been doing php for a while

the $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";



#3 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 21 September 2006 - 10:27 PM

Try this

<?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";
}
?>


#4 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 21 September 2006 - 10:37 PM

but if there is no info then it will error up so try

<?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";
}
?>


#5 87dave87

87dave87
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 22 September 2006 - 09:25 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users