Johnain Posted December 31, 2007 Share Posted December 31, 2007 Hi All. I hope people dont mind. I have been trying to fix this syntax error for almost half a day and I just cannot see what is wrong. I am a new boy but learning fast. What I have learned really quickly is that it is the "simple" things that bambooze me and then icky ones that I can do. Just like my previous experience with Foxpro and ABAP/4, but at least there I had a debugger. I am trying to put a list of names into a drop down box as list options. All of the includes are reliable because they are in all of my pages. The error I get is ..... Parse error: syntax error, unexpected '?' in /home/johnain/public_html/scripts/changeuser.php on line 60 Line 60 is shown in red below ___________________________________________________________________________________________ <?php require('db_connect.php'); // database connect script. ?> <html> <head> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- saved from url=(0014)about:internet --> <?php $langg = $_GET['langg']; include_once($_SERVER['DOCUMENT_ROOT'].'/scripts/incgetvars.php'); switch ($langg){ case "FR": echo"<title>Le Pré De Barre. Zone du personnel, maintenez l'utilisateur.</title>" ; break; default: echo "<title>Le Pré De Barre. Staff zone, maintain user.</title>" ; } ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="../css/style1.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="header"> <div id="sitebranding"> <?php include_once($_SERVER['DOCUMENT_ROOT'].'/scripts/incsitebrand.php'); ?> </div> <!-- End of site branding div --> <div id="tagline"> <?php include_once($_SERVER['DOCUMENT_ROOT'].'/scripts/inctagline.php'); ?> </div> <!-- End of tagline div --> </div> <!-- end of header div --> <div id="navigation"> <?php $noshow =40; include_once($_SERVER['DOCUMENT_ROOT'].'/scripts/incgetnav.php'); ?> </div> <!-- end of navigation div --> <div id="bodycontentstaff"> <?php if (!isset($_POST['submit'])) { // If form has not been submitted this must be step 1 $stepno = 1; switch ($stepno) { case 1: // Start step 1. Ask which user to maintain. $query = "SELECT username FROM users ; $result=mysql_query($query); $num=mysql_numrows($result); ?> <h4>User maintenance - select user.</h4> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <table align="center" border="1" cellspacing="0" cellpadding="3"> <tr> <td>User name?</td> <td><select name="uname"> <? $i=0; while ($i < $num) { uname=mysql_result($result,$i,"username"); <option value="<? $uname ?>" selected="selected"><? $uname ?></option> $i++; } ?> </select> </td> </tr> <tr> <td colspan="2" align="right"> <input type="submit" name="submit" value="<? echo ($buttontext) ?>"> </td> </tr> </table> </form> <? break; case 2: // Start step 2. User details maintenance. break; case 3: // Start step 3. Changed details are saved or abandoned. break; } ?> </div> <!-- end of bodycontentstaff --> </body> </html> } ____________________________________________________________________________________________ Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/ Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2007 Share Posted December 31, 2007 first of all this <? $i=0; while ($i < $num) { uname=mysql_result($result,$i,"username"); <option value="<? $uname ?>" selected="selected"><? $uname ?></option> $i++; } ?> should be <? while ($row = mysql_fetch_assoc($result)) { echo "<option value="{$row['uname']}" >{$row['uname']}</option>"; } ?> looking at the other errors Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426582 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 Thanks a million rajivgonsalves I bet there are loads! John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426583 Share on other sites More sharing options...
drummer101 Posted December 31, 2007 Share Posted December 31, 2007 To be honest, you really don't even NEED to list the action, as it automatically defaults to self. Edit: Line 60 is different when I pasted it into an editor.. ??? <h4>User maintenance - select user.</h4> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <table align="center" border="1" cellspacing="0" cellpadding="3"> <tr> <td>User name?</td> <td><select name="uname"> <? $i=0; while ($i < $num) { uname=mysql_result($result,$i,"username"); <option value="<? $uname ?>" selected="selected"><? $uname ?></option> $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426584 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 Hi Ravij So to do that do I just change the line to this? <form "method="post"> Regards John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426586 Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2007 Share Posted December 31, 2007 Yes do that.. see if it works however your same code over here gave a a different error Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426587 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 Hi again Sorry, I put in a " too far !! <form method="post"> Regards John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426588 Share on other sites More sharing options...
drummer101 Posted December 31, 2007 Share Posted December 31, 2007 So to do that do I just change the line to this? <form "method="post"> Yes Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426590 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 Hi again This time I get for <form method="post"> Parse error: syntax error, unexpected T_STRING in /home/johnain/public_html/scripts/changeuser.php on line 60 If the line was any shorter it would be invisible !! Regards John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426591 Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2007 Share Posted December 31, 2007 try this... you got a lot of stuff missing out <?php require('db_connect.php'); // database connect script. ?> <html> <head> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- saved from url=(0014)about:internet --> <?php $langg = $_GET['langg']; include_once($_SERVER['DOCUMENT_ROOT'].'/scripts/incgetvars.php'); switch ($langg) { case "FR": echo"<title>Le Pré De Barre. Zone du personnel, maintenez l'utilisateur.</title>" ; break; default: echo "<title>Le Pré De Barre. Staff zone, maintain user.</title>" ; } ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="../css/style1.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="header"> <div id="sitebranding"> <?php include_once($_SERVER['DOCUMENT_ROOT'].'/scripts/incsitebrand.php'); ?> </div> <!-- End of site branding div --> <div id="tagline"> <?php include_once($_SERVER['DOCUMENT_ROOT'].'/scripts/inctagline.php'); ?> </div> <!-- End of tagline div --> </div> <!-- end of header div --> <div id="navigation"> <?php $noshow =40; include_once($_SERVER['DOCUMENT_ROOT'].'/scripts/incgetnav.php'); ?> </div> <!-- end of navigation div --> <div id="bodycontentstaff"> <?php if (!isset($_POST['submit'])) { // If form has not been submitted this must be step 1 $stepno = 1; switch ($stepno) { case 1: // Start step 1. Ask which user to maintain. $query = "SELECT username FROM users ; $result=mysql_query($query); $num=mysql_num_rows($result); ?> <h4>User maintenance - select user.</h4> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table align="center" border="1" cellspacing="0" cellpadding="3"> <tr> <td>User name?</td> <td><select name="uname"> <?php while ($row = mysql_fetch_assoc($result)) { echo "<option value='{$row['uname']}' >{$row['uname']}</option>"; } ?> </select> </td> </tr> <tr> <td colspan="2" align="right"> <input type="submit" name="submit" value="<?php echo $buttontext; ?>"> </td> </tr> </table> </form> <?php break; case 2: // Start step 2. User details maintenance. break; case 3: // Start step 3. Changed details are saved or abandoned. break; } } ?> </div> <!-- end of bodycontentstaff --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426593 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 Hi Rajiv That is much better. It passed the test and presented a screen with the input box. No values in the drop down ist and a warning ... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/johnain/public_html/scripts/tryme.php on line 57 Line 57 is $num=mysql_num_rows($result); regards John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426597 Share on other sites More sharing options...
drummer101 Posted December 31, 2007 Share Posted December 31, 2007 $num=mysql_numrows($result); points to -> which points to $result=mysql_query($query); $query = ??? Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426598 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 Hi rajiv I looke here http://www.php.net/mysql_num_rows But it just reinforces your code. Regrds John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426599 Share on other sites More sharing options...
drummer101 Posted December 31, 2007 Share Posted December 31, 2007 John, the error is actually in your sql query. Please post that so that we can help you Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426600 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 Hi Rajiv Ok the reason for the previous error was that an absent CR put the select statement behind the // comment on the line above when I cut and pasted. That is fine now but I am back to this ... Parse error: syntax error, unexpected '?' in /home/johnain/public_html/scripts/tryme.php on line I am going to force an ftp by deleting the target and uploading again, just to be sure. Regrds John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426601 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 John, the error is actually in your sql query. Please post that so that we can help you Hi there Here is the query $query = "SELECT username FROM users ; Regards John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426602 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 John, the error is actually in your sql query. Please post that so that we can help you Here it is $query = "SELECT username FROM users ; Regards John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426604 Share on other sites More sharing options...
drummer101 Posted December 31, 2007 Share Posted December 31, 2007 $query = "SELECT username FROM users ; needs to be either $query = mysql_query("SELECT username FROM users WHERE .... "); OR $query = mysql_query("SELECT * FROM users"); Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426606 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 Hi Dummer Aaaaahhhhhh! Realisation dawns !! I will try it out now. Regards John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426608 Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2007 Share Posted December 31, 2007 hey thats my fault it was there in the original code while cleaning it up I deleted that line by mistake... sorry Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426610 Share on other sites More sharing options...
GingerRobot Posted December 31, 2007 Share Posted December 31, 2007 $query = "SELECT username FROM users ; needs to be either $query = mysql_query("SELECT username FROM users WHERE .... "); OR $query = mysql_query("SELECT * FROM users"); Err, no it doesn't. The query is actually executed later in the script with this line: $result=mysql_query($query); However, if John has posted the exact line where he as defined the query, then there are other issues. If the query is just: $query = "SELECT username FROM users ; Then you are missing a double quote. It should be: $query = "SELECT username FROM users" ; However, when you change it to that, we are going to find another error somewhere, since there must be a double quote lying around preventing the syntax error that should be display with the current code. Edit: Perhaps i've confused the issue here. In rajiv's cleaned up code, the query is executed. I assumed the variable $query, was defined elsewhere. Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426615 Share on other sites More sharing options...
drummer101 Posted December 31, 2007 Share Posted December 31, 2007 Always follow your code back as far as you can through the definitions if you can't find an error on the line it says. You'll find it sooner or later I'm horrible with my SQL so I always know that error means "GO CHECK YOUR SQL STUPID!" Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426618 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 $query = "SELECT username FROM users ; needs to be either $query = mysql_query("SELECT username FROM users WHERE .... "); OR $query = mysql_query("SELECT * FROM users"); Hi I ran it with $query = mysql_query("SELECT * FROM users"); and got a result screen with a warning Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/johnain/public_html/scripts/tryme.php on line 58 but according to the manual that looks ok to my newcomers mind. There are two records in the table but none were in my drop down list. I do not want to waste the time of you guys, you have been great. Is this where I go off and try again, or is there an obvious solution that I just cannot see? Regards John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426620 Share on other sites More sharing options...
Johnain Posted December 31, 2007 Author Share Posted December 31, 2007 Always follow your code back as far as you can through the definitions if you can't find an error on the line it says. You'll find it sooner or later I'm horrible with my SQL so I always know that error means "GO CHECK YOUR SQL STUPID!" Spot on Drummer. There was a missing " I have run the job again using $query = "SELECT username FROM users" and it runs without error. My problem now is that I do not get any data from my two users. I am going to walk through my code and see if I can work out why ... and yes, I will check out the table !!! Regards John Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426622 Share on other sites More sharing options...
GingerRobot Posted December 31, 2007 Share Posted December 31, 2007 Well, on this line here: echo "<option value='{$row['uname']}' >{$row['uname']}</option>"; You try to use the row uname, but in your query, you select from username. Since you're no longer getting an SQL error, i would imagine the correct row is username, and so you must change the above line accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/83825-solved-bamboozled-cannot-figure-out-the-error/#findComment-426623 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.