Jump to content

SEARCH ENGINE CODE (PHP) I NEED HELP!


GPCoin

Recommended Posts

I need some help with a php code I made for a search engine which I will use on my site, but an error code comes up please help me im ok at php but i need some pointers on my code!

 

CODE:

 

<?php

$button = $GET_['submit'];

$search = $GET_['search'];



if (!$button)

   echo "Please enter a keyword!";

else

{

    if (strlen($search)<2)

             echo "search term to short"

      else

      {   

            echo "you searched for $search <hr size='1'>"

       }

        mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","81834567");

        mysql_select_db("seanhall_search");

      



         

              $search_exploded = explode(" ",$search)



              foreach($search_exploded as $search_each)

              {



                   $x++;

                   if ($x==1)

                      $construct .= "keywords LIKE '%$search_each%'";

                   else

                      $construct .= " OR keywords LIKE '%$search_each%'";

              }





        $construct = "SELECT * FROM searchengine WHERE $construct";

        

        echo $construct;

        $run = mysql_query($construct);

        

        $found = mysql_num_rows($run)



        if ($found==0)

           echo "No results Found.";

        else

        {

            echo  "$foundnum results found!<p>";



          while ($runrows = mysql_fetch_assoc($run))

          {

           $title = $runrows['title'];

           $desc = $runrows['description'];

           $url = $runrows['url']

           

           echo "

            <b>$title</b><br>

            $desc<br>

            <a herf='$url'>$url</a><br>

           ";



          }

    }

}

?>

error:

 

Parse error: syntax error, unexpected T_ELSE, expecting ',' or ';' in /home/seanhall/public_html/search.php on line 11

 

Help

Link to comment
Share on other sites

You had a lot of brackets missing and also semicolons, try this and double check your brackets as how to group your else.

 

<?php

$button = $GET_['submit'];
$search = $GET_['search'];

if (!$button) {
echo "Please enter a keyword!";
} else {
if (strlen($search)<2){
echo "search term to short";
} else {   
echo "you searched for $search <hr size='1'>";
}

        mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","81834567");

        mysql_select_db("seanhall_search");

$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each) {
$x++;
if ($x==1) {
$construct .= "keywords LIKE '%$search_each%'";
} else {
$construct .= " OR keywords LIKE '%$search_each%'";
}
$construct = "SELECT * FROM searchengine WHERE $construct";
echo $construct;
$run = mysql_query($construct);
$found = mysql_num_rows($run);
if ($found==0) {
echo "No results Found.";
} else {
echo  "$foundnum results found!<p>";

         while ($runrows = mysql_fetch_assoc($run)) {

           $title = $runrows['title'];

           $desc = $runrows['description'];

           $url = $runrows['url'];

           

           echo "

            <b>$title</b><br>

            $desc<br>

            <a herf='$url'>$url</a><br>

           ";



          }

    }

}

?>

Link to comment
Share on other sites

well it works but once again a new error but now when you enter anything it says "please enter a keyword" even thougth i have, can you see anything which will cause it to KEEP doing it.

 

<?php

$button = $GET_['submit'];
$search = $GET_['search'];

if (!$button) {
echo "Please enter a keyword!";
} else {
if (strlen($search)<2){
echo "search term to short";
} else {   
echo "you searched for $search <hr size='1'>";
}

        mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","*********");

        mysql_select_db("seanhall_search");

$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each) {
$x++;
if ($x==1) {
$construct .= "keywords LIKE '%$search_each%'";
} else {
$construct .= " OR keywords LIKE '%$search_each%'";
}
$construct = "SELECT * FROM searchengine WHERE $construct";
echo $construct;
$run = mysql_query($construct);
$found = mysql_num_rows($run);
if ($found==0) {
echo "No results Found.";
} else {
echo  "$foundnum results found!<p>";

         while ($runrows = mysql_fetch_assoc($run)) {

           $title = $runrows['title'];

           $desc = $runrows['description'];

           $url = $runrows['url'];

           

           echo "

            <b>$title</b><br>

            $desc<br>

            <a herf='$url'>$url</a><br>

           ";



          }

    }

}

}

?>

Link to comment
Share on other sites

not to be a pain but can you put it in this code because I don't know how to echo a button. sorry.

 

code:

  <form action="search.php" method="get" >
<front face='sans-serif' size=5>
<center>
Search Engine<br />
<input name="textfield" type="text" id="textfield" size="40" />
<input type='submit' name='search' value='submit'>
<center>
<font>
</form>

Link to comment
Share on other sites

All you really need to do is use the one and not the button.

 

<?php

$search = $GET_['search'];

