Jump to content

[SOLVED] newbie needs help with forms


perryub

Recommended Posts

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>"; 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/136760-solved-newbie-needs-help-with-forms/
Share on other sites

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

<?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.

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

 

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.