Forum Moderators: coopster
The problem is that the search form immediatly displays resetted and there is no output even if i search for a correct data.
I have tried for two days now and can't get it to work. Maybe someone has an idea. Here is the code:
<?PHPINCLUDE 'db.php';
IF(!empty($_POST['select'])) {
$sql = mysql_query("SELECT first_name, last_name, ".$_POST['extrafield']." FROM users
WHERE ".$_POST['search']." LIKE '%".$_POST['extrafield']."%'");WHILE ($row = mysql_fetch_array($sql)) {?>
<HTML>
<HEAD></HEAD>
<BODY><DIV ALIGN=center>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="1">
<TR>
<TD ALIGN=left BGCOLOR=#1A5D15><?php ECHO $row["first_name"];?></TD>
<TD ALIGN=left BGCOLOR=#1A5D15><?php ECHO $row["last_name"];?></TD>
<TD ALIGN=left BGCOLOR=#1A5D15><?php ECHO $row["extrafield"];?></TD>
</TR>
</TABLE>
</DIV><? mysql_close($connection);
}}
ELSE {?>
<FORM ACTION="testsearch.php" METHOD="post">
<DIV ALIGN=center>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="1">
<TR><TD>Choose Field: <SELECT NAME="extrafield">
<OPTION VALUE="id">ID</option>
<OPTION VALUE="email_address">E-Mail</option>
<OPTION VALUE="username">User</option>
<OPTION VALUE="password">PW</option>
</SELECT>
Search For: <INPUT TYPE="text" NAME="search"></TD></TR>
<TR><TD><INPUT TYPE="submit" NAME="Select"></TD></TR>
</TABLE>
</DIV>
</FORM><? }?>
</BODY>
</HTML>
Any help is welcome
Malle
[edited by: jatar_k at 7:40 am (utc) on Nov. 6, 2004]
[edit reason] no personal urls thanks [/edit]
Try echoing your query to see exactly whats it is saying:
$sql = mysql_query("SELECT first_name, last_name, ".$_POST['extrafield']." FROM users WHERE ".$_POST['search']." LIKE '%".$_POST['extrafield']."%'");
echo $sql;
exit;
Should this:
WHERE ".$_POST['search']." LIKE '%".$_POST['extrafield']."%'");
actually be this:
WHERE ".$_POST['extrafield']." LIKE '%".$_POST['search']."%'");
dc :)
Then i tried following and didnt get a result back (also no error message)
<?PHPINCLUDE 'db.php';
$sql = mysql_query("SELECT first_name, last_name, ".$_POST['extrafield']." FROM users
WHERE ".$_POST['extrafield']." LIKE '%".$_POST['search']."%'");echo $sql;
exit;?>
Somehow it seems as if the IF condition never takes place. But i just don't know why.
I would write more to the problem if i knew what it was about. Till then i have to rely on you people out there to put me in the right direction :)
Thx for trying to help me
Malle
I am sure it will help.
------------------
If it doesn't resolve the problem, than you can use a hidden value in your form :
<INPUT name='step' type='hidden' value='1'>
Just retrieve the data using PHP_POST and change your if statement to :
if ($step=="1") {blah blah}
Firstly, change
<INPUT TYPE="submit" NAME="Select">
to
<INPUT TYPE="submit" NAME="select">I am sure it will help.
Nope didn't help. Maybe i have to put in value as well? will try later....
If it doesn't resolve the problem, than you can use a hidden value in your form :
<INPUT name='step' type='hidden' value='1'>Just retrieve the data using PHP_POST and change your if statement to :
if ($step=="1") {blah blah}
This did the job. Thanks very much, you are the best :)
Even tho i still don't know why it didn't work the other way round...but i couldn't care less atm ;)
You saved my day
Malle