drumhrd Posted April 21, 2009 Share Posted April 21, 2009 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 More sharing options...
AE117 Posted April 21, 2009 Share Posted April 21, 2009 dont use the () around the name that will go for require once as well so include 'db_login.php'; Link to comment https://forums.phpfreaks.com/topic/154984-solved-unexpect-t_functionplease-help/#findComment-815194 Share on other sites More sharing options...
WolfRage Posted April 21, 2009 Share Posted April 21, 2009 Use the code tags so we can read the code easier. Thanks. Link to comment https://forums.phpfreaks.com/topic/154984-solved-unexpect-t_functionplease-help/#findComment-815195 Share on other sites More sharing options...
PFMaBiSmAd Posted April 21, 2009 Share Posted April 21, 2009 Posting your code with line numbers also prevents someone from easily trying to duplicate the problem. Link to comment https://forums.phpfreaks.com/topic/154984-solved-unexpect-t_functionplease-help/#findComment-815196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.