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
ice-o
Forum Newbie
Posts: 1 Joined: Sun Mar 13, 2005 11:00 am
Post
by ice-o » Sun Mar 13, 2005 11:04 am
It automatically just displays the first line out of the table and that's it, i can't search, nuthing!
Code: Select all
<?php
require("config.php");
echo"
<form action=\"$_PHPSELF\" method=\"post\">
<input type=\"text\" name=\"searchterm\"><br/>
<input type=\"Submit\" value=\"Update\">
</form>";
$searchterm = $_GET['searchterm'];
$query = "SELECT content, title FROM pages WHERE content LIKE '%$searchterm%' OR title LIKE '%$searchterm%'";
$result = mysql_query($query);
if (!isset($_GET['submit']))
{
$row = mysql_fetch_array($result);
$content = $row['content'];
$title = $row['title'];
echo "$content";
echo "$title";
}
else {
echo "standard";
}
?>
feyd | Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Mar 13, 2005 11:15 am
your form uses POST, you are looking for $_GET['submit'] which will not exist. $_POST['Submit'] will, but you shouldn't check for it, as IE at least will not submit the button if someone hit enter in the text field.
$_PHPSELF doesn't exist. $PHP_SELF may.. $_SERVER['PHP_SELF'] does.
your query will potentially return multiple records. A loop is required to get all the records found. Not just asking for an array (mysql_fetch_array() returns a single record, at most.)
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Mar 13, 2005 3:18 pm
ice-o made a new thread for this by mistake..
ice-o wrote: Code: Select all
<?php
require("config.php");
echo"
<form action="$PHP_SELF" method="post">
<input type="text" name="searchterm"><br/>
<input type="Submit" value="Update">
</form>";
$searchterm = $_GET['searchterm'];
$query = "SELECT content, title FROM pages WHERE content LIKE '%$searchterm%' OR title LIKE '%$searchterm%'";
$result = mysql_query($query);
if (isset($_POST['submit']))
{
$row = mysql_fetch_array($result);
$content = $row['content'];
$title = $row['title'];
echo "$content";
echo "$title";
}
else {
echo "standard";
}
?>
this looks exactly like your first post..
brad7451
Forum Newbie
Posts: 4 Joined: Sat Mar 12, 2005 1:03 am
Post
by brad7451 » Sun Mar 13, 2005 3:32 pm
Code: Select all
<?php
require("config.php");
echo"<form action=\".$_SERVER['PHP_SELF']."\" method=\"post\">
<input type=\"text\" name=\"searchterm\"><br/>
<input type=\"hidden\" name=\"posted\" value=\"true\">
<input type=\"Submit\" value=\"Update\">
</form>";
$searchterm = $_POST['searchterm'];
$query = mysql_query("SELECT content, title FROM pages WHERE content LIKE '%$searchterm%' OR title LIKE '%$searchterm%'");
if(isset($_POST['posted'])) {
while($result=mysql_fetch_array($query)) {
$content = $result['content'];
$title = $result['title'];
echo $content."<BR>";
echo $title."<BR><BR>";
}
}
?>
feyd | Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]