PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Fri Jan 16, 2004 7:23 pm
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!!!???!?!?!?!?
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Fri Jan 16, 2004 7:25 pm
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 ;
ilovetoast
Forum Contributor
Posts: 142 Joined: Thu Jan 15, 2004 7:34 pm
Post
by ilovetoast » Fri Jan 16, 2004 8:45 pm
Umm... you're checking !isset($_POST['submit'] but your form has method=GET. I changed that and it works for me.
peace
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Fri Jan 16, 2004 9:06 pm
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
DuFF
Forum Contributor
Posts: 495 Joined: Tue Jun 24, 2003 7:49 pm
Location: USA
Post
by DuFF » Fri Jan 16, 2004 10:05 pm
Did you change the if(!isset($_POST['submit'])) to if(!isset($_GET['submit'])) ?
That seems like it would cause those problems. . .
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Fri Jan 16, 2004 10:18 pm
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