if (!isset($search)) {
echo "Please enter a keyword!";
} else {
if (strlen($search)<2){
echo "search term to short";
} else {   
echo "you searched for $search <hr size='1'>";
}

        mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","*********");

        mysql_select_db("seanhall_search");

$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each) {
$x++;
if ($x==1) {
$construct .= "keywords LIKE '%$search_each%'";
} else {
$construct .= " OR keywords LIKE '%$search_each%'";
}
$construct = "SELECT * FROM searchengine WHERE $construct";
echo $construct;
$run = mysql_query($construct);
$found = mysql_num_rows($run);
if ($found==0) {
echo "No results Found.";
} else {
echo  "$foundnum results found!<p>";

         while ($runrows = mysql_fetch_assoc($run)) {

           $title = $runrows['title'];

           $desc = $runrows['description'];

           $url = $runrows['url'];

           

           echo "

            <b>$title</b><br>

            $desc<br>

            <a herf='$url'>$url</a><br>

           ";



          }

    }

}

}

?>

Link to comment
Share on other sites

i used your code and eddited it down and i think i have got it working with one slight hitch

 

here is the error:

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'seanhall_seanhal'@'free.monkeyserve.com' (using password: YES) in /home/seanhall/public_html/search.php on line 8

 

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'seanhall'@'localhost' (using password: NO) in /home/seanhall/public_html/search.php on line 10

 

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/seanhall/public_html/search.php on line 10

SELECT * FROM searchengine WHERE keywords LIKE '%%'

Warning: mysql_query() [function.mysql-query]: Access denied for user 'seanhall'@'localhost' (using password: NO) in /home/seanhall/public_html/search.php on line 23

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/seanhall/public_html/search.php on line 23

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/seanhall/public_html/search.php on line 24

 

would this be caused by the lack of $search = $button_['submit'];

or beause ive done this with the code:

 

<?php

$search = $GET_['search'];


echo "you searched for $search <hr size='1'>";

        mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","********");

        mysql_select_db("seanhall_search");

$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each) {
$x++;
if ($x==1) {
$construct .= "keywords LIKE '%$search_each%'";
} else {
$construct .= " OR keywords LIKE '%$search_each%'";
}
$construct = "SELECT * FROM searchengine WHERE $construct";
echo $construct;
$run = mysql_query($construct);
$found = mysql_num_rows($run);
if ($found==0) {
echo "No results Found.";
} else {
echo  "$foundnum results found!<p>";

         while ($runrows = mysql_fetch_assoc($run)) {

           $title = $runrows['title'];

           $desc = $runrows['description'];

           $url = $runrows['url'];

           

           echo "

            <b>$title</b><br>

            $desc<br>

            <a herf='$url'>$url</a><br>

           ";



          }

    }

}

?>

Link to comment
Share on other sites

ahh, i see now

 

textfield=funny&search=search

 

you have 2 gets, so rename textfield to search and just use that in your form

 

try this

<form action="search.php" method="get">
<font face='sans-serif' size=5>
<center>
Search Engine<br />
<input type="text" name="search" id="search" size="40"/>
<input type="submit" />
<center>
</font>
</form>

Link to comment
Share on other sites

ok back to basics, try this link and do a search, then will see the results would show same page and everything works as it should. The code displays after the search is submitted.

http://get.blogdns.com/sample-search.php

 

Here's the code for it anyway.

<form action="" method="get">
Search: <input type="text" name="search" />
<input type="submit" value="Search"/>
</form>

<?php
$search = mysql_real_escape_string($_GET['search']);

if (!isset($search) OR $search == "") {
echo "Enter a search word";
} else {
echo "<h2>$search</h2>";
}
echo "<br />";
?>

 

This line targets results same page as script

<form action="" method="get">

 

otherwise you can do to target the different page

<form action="search.php" method="get">

Link to comment
Share on other sites

I saw you had this

http://www.gpcoin.monkeyserve.com/search.php?textfield=test&search=search

 

so in your form you have the get value as textfield, but in your code you are looking for get values of search.

 

so use the example of the form i gave in that code and try it

 

What I'm saying is you never had any values for $_GET['search'] because your form never sends any

Link to comment
Share on other sites

ok, here are the codes

 

search form:

<div id="apDiv3">
<form action="search.php" method="get">
Search: 
  <input type="text" name="search" />
<input type="submit" value="Search"/>
</form>
  </iframe>
</div>

 

Search

<?php

$search = $GET_['search'];

if (!isset($search)) {
echo "Please enter a keyword!";
} else {
if (strlen($search)<2){
echo "search term to short";
} else {   
echo "you searched for $search <hr size='1'>";
}

        mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_search","*******");

        mysql_select_db("seanhall_search");

$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each) {
$x++;
if ($x==1) {
$construct .= "keywords LIKE '%$search_each%'";
} else {
$construct .= " OR keywords LIKE '%$search_each%'";
}
$construct = "SELECT * FROM searchengine WHERE $construct";
echo $construct;
$run = mysql_query($construct);
$found = mysql_num_rows($run);
if ($found==0) {
echo "No results Found.";
} else {
echo  "$foundnum results found!<p>";

         while ($runrows = mysql_fetch_assoc($run)) {

           $title = $runrows['title'];

           $desc = $runrows['description'];

           $url = $runrows['url'];

           

           echo "

            <b>$title</b><br>

            $desc<br>

            <a herf='$url'>$url</a><br>

           ";



          }

    }

}

}

?>

 

I hope you can fix it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.