mslauren Posted August 15, 2010 Share Posted August 15, 2010 Hi, I have a basic php code that allows the user to search and display data from a database. I have searched and searched the entire code for errors, but I cannot find any. When I try to run the code (do a search) it gives me this error: Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' on line 99 This is my line 99: echo ' <a href="'.$_SERVER['PHP_SELF']."?s=$news&q=$var\">Next 10 >></a>"; and this is my whole code: <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("localhost","xxxxxx","xxxxx"); mysql_select_db("xxxxxx") or die("Unable to select database"); // Build SQL Query $query = "SELECT lastname, firstname, state, zip, jobtype, otherjobtype, nightavail, weekendavail, ptft, objective, resume FROM data WHERE jobtype LIKE '%" . $trimmed . "%' ORDER BY lastname"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; // google echo "<p><a href='http://www.google.com/search?q=". $trimmed . "' target='_blank' title='Look up " . $trimmed . " on Google'>Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["1st_field"]; echo "$count.) $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { $prevs=($s-$limit); print ' <a href="'.$_SERVER['PHP_SELF'].'?s=$prevs&q=$var"><< Prev 10</a>  '; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo ' <a href="'.$_SERVER['PHP_SELF']."?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> I am completely new to php. If anyone could give me a hint I'd greatly appreciate it... Link to comment https://forums.phpfreaks.com/topic/210800-unexpected-t_lnumber/ Share on other sites More sharing options...
teynon Posted August 15, 2010 Share Posted August 15, 2010 You have some crazy strings going here: echo ' <a href="'.$_SERVER['PHP_SELF']."?s=$news&q=$var\">Next 10 >></a>"; Try echo " <a href=\"{$_SERVER['PHP_SELF']}?s={$news}&q={$var}\">Next 10>></a>"; Link to comment https://forums.phpfreaks.com/topic/210800-unexpected-t_lnumber/#findComment-1099619 Share on other sites More sharing options...
kickstart Posted August 15, 2010 Share Posted August 15, 2010 Hi I have tried to run your script there are didn't get any initial errors like that (just runtime ones as I hadn't set the table up). Are you sure that is the script that is giving you the error? All the best Keith Link to comment https://forums.phpfreaks.com/topic/210800-unexpected-t_lnumber/#findComment-1099624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.