Jump to content

Archived

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

87dave87

simple question - passing data from form to results page

Recommended Posts

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

Share this post


Link to post
Share on other sites
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";

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.