Jump to content

simple question - passing data from form to results page


87dave87

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)?
Link to comment
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";

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.