I recently made an ajax/php script to query a database.
I had the ajax page and the request page seperate unlil I got it working but when I did merge then I came about a problem.
The problem arises at the merge in the if else statement. I have
PHP Code:
<?php
if ($_SERVER['QUERY_STRING']){.....etc.....};
else { ?>
//start of html
<html>
<head>
....etc....
I canneot get this to work,
any help would be appreciated,
Thanks
We may need more info on what you mean by it not working: what does it do that you don't want it to do or not do that you want it to do?
One suggestion: use the empty() function to test the $_SERVER value, just in case it's not set at all, e.g.:
PHP Code:
<?php
if(!empty($_SERVER['QUERY_STRING'])) {
// do something with query string
}
else {
?>
<!-- some HTML -->
<?php
}
?>
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
For a syntax error such as that we'll probably need to see the actual code, not a "brief synopsis". But "andx85" has a good point if your actual code is written that way witha ";" following the "}".
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Yeah, the "unexpected else" is definitely coming from that semi-colon at following the closing curly bracket at the end of the if statement.
Also, not sure what the rest of your page looks like, but it's good practice (IMO) to keep the business logic separate from the presentation. So you could do something like this...
Bookmarks