Re: search form w/ multiple fields

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




since: <?php echo $_POST['firstname']; ?> does not work on your installation, try: <?php echo $GLOBALS['HTTP_POST_VARS']['firstname']; ?> when the form is submitted.

there is an obvious oversight in the SQL query below. You are currently checking whether or not the firstname, lastname, phone or email data from the form is present in only the firstname field.

also, an elegant solution would be to build the SQL query based on which form fields have been populated.



Vincent Jordan wrote:
I have a form with firstname, lastname, phone, and email fields. I would
like to search the database and return results to the same page in an
iframe. I want to be able to search my just one or multiple. For example
I can search by "firstname" with value of "john" and it will return all
"john" rows in iframe or search "firstname" value "john" and "lastname"
value "smith" and again will return all rows with data in iframe. I have tried this but don't think I am doing something correct:
$result = mysql_query ("select * from customerinfo where firstname like
'%".$_POST['firstname']."%' or '%".$_POST['lastname']."%' or
'%".$_POST['phone']."%' or '%".$_POST['email']."%'");
I cant seem to figure out how to display. I have tried <?php echo
$_POST['firstname']; ?> in the HTML but there was no return of data. This is my form:
<form action="search.php" method="post" name="search" id="search">
First Name: <input type="text" name="firstname" />
Last Name: <input type="text" name="lastname" />
Phone : <input type="text" name="phone" />
Email : <input type="text" name="email" />
<input type="submit" value="search">
</form>
all of this is on the same page, the page is called search.php



--

_________________
Matthew McNicol

yellowmarker.co.uk
PHP / MySQL web development

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux