Jump to content

Whats wrong here?


phpnewbie1989

Recommended Posts

Hey,
  I am trying to build a search area for people to come in and search a database with two keywords. I am getting this error though:

Parse error: syntax error, unexpected ';' in /home2/freedh/public_html/search.php on line 36

CODING:
// This could be supplied by a user, for example

// Formulate Query
// This is the best way to perform a SQL query
// For more examples, see mysql_real_escape_string()
$query = sprintf("SELECT HUB, ARRIVAL, ETE, DISTANCE, MINIMUM_PAX, MAXIMUM_PAX, ROUTE, FLIGHT_# FROM routes WHERE HUB='%s' AND ARRIVAL='%s'",

// Perform Query
$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
  $message  = 'Invalid query: ' . mysql_error() . "\n";
  $message .= 'Whole query: ' . $query;
  die($message);
}

// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($result)) {
  echo $row['HUB'];
  echo $row['ARRIVAL'];
  echo $row['ETE'];
  echo $row['DISTANCE'];
  echo $row['MINIMUM_PAX'];
  echo $row['MAXIMUM_PAX'];
  echo $row['ROUTE'];
  echo $row['FLIGHT_#'];
}

// Free the resources associated with the result set
// This is done automatically at the end of the script
mysql_free_result($result);
?>
Link to comment
https://forums.phpfreaks.com/topic/23052-whats-wrong-here/
Share on other sites

This

[code=php:0]
$query = sprintf("SELECT HUB, ARRIVAL, ETE, DISTANCE, MINIMUM_PAX, MAXIMUM_PAX, ROUTE, FLIGHT_# FROM routes WHERE HUB='%s' AND ARRIVAL='%s'",
[/code]

Should be

[code=php:0]
$query = sprintf("SELECT HUB, ARRIVAL, ETE, DISTANCE, MINIMUM_PAX, MAXIMUM_PAX, ROUTE, FLIGHT_# FROM routes WHERE HUB='%s' AND ARRIVAL='%s'");
[/code]

You forgot the );

Also when posting code you should use the following bbcodes

For code with the <?php and ?> [nobbc][code][/code][/nobbc]

example

[nobbc][code]
<?php
echo "something";
?>
[/code][/nobbc]

Will look like this

[code]
<?php
echo "something";
?>
[/code]

No for code with out the tags use [nobbc][php][/php][/nobbc]

like this

[nobbc][code=php:0]
echo "something";
[/code][/nobbc]

Will look like this

[code=php:0]
echo "something";
[/code]

Hope that helps,
Tom
Link to comment
https://forums.phpfreaks.com/topic/23052-whats-wrong-here/#findComment-104128
Share on other sites

Thank you for the tip I really appreciate it. I just have one more question and I promise I wont ask anymore stupid things. How can I get a form to work with the php. I need to make it so that the people can insert the actual query words or keywords. I would really appreciate this last bit of help.
Link to comment
https://forums.phpfreaks.com/topic/23052-whats-wrong-here/#findComment-104156
Share on other sites

you name the form elements  whatever you like (term1 term2)
then when you process the form you get your $_POST['term1'] clean it for sql injections then set it to a variable

$_post['term1']=$term1
etc etc

then you can use them in your query
sql=("SELECT * FROM blue WHERE something=".$term1." OR ".#term2") blah blah
Link to comment
https://forums.phpfreaks.com/topic/23052-whats-wrong-here/#findComment-104172
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.