jeff5656 Posted March 31, 2008 Share Posted March 31, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/ Share on other sites More sharing options...
Caesar Posted March 31, 2008 Share Posted March 31, 2008 Change query string to... <?php $query = "SELECT * FROM `reminders` WHERE `done_status` = 'a' AND `physician`='".$physicia."' ORDER BY `check_date` DESC"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505913 Share on other sites More sharing options...
jeff5656 Posted March 31, 2008 Author Share Posted March 31, 2008 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"; Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505919 Share on other sites More sharing options...
frijole Posted March 31, 2008 Share Posted March 31, 2008 you added spaces on each side of the $physician variable. Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505922 Share on other sites More sharing options...
sasa Posted March 31, 2008 Share Posted March 31, 2008 echo $physician; add ; to end Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505923 Share on other sites More sharing options...
jeff5656 Posted March 31, 2008 Author Share Posted March 31, 2008 I tried that and same error: I got rid of spaces: $query = "SELECT * FROM 'reminders' WHERE 'done_status' = 'a' AND 'physician'='".$physician."' ORDER BY 'check_date' DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505925 Share on other sites More sharing options...
dmccabe Posted March 31, 2008 Share Posted March 31, 2008 $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 ^ Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505926 Share on other sites More sharing options...
jeff5656 Posted March 31, 2008 Author Share Posted March 31, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505929 Share on other sites More sharing options...
jeff5656 Posted March 31, 2008 Author Share Posted March 31, 2008 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']) ; Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505933 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2008 Share Posted March 31, 2008 In MySQL queries, you need to quote strings and but not field names. Try: <?php $query = "SELECT * FROM reminders WHERE done_status = 'a' AND physician = '$physician' ORDER BY check_date DESC"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505934 Share on other sites More sharing options...
sasa Posted March 31, 2008 Share Posted March 31, 2008 change to $query = "SELECT * FROM `reminders` WHERE `done_status` = 'a' AND `physician` = ' ". $physician ." ' ORDER BY `check_date` DESC"; change ' to ` around fields names Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505935 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2008 Share Posted March 31, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505937 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2008 Share Posted March 31, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505939 Share on other sites More sharing options...
sasa Posted March 31, 2008 Share Posted March 31, 2008 ops i just copy original code Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505943 Share on other sites More sharing options...
jeff5656 Posted March 31, 2008 Author Share Posted March 31, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505981 Share on other sites More sharing options...
jeff5656 Posted March 31, 2008 Author Share Posted March 31, 2008 actually don't answer that isset question. That is a different topic so I will leave a new post. thank for above help to all. That part now works. Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-505991 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2008 Share Posted March 31, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/98869-parse-error/#findComment-506051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.