LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 09-04-2010, 04:06 AM   #1
zev42
LQ Newbie
 
Registered: Sep 2010
Distribution: Unbuntu 10.04
Posts: 18

Rep: Reputation: 0
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 05:21 AM. Reason: added code tags :P
 
Old 09-04-2010, 04:59 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
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 05:01 AM.
 
Old 09-04-2010, 05:33 AM   #3
zev42
LQ Newbie
 
Registered: Sep 2010
Distribution: Unbuntu 10.04
Posts: 18

Original Poster
Rep: Reputation: 0
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!!
 
Old 09-04-2010, 05:44 AM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
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 05:49 AM. Reason: Added PS and PPS
 
Old 09-04-2010, 06:08 AM   #5
zev42
LQ Newbie
 
Registered: Sep 2010
Distribution: Unbuntu 10.04
Posts: 18

Original Poster
Rep: Reputation: 0
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Another PHP parse error hiddenmirageads Programming 3 08-25-2009 10:39 PM
What's the meaning of "PHP Parse error: parse error, unexpected $ in..." frandalla Programming 23 03-04-2009 01:34 PM
PHP Error Parse error: parse error, unexpected $ in /home/content/S/k/i/SkinCare4U/h CowanServices Programming 2 12-09-2008 09:26 PM
PHP parse error in config.inc.php.in Confusedious Linux - Software 2 11-03-2005 06:08 AM


All times are GMT -5. The time now is 10:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration