Page 1 of 1
[SOLVED] Searching a news database for a string!@#$%^&*
Posted: Fri Jan 16, 2004 7:23 pm
by dull1554
i was wondering if there was a better way to do this? and why it's not working????
Code: Select all
<?php
if(!isset($_POST['submit']))
{
echo "<form method=GET action=search.php>
<input type=text name=string>
<input type=submit value=submit name=submit>
</form>";
}
else
{
include "db.php";
$query = mysql_query( "SELECT * FROM news WHERE subject=$_POST['string'] OR post_text=$_POST['string']" );
$result = mysql_fetch_array($query);
echo $result;
exit;
}
?>
as always any and all help will be greatly appreciated!!!???!?!?!?!?
Posted: Fri Jan 16, 2004 7:25 pm
by dull1554
forgot to tell you guys, when i try it, it does not search the db it just prints out the froum.
Code: Select all
and heres my db setup
CREATE TABLE `news` (
`post_id` int(11) NOT NULL auto_increment,
`subject` varchar(128) default NULL,
`date` varchar(128) default NULL,
`post_text` text,
PRIMARY KEY (`post_id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;
Posted: Fri Jan 16, 2004 8:45 pm
by ilovetoast
Umm... you're checking !isset($_POST['submit'] but your form has method=GET. I changed that and it works for me.
peace
Posted: Fri Jan 16, 2004 9:06 pm
by dull1554
see now when i try it it just says
Code: Select all
Notice: Undefined index: 'string' in c:\program files\apache group\apache\htdocs\test\news\search.php on line 15
Notice: Undefined index: 'string' in c:\program files\apache group\apache\htdocs\test\news\search.php on line 15
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\test\news\search.php on line 16
Posted: Fri Jan 16, 2004 10:05 pm
by DuFF
Did you change the if(!isset($_POST['submit'])) to if(!isset($_GET['submit']))?
That seems like it would cause those problems. . .
Posted: Fri Jan 16, 2004 10:18 pm
by dull1554
yea, i'm not exactly sure what i did but i got it to work and i also made some other mods(beyond making it work)
Code: Select all
<?php
if(!isset($_POST['pass']))
{
echo "<form method=POST action=search.php>
<input type=text name=string>
<input type=hidden name=pass value=pass>
<input type=submit value=submit name=submit>
</form>";
}
elseif(isset($_POST['pass']))
{
include "db.php";
$query = mysql_query("SELECT * FROM news WHERE subject like '%".$_POST['string']."%' OR post_text like '%".$_POST['string']."%'");
$result = mysql_fetch_array($query);
if($result['subject'] == "")
{
echo "your search has returned no results!";
}
else
{
echo "<table>
<tr><td>".$result['subject']." -- ".$result['date']."</td></tr>
<tr><td>".$result['post_text']."</td></tr>
</table><br><br>";
}
exit;
}
else
{
echo "this script failed miserably!?!?!?!?!?!?";
}
?>
do with it what you wish, and thanks for all the help
CONSIDER IT SOLVED