Jump to content

[SOLVED] unexpect t_function..please help


drumhrd

Recommended Posts

hello.  I am learning php/mysql.

 

I am trying to build a function to call to perform a database search.

 

I keep getting

 

Parse error: syntax error, unexpected T_FUNCTION in /var/www/db_query.php on line 3

 

I cannot figure out what's wrong. the t_function is usually a missing close bracket or ";" or something like that..I cannot figure out why I am getting this error.

 

 

<?php

2  function query_db($qstring) {

3      include('db_login.php');  //connection details

4      require_once('DB.php');  //PEAR DB

5      $connection = DB::connect("mysql://$db_username:$db_password@$db_host/$db_database");

6

7      if (DB::isError($connection)){  //check for connect errors

8          die ("Could not connect to the database: <br />". DB::errorMessage($connection));

9      }

 

 

10    if (get_magic_quotes_gpc(  )) {  //guard against SQL injection

11        $qstring = stripslashes($qstring);

12    }

13    $qstring = mysql_real_escape_string($qstring);

14    $query = "SELECT title, pages, author_id, author_name FROM books NATURAL JOIN authors WHERE books.title LIKE '%$qstring%'";  //build the query

16    $result = $connection->query($query);

17    if (DB::isError($result)){

18        die("Could not query the database:<br />".$query." ".DB::errorMessage($result));

20    }

21    echo ('<table border="1">');

22    echo "<tr><th>Title</th><th>Author</th><th>Pages</th></tr>";

23    while ($result_row = $result->fetchRow(  )) {

24        echo "<tr><td>";

25        echo $result_row[1] . '</td><td>';

26        echo $result_row[3] . '</td><td>';

27        echo $result_row[2] . '</td></tr>';

28    }

29    echo ("</table>");

30    $connection->disconnect(  );

31 }

32 ?>

 

 

Any help would be great..thanks!

Link to comment
https://forums.phpfreaks.com/topic/154984-solved-unexpect-t_functionplease-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.