0

Can someone look at this and tell my why it's not working like it should? It gets the data from the database fine, just wont post to search.php

<?php

 
//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("localhost","root",""); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("test1") or die("Unable to select database"); //select which database we're using


$sql="SELECT LastName, FirstName FROM persons";
$result=mysql_query($sql);

$optionsfname="";
$optionslname="";

while ($row=mysql_fetch_array($result)) {

    $id=$row["ID"];
    $fname=$row["FirstName"];
	$lname=$row["LastName"];
   $optionsfname.="<OPTION VALUE=\"$id\">".$fname.'</option>';
   $optionslname.="<OPTION VALUE=\"$id\">".$lname.'</option>';

}

?>


<form action="search.php" method="GET">

<select name="name">
<OPTION VALUE=0>First Name
<?=$optionsfname?>
</SELECT>
<input type="Submit" value="Search"/>
</form>

search.php

<?php

  // Get the search variable from URL
  $varfname = @$_GET['fname'] ;
  $varname = @$_GET['name'] ;
  $trimmedfname = trim($varfname);
  $trimmedname = trim($varname); //trim whitespace from the stored variable
// rows to return
$limit=50; 

// check for an empty name and display a message.
if ($trimmedname  == "") 
  {
  echo "<p>A last name is required...</p>";
  exit;
  }

When I click submit it gives me the message A last name is required.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by nicholaslee21
0

try this you for got the "l" in front of lnames

<?php

  // Get the search variable from URL
  $varfname = @$_GET['fname'] ;
  $varlname = @$_GET['lname'] ;
  $trimmedfname = trim($varfname);
  $trimmedname = trim($varlname); //trim whitespace from the stored variable
// rows to return
$limit=50; 

// check for an empty name and display a message.
if ($trimmedname  == "") 
  {
  echo "<p>A last name is required...</p>";
  exit;
  }

Edited by ApocDen: n/a

0

try this you for got the "l" in front of lnames

<?php

  // Get the search variable from URL
  $varfname = @$_GET['fname'] ;
  $varlname = @$_GET['lname'] ;
  $trimmedfname = trim($varfname);
  $trimmedname = trim($varlname); //trim whitespace from the stored variable
// rows to return
$limit=50; 

// check for an empty name and display a message.
if ($trimmedname  == "") 
  {
  echo "<p>A last name is required...</p>";
  exit;
  }

Thanks for your reply! Again!

I intentionally did that, varname and trimmedname = last name. Only last name is required. I added the first name option later on.

Is the form inside the form tags correct?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.