perryub Posted December 12, 2008 Share Posted December 12, 2008 Hi, I am trying to write a script that will display a form in which the user will enter a search string will then be used to search across a few tables. Right now, I'm missing something very small because I get: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /data/9/0/111/137/600626/user/612742/htdocs/EagleEyes/SearchNotFinished.php on line 75 Any help to this very new newbie would be appreciated. Perry <?PHP if (isset($_POST['keyword'])) { // set database server access variables: $host = "123.456.789.10"; $user = "NotMyUserName"; $pass = "NotMyPasswordEither"; $db = "MyDB"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql = "SELECT Students.OEN, Students.LastName, Students.FirstName, Notes.Note FROM Students, Notes WHERE Students.OEN = Notes.OEN AND MATCH (Notes.Note) AGAINST ($_POST['keyword'])"; $result = MySQL_query($sql); } else { echo "<form action='SearchNotWorking.php' method='POST'>"; echo "<input type='text' name='keyword'>"; echo "<input type='submit' value='Search!'>"; echo "</form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/136760-solved-newbie-needs-help-with-forms/ Share on other sites More sharing options...
peranha Posted December 12, 2008 Share Posted December 12, 2008 We need to see the code for this page SearchNotFinished.php on line 75 Quote Link to comment https://forums.phpfreaks.com/topic/136760-solved-newbie-needs-help-with-forms/#findComment-714269 Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 seeing as the problems on line 75 maybe you should post more code Quote Link to comment https://forums.phpfreaks.com/topic/136760-solved-newbie-needs-help-with-forms/#findComment-714272 Share on other sites More sharing options...
perryub Posted December 13, 2008 Author Share Posted December 13, 2008 Hi, Sorry, I guess I should have made this more explicit. The <?PHP line is actually line 63 of the file. The first lines are code from the page's template (other <div>'s) and are not editable regions. Line 75 is the line: $sql = "SELECT Students.OEN, Students.LastName, Students.FirstName, Notes.Note FROM Students, Notes WHERE Students.OEN = Notes.OEN AND MATCH (Notes.Note) AGAINST ($_POST['keyword'])"; Thanks, Perry Quote Link to comment https://forums.phpfreaks.com/topic/136760-solved-newbie-needs-help-with-forms/#findComment-714333 Share on other sites More sharing options...
premiso Posted December 13, 2008 Share Posted December 13, 2008 <?php if (isset($_POST['keyword'])) { // set database server access variables: $host = "123.456.789.10"; $user = "NotMyUserName"; $pass = "NotMyPasswordEither"; $db = "MyDB"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql = "SELECT Students.OEN, Students.LastName, Students.FirstName, Notes.Note FROM Students, Notes WHERE Students.OEN = Notes.OEN AND MATCH (Notes.Note) AGAINST (" . $_POST['keyword'] . ")"; $result = mysql_query($sql); } else { echo "<form action='SearchNotWorking.php' method='POST'>"; echo "<input type='text' name='keyword'>"; echo "<input type='submit' value='Search!'>"; echo "</form>"; } ?> One problem would have been the mysql_query, I changed it to all lower case cause php is case sensitive. The other problem was the post variable in double quote you either need to encase array variables with { and } or concat them, I switched it to the concat version. Quote Link to comment https://forums.phpfreaks.com/topic/136760-solved-newbie-needs-help-with-forms/#findComment-714345 Share on other sites More sharing options...
perryub Posted December 13, 2008 Author Share Posted December 13, 2008 Thanks Premiso. I don't know if it is expected behavior or not, but to get the query to execute properly, I had to add another set of single quotes in the query near the $_POST: AGAINST ('" . $_POST['keyword'] . "')"; It seems that the MATCH-AGAINST statement requires it. Is this normal? Perry Quote Link to comment https://forums.phpfreaks.com/topic/136760-solved-newbie-needs-help-with-forms/#findComment-714573 Share on other sites More sharing options...
peranha Posted December 13, 2008 Share Posted December 13, 2008 yes it is because it is text, so it need the single quotes. hence what you have there. Quote Link to comment https://forums.phpfreaks.com/topic/136760-solved-newbie-needs-help-with-forms/#findComment-714575 Share on other sites More sharing options...
revraz Posted December 13, 2008 Share Posted December 13, 2008 You could also simply use {$_POST['keyword']} Quote Link to comment https://forums.phpfreaks.com/topic/136760-solved-newbie-needs-help-with-forms/#findComment-714577 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.