Jump to content


Photo

Whats wrong here?


  • Please log in to reply
8 replies to this topic

#1 phpnewbie1989

phpnewbie1989
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 05 October 2006 - 04:01 AM

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);
?>

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 05 October 2006 - 04:14 AM

This

$query = sprintf("SELECT HUB, ARRIVAL, ETE, DISTANCE, MINIMUM_PAX, MAXIMUM_PAX, ROUTE, FLIGHT_# FROM routes WHERE HUB='%s' AND ARRIVAL='%s'",

Should be

$query = sprintf("SELECT HUB, ARRIVAL, ETE, DISTANCE, MINIMUM_PAX, MAXIMUM_PAX, ROUTE, FLIGHT_# FROM routes WHERE HUB='%s' AND ARRIVAL='%s'");

You forgot the );

Also when posting code you should use the following bbcodes

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

example

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

Will look like this

<?php
echo "something";
?>

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

like this

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

Will look like this

echo "something";

Hope that helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 phpnewbie1989

phpnewbie1989
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 05 October 2006 - 04:59 AM

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.

#4 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 05 October 2006 - 05:06 AM

you need to clarify your question... forms work in php th same way they work in other languages... your form action calls teh script that process teh form form elements are variables etc...

#5 phpnewbie1989

phpnewbie1989
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 05 October 2006 - 05:33 AM

Okay lets see if I can do this :)

I am trying to build the form, but in the coding I dont know how to specify that the two fields in the form are my search keywords for the SQL database data. How do I designate the two form fields as my search criteria?

#6 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 05 October 2006 - 05:37 AM

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

#7 phpnewbie1989

phpnewbie1989
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 05 October 2006 - 05:42 AM

Thank you very much for the Help. I really appreciate this.

#8 phpnewbie1989

phpnewbie1989
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 05 October 2006 - 05:58 AM

IM again sorry to bother, I have not had much luck at following those steps. It tells me there was an unexpected ='s where I put the SQL=  line.

#9 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 05 October 2006 - 06:58 AM

put the row you are trying to match in `` like so and the variables in '':
sql=("SELECT * FROM `blue` WHERE `something`='".$term1."'");

not all ppl do this but you should start doing it.
Good luck with your coding.
Jason / ProjectFear / Jaysonic




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users