Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
09-04-2010, 03:06 AM
#1
LQ Newbie
Registered: Sep 2010
Distribution: Unbuntu 10.04
Posts: 18
Rep:
php parse error
I too hit a brick wall with a parse error, but it was over a search engine php, so a ton of code to un ravel, being in php by only 4 days, i figured i'd take it to an expert heres the code:
Code:
<?php
$submit = $_POST["submit"];
$keywords = $_POST["keywords"];
if(isset($submit) || isset($keywords))
{
doSearch($keywords);
}
else
{
getKeywords();
}
function getKeywords()
{
?>
<html>
<head>
<title> Enter Search Keywords </title>
</head>
<body bgcolor="#000000">
<form name="frmKW" action="srh.php" method="post">
<input type="text" name="keywords" maxlength="100" border="#ff6600">
<input type="submit" name="submit" value="Search" bgcolor="#222222" border="#ff6600">
</form>
</body>
</html>
<?php
}
{
}
function doSearch($search_keywords)
{
$arrWords = explode(" ", $search_keywords);
if(sizeof($arrWords) == 0 || $search_keywords == "")
{
echo "search for blank engaged<br>";
echo "<a href='searchdocs.php'>Go Back</a>";
}
else
{
// Connect to the database
$dServer = "localhost";
$dDb = "content";
$dUser = "admin";
$dPass = "password";
$s = @mysql_connect($dServer, $dUser, $dPass)
or die("Couldn't connect to database server");
@mysql_select_db($dDb, $s)
or die("Couldn't connect to database");
for($i = 0; $i < sizeof($arrWords); $i++)
{
$query = "select articleIds from searchWords where word = '{$arrWords[$i]}'";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0)
{
// Get the id's of the articles
$row = mysql_fetch_array($result);
$arrIds = explode(",", $row[0]);
$arrWhere = implode(" OR articleId = ", $arrIds);
$aQuery = "select articleId, title, left(content, 100) as summary from articles where articleId = " . $arrWhere;
$aResult = mysql_query($aQuery);
$count = 0;
$articles = array();
if(mysql_num_rows($aResult) > 0)
{
while($aRow = mysql_fetch_array($aResult))
{
$articles[$count] = array (
"articleId" => $aRow["articleId"],
"title" => $aRow["title"],
"summary" => $aRow["summary"]
);
$count++;
}
}
if(isset($articles))
{
$articles = array_unique($articles);
echo "<h1>" . sizeof($articles);
echo (sizeof($articles) == 1 ? " article" : " articles");
echo " found:</h1>";
foreach($articles as $a => $value)
{
?>
<a href="article.php?articleId=<?php echo $articles[$a]["articleId"]; ?>">
<b><u><?php echo $articles[$a]["title"]; ?></u></b>
</a>
<br><?php echo $articles[$a]["summary"] . "..."; ?>
<br>
<a href="article.php?articleId=<?php echo $articles[$a]; ?>">
http://www.mysite.com/article.php?articleId=<?php echo $articles[$a]["articleId"]; ?>
</a>
<br><br>
<?php
}
}
else
{
echo "No results found for '$search_keywords'<br>";
echo "<a href='searchdocs.php'>Go Back</a>";
}
}
}
}
?>
Last edited by zev42; 09-04-2010 at 04:21 AM .
Reason: added code tags :P
09-04-2010, 03:59 AM
#2
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794
Please post your code between [code] and [/code] tags. It makes it far easier to read as it will maintain indentations.
Below my attempt to get YOUR indentations right; I might have made a mistake.
Code:
<?php
$submit = $_POST["submit"];
$keywords = $_POST["keywords"];
if(isset($submit) || isset($keywords))
{
doSearch($keywords);
}
else
{
getKeywords();
}
function getKeywords()
{
?>
<html>
<head>
<title> Enter Search Keywords </title>
</head>
<body bgcolor="#000000">
<form name="frmKW" action="srh.php" method="post">
<input type="text" name="keywords" maxlength="100" border="#ff6600">
<input type="submit" name="submit" value="Search" bgcolor="#222222" border="#ff6600">
</form>
</body>
</html>
<?php
}
{
}
function doSearch($search_keywords)
{
$arrWords = explode(" ", $search_keywords);
if(sizeof($arrWords) == 0 || $search_keywords == "")
{
echo "search for blank engaged<br>";
echo "<a href='searchdocs.php'>Go Back</a>";
}
else
{
// Connect to the database
$dServer = "localhost";
$dDb = "content";
$dUser = "admin";
$dPass = "password";
$s = @mysql_connect($dServer, $dUser, $dPass) or die("Couldn't connect to database server");
@mysql_select_db($dDb, $s) or die("Couldn't connect to database");
for($i = 0; $i < sizeof($arrWords); $i++)
{
$query = "select articleIds from searchWords where word = '{$arrWords[$i]}'";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0)
{
// Get the id's of the articles
$row = mysql_fetch_array($result);
$arrIds = explode(",", $row[0]);
$arrWhere = implode(" OR articleId = ", $arrIds);
$aQuery = "select articleId, title, left(content, 100) as summary from articles where articleId = " . $arrWhere;
$aResult = mysql_query($aQuery);
$count = 0;
$articles = array();
if(mysql_num_rows($aResult) > 0)
{
while($aRow = mysql_fetch_array($aResult))
{
$articles[$count] = array (
"articleId" => $aRow["articleId"],
"title" => $aRow["title"],
"summary" => $aRow["summary"]
);
$count++;
}
}
if(isset($articles))
{
$articles = array_unique($articles);
echo "<h1>" . sizeof($articles);
echo (sizeof($articles) == 1 ? " article" : " articles");
echo " found:</h1>";
foreach($articles as $a => $value)
{
?>
<a href="article.php?articleId=<?php echo $articles[$a]["articleId"]; ?>">
<b><u><?php echo $articles[$a]["title"]; ?></u></b>
</a>
<br><?php echo $articles[$a]["summary"] . "..."; ?>
<br>
<a href="article.php?articleId=<?php echo $articles[$a]; ?>">
http://www.mysite.com/article.php?articleId=<?php echo $articles[$a]["articleId"]; ?>
</a>
<br><br>
<?php
}
}
else
{
echo "No results found for '$search_keywords'<br>";
echo "<a href='searchdocs.php'>Go Back</a>";
}
}
}
}
?>
From what I see now, you're missing a curly
Last edited by Wim Sturkenboom; 09-04-2010 at 04:01 AM .
09-04-2010, 04:33 AM
#3
LQ Newbie
Registered: Sep 2010
Distribution: Unbuntu 10.04
Posts: 18
Original Poster
Rep:
wow.. thanks much!
hrmm,
did you add it?
the semantics are wonderous! but im still receiving a error on the final line.. could it also be because most of my pages are .htm's and the article it requests is article.php?
aside, im sorry if i in any way imlied this is MY code or that i constructed it, obvious enough see
it was a public doc tutorial, and i'd just about given up on searchbars lol
again, much thanks for the assitence, i grok your talent!!
09-04-2010, 04:44 AM
#4
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794
No, I did not add it; should be before the last '?>' to close the function doSearch
No, it's not because of php versus htm as you get a parse error indicating that PHP processes it
No, I did not say it was your code although it is the code that you posted and therefore the reference to YOUR
Else it gets to difficult to explain
If you use an editor with syntax highlighting, you might see it.
PS
There is a dedicated
programming section at LQ
PPS
If your problem is solved, please mark it as such using the thread tools just above the first post.
Last edited by Wim Sturkenboom; 09-04-2010 at 04:49 AM .
Reason: Added PS and PPS
09-04-2010, 05:08 AM
#5
LQ Newbie
Registered: Sep 2010
Distribution: Unbuntu 10.04
Posts: 18
Original Poster
Rep:
THANKS MUCH!!
lol, the document reads perfectly, now i have a couldnt connect to database server, dont stress, i can google and check the programming link, thaks again sir!
All times are GMT -5. The time now is 05:06 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News