2017-02-25 2 views
-1

Parse error: syntax error, unexpected ';', expecting ',' or ')' in /home/u459249666/public_html/ss/search.php on line 19Php-Fehler: Parse error

$confiq = array(
    'host' => 'localhost', 
      'username' => 'root', 
      'password' => '', 
      'dbname' => 'hunklessons', 
); 

$db = new PDO('mysql:host='.$confiq['host'].';dbname='.$confiq['dbname'],$confiq['username'],$confiq['password'].''); 

if(isset($_GET['s']) && !empty($_GET['s'])) { 

    //secure the search input 
    $search = trim(strip_tags($_GET['s'])); 

    //convert the space in the search to sepreate terms 
    $search_terms = explode(" ", $search); 

    $term_count = 0; 
    $q = ""; 
    $result = array(); 
    $i = 0; 

    foreach ($search_terms as $term) { 
     $term_count++; 
       if($term_count === 1) { 
         $q .= "`title` LIKE '%$term%' "; 
    } else { 
         $q .= "AND `title` LIKE '%$term%' "; 
       } 
    } 

      //prepare the mysql query in PDO 
    $query = $db->query("SELECT * FROM `google_search` WHERE $q"); 

     //get the number of the results found 
    $num = $query->rowCount(); 

    if ($num > 0) { 
     //fetch the result 
    while($row = $query->fetch(PDO::FETCH_ASSOC)){ 
      //put the results in the array 
          $result[$i] =  array(
            'title' => $row['title'], 
            'desc' => $row['description'], 
            'link' => $row['link'] 
         ); 
          $i++; 
       } 
    } 

    //convert result array into json format 
    $json_result = json_encode($result); 

    echo $json_result; 
} 

Auf dieses Skript Laufen Ich erhalte

parse error in line 19

aber ich bin nicht in der Lage zu verstehen, was der Fehler ist, wie kann es korrigiert werden.

Ich habe viel versucht. Da ich Anfänger bin, ist es manchmal sehr verwirrend. Bitte helfen Sie mir

Antwort

0

Sie haben einen Fehler in PHP. Parsen Sie es nicht in HTML-Entität Name

sollte es wie folgt sein.

<?php 

//connect to the db 

$confiq = array(

    'host' => 'localhost', 

    'username' => 'root', 

    'password' => '', 

    'dbname' => 'hunklessons', 

); 



$db = new PDO('mysql:host='.$confiq['host'].';dbname='.$confiq['dbname'],$confiq['username'],$confiq['password'].''); 

?> 



<?php 

if(isset($_GET['s']) && !empty($_GET['s'])){ //<----------- change this line 

    //secure the search input 

    $search = trim(strip_tags($_GET['s'])); //<----------- change this line 



    //convert the space in the search to sepreate terms 

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

    $term_count = 0; 

    $q = ""; 

    $result = array(); 

    $i = 0; 



    foreach ($search_terms as $term) { 

    $term_count++; 

    if($term_count === 1){ 

    $q .= "`title` LIKE '%$term%' "; 

    }else{ 

    $q .= "AND `title` LIKE '%$term%' "; 

    } 

    } 



    //prepare the mysql query in PDO 

    $query = $db->query("SELECT * FROM `google_search` WHERE $q"); 



    //get the number of the results found 

    $num = $query->rowCount(); 



    if($num > 0){ 

    //fetch the result 

    while($row = $query->fetch(PDO::FETCH_ASSOC)){ 

    //put the results in the array 

    $result[$i] = array(

     'title' => $row['title'], 

     'desc' => $row['description'], 

     'link' => $row['link'] 

    ); 

    $i++; 

    } 

    } 



    //convert result array into json format 

    $json_result = json_encode($result); 

    echo $json_result; 

} 

?> 
0

Sie können Werte in $ _GET Array wie folgt erhalten. Befolgen Sie die folgende Methode, wenn Sie den Wert der s-Variablen von $ _GET array

if(isset($_GET['s']) && !empty($_GET['s'])){ 
abrufen möchten
Verwandte Themen