Jump to content

[SOLVED] Bamboozled. cannot figure out the error.


Johnain

Recommended Posts

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>

 

 

 

 

    }

 

 

 

 

 

____________________________________________________________________________________________

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

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++;

          }

Link to comment
Share on other sites

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>



Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

$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

 

 

Link to comment
Share on other sites

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!" :D

 

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

Link to comment
Share on other sites

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.

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.