Jump to content

parse error


jeff5656

Recommended Posts

I get this error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\wamp\www\consults\reminders\displayreminders.php on line 17

 

for this code:

 

<?php
$physician =  isset($HTTP_POST_VARS['physician']) ? $HTTP_POST_VARS['physician'] : '';


$query = "SELECT * FROM reminders WHERE done_status = 'a' AND physician = $physician ".
	"ORDER BY check_date DESC";

 

Line 17 refers to the $query line.

 

Thanks for any help.

Link to comment
Share on other sites

Here is what you suggested but it doesn't work.  Get the same error:

 

<?php
$physician =  isset($HTTP_POST_VARS['physician']) ? $HTTP_POST_VARS['physician'] : '';
echo $physician

$query = "SELECT * FROM 'reminders' WHERE 'done_status' = 'a' AND 'physician' = ' ". $physician ." ' ORDER BY 'check_date' DESC";

Link to comment
Share on other sites

$physician =  isset($HTTP_POST_VARS['physician']) ? $HTTP_POST_VARS['physician'] : '';

 

It may just be me showing my inexperience, but that line makes no sense either?

 

what is the ? $HTTP_POST_VARS['physician'] : doing?

 

and why the " at the end?

 

echo $physician;

add ; to end

 

Also what he said ^

Link to comment
Share on other sites

after correcting ; at end of echo statement, I get this new error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''reminders' WHERE 'done_status' = 'a' AND 'physician'='' ORDER BY 'check_date' D' at line 1

Link to comment
Share on other sites

what is the ? $HTTP_POST_VARS['physician'] : doing?

 

and why the " at the end?

 

Good question.  The person I got that from gave me that snippet.  The goal is to set the variable from the previous form and assign it to $physician.  So is this how I do it:

 

$physician =  isset($HTTP_POST_VARS['physician']) ;

Link to comment
Share on other sites

This line

<?php
$physician =  isset($HTTP_POST_VARS['physician']) ? $HTTP_POST_VARS['physician'] : '';
?>

is using a ternary operator, which is a short had for an if-else statement. The above could have been written as

<?php
if (isset($HTTP_POST_VARS['physician']))
    $physician = $HTTP_POST_VARS['physician'];
else
    $physician = '';
?>

 

BTW, you should be using $_POST instead of $HTTP_POST_VARS

 

Ken

Link to comment
Share on other sites

Sasa,

 

in your code

<?php
$query = "SELECT * FROM `reminders` WHERE `done_status` = 'a' AND `physician` = ' ". $physician ." ' ORDER BY `check_date` DESC";
?>

you've put extra spaces around the value of $physician. It probably should be:

<?php
$query = "SELECT * FROM `reminders` WHERE `done_status` = 'a' AND `physician` = '". $physician ."' ORDER BY `check_date` DESC";
?>

 

Ken

Link to comment
Share on other sites

Thank you it works BUT, the variable is not retained if I go to another page:

 

I put this at the beginning of another page:

 

if (isset($_POST['physician']))
    $physician = $_POST['physician'];
else
    $physician = '';

 

and that other page I populate the form with this variable:

 

<input type="text" name="physician" id="physician" value="<?php echo $physician; ?>"/>

 

but it is blank.  In fact, when I echo $physician, it is blank!

Link to comment
Share on other sites

If you want to pass values to another script, you should be using SESSIONS.

 

At the start of each script, before any output is sent to the browser, put

<?php
session_start();
?>

 

In the script that wants to send the value, put

<?php
$_SESSION = $physician;
?>

 

In the script where you want to retrieve the value, put

<?php
$physician = $_SESSION['physician'];
?>

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.