How to Pass data from forms without clicking submit
Posted: Mon May 31, 2010 12:53 am
In the code below how can I assign a value to $_POST['name'] even with out clicking the submit botton? So when the page load the $_POST['name'] already has a value that will reflect on the query that will display the data?
I am trying but I can't figure it out.
I am trying but I can't figure it out.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Search Contacts</title>
<style type="text/css" media="screen">
ul li{
list-style-type:none;
}
</style>
</head>
<body>
<h3>Search Contacts Details</h3>
<p>You may search either by first or last name</p>
<form method="post" action="search_display2.php?go" id="searchform">
<input type="text" name="name" >
<input type="submit" name="submit" value="Search">
</form>
<?php
$pangalan=$_POST['name'];
//connect to the database
$db=mysql_connect ("localhost", "root") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("records2");
//-query the database table
//$sql="SELECT id, fname, lname FROM table1 WHERE fname LIKE '%" . $name . "%' OR lname LIKE '%" . $name ."%'";
$sql="SELECT * FROM table1 WHERE fname LIKE '%" . $pangalan . "%' OR lname LIKE '%" . $pangalan ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$FirstName =$row['fname'];
$LastName=$row['lname'];
$PhoneNumber=$row['phone'];
$Email=$row['email'];
$image=$row['imagepath'];
//-display the result of the array
echo "<ul>\n";
echo "<li>Name: " . $FirstName . " " . $LastName . "</li>\n";
echo "<li>" . $PhoneNumber . "</li>\n";
echo "<li>" . "<a href=mailto:" . $Email . ">" . $Email . "</a></li>\n";
echo "</ul>";
echo "<tr>";
echo "<td><img src =\"" . $row['imagepath']."\"></td>";
echo "</tr>";
echo '<td><a href="edit(for_search).php?id=' . $row['id'] . '">Edit</a></td>';
}
?>
</body>
</html>