Hi guys,

This is my first post !

I'm perpetually encountering the following error while trying to run my php code:

Parse Error: parse error, Unexpected T_Variable in C:\Inetpub\wwwroot\glucotext.php on line 24

Here is only the php code. (in which case 'line 24' would be inappropriate)

<?php
$date = date('H:i, jS F');
$time = time()

$outputstring = $patientid."\t".$date."\t".$time."\t".$bglevel."\t".$comments."\n"

// open file for appending
@ $fp = fopen("$DOCUMENT_ROOT..\records\records.txt",'ab');

fwrite($fp, $outputstring, strlen($outputstring));
fclose($fp);

echo '<p>Record updated.</p>';
?>

The code was created simply to write the data in the fields into a text file. i just cant figure out what error means.
I can be abs sure that there isn't a typo error in the variable names.

Id greatly appreciate any help !

    Hi, and welcome.

    It looks like you are missing some semi colons. Try this.

    <?php
    $date = date('H:i, jS F');
    $time = time(); // needed semi-colon
    
    $outputstring = $patientid . "\t" . $date . "\t";
    $outputstring .= $time . "\t" . $bglevel . "\t" . $comments . "\n";
    
    // put @ symbol in front of fopen function
    $fp = @fopen($DOCUMENT_ROOT . "\..\records\records.txt",'ab');
    
    if($fp)
    {
    	fwrite($fp, $outputstring, strlen($outputstring));
    	fclose($fp);
    	echo '<p>Record updated.</p>';
    }
    else {
    	echo '<p>Could not update record.</p>';
    }
    ?>
    
      a year later

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <title>Veiw Image</title>
      </head>
      <body>
      <?php

      $okay = FALSE;

      if (isset($_GET['image'])){

      $ext = substr ($_GET['image'], -3);

      if ($ext =='.png' OR $ext == '.jpg' $ext == '.jpeg' OR $ext =='.gif'){

      if ($image = @getimagesize ('images/'.$GET['image'])){
      echo "<img src=\"images/{$
      GET['image']}\"$image[3] border=\"2\"/>";
      $okay = TRUE;
      }
      }
      }
      if (!$okay){
      echo'This script must receive a valid image name';
      }
      ?>
      <div><a href="javascript:self.close();">Close</a></div>
      </body>
      </html>

      Can someone help me. I checked for missing ";" but still will not work?

        Looks like you left out an "OR":

        if ($ext =='.png' OR $ext == '.jpg' [b][color=red]OR[/color][/b] $ext == '.jpeg' OR $ext =='.gif'){
        

          I would use || instead of OR in the if-statements. It is a big difference in operator precedence between the two, and in some cases it may cause trouble with OR.

            Piranha wrote:

            I would use || instead of OR in the if-statements. It is a big difference in operator precedence between the two, and in some cases it may cause trouble with OR.

            I guess that's a personal preference sort of thing. I actually prefer to use 'and' and 'or' because of the difference in precedence. With the word versions, I know that they are lowest in precedence (except for ','), while I have to remember that the ternary operator and all the assignment operators are lower than '||' and '&&'. If at any point that lower precedence is an issue, it is easily dealt with by parentheses. Plus, it makes my code easier to read.

            But the important thing is to realize that there is a precedence difference, and be aware of when you need to tread carefully with your comparison operators.

              NogDog wrote:

              But the important thing is to realize that there is a precedence difference, and be aware of when you need to tread carefully with your comparison operators.

              Amen to that.

                Thank you for that last reply. You are sent from heaven, this one has been troubling me for days now.
                I am new so I hope you dont mind. I have manage to build a database with registration and the info does store, but when you try to log in this is what I get:

                Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Inetpub\vhosts\saltypaws.co.uk\httpdocs\loggedin.php on line 17

                <?php # Script 7.2 loggedin.php
                include ('nocache.php');
                ob_start(); //Start output buffering.
                session_start();//Set session and redirect.
                session_name ('YourVisitID');

                //Set page and tile.
                $page_tite = 'Logged In';
                include ('inc/header.inc');
                //If no session is present redirect user.
                if (isset($SESSION['first_name'])){
                echo "You are now logged in,
                {$
                SESSION['first_name']}!";
                }else{
                ob_end_clean(); //Delete buffer.
                header("Location:http://'.$SERVER['HTTP_HOST'].dirname($SERVER['PHP_SELF']).'index.php");
                exit();
                }
                include ('inc/footer.inc');
                ob_end_flush(); //Send everything to web browser.
                ?>

                Can anyone help?

                  When posting PHP code, please use the board's [PHP][/PHP] bbcode tags - they make the code much, much easier to read (as well as aiding the diagnosis of syntax errors). You should edit your posts now and add these bbcode tags to help others in reading/analyzing your code.

                  In fact, once you add these tags to your post and view the code with the board's syntax highlighting (though you should be using an editor that offers syntax highlighting, as there's too many of them out there not to), your problem will become increasingly obvious once you examine the header() line.

                    Thanks and I will but how do I do that?

                      <?php # Script 7.2 loggedin.php
                      include ('nocache.php');
                      ob_start(); //Start output buffering.
                      session_start();//Set session and redirect.
                      session_name ('YourVisitID');
                      
                      //Set page and tile.
                      $page_tite = 'Logged In';
                      include ('inc/header.inc');
                      //If no session is present redirect user.
                      if (isset($_SESSION['first_name'])){ 
                      echo "You are now logged in, 
                      {$_SESSION['first_name']}!";
                      }else{
                      ob_end_clean(); //Delete buffer.
                      header("Location:http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'index.php");
                      exit();
                      }
                      include ('inc/footer.inc');
                      ob_end_flush(); //Send everything to web browser.
                      ?>

                      Thanks!

                        a year later

                        I get a unexpected T_Variable error in this code which points to the line were the results variable is stored with query results. I check all the variables to make sure they were getting information and storing it with an echo. I know it is connecting and able to return the entries in the database it only fails when I add a the WHERE and try to limit the results.

                        <?php
                        mysql_connect("10.6.171.24","user","password")or die(mysql_error());
                        mysql_select_db("Masonite")or die(mysql_error());
                        
                        include('mysqlSearchForm.htm');
                        
                        
                        $state=($_POST['state']);
                        $state2=($_POST['state2']);
                        $state3=($_POST['state3']);
                        $type=($_POST['type']);
                        $type2=($_POST['type2']);
                        $type3=($_POST['type3']);
                        $disicipline=($_POST['disicipline']);
                        $disicipline2=($_POST['disicipline2']);
                        $disicipline3=($_POST['disicipline3']);
                        
                        $results= mysql_query('SELECT Type, Disicipline, State FROM Schools WHERE Type = '$type'');
                        
                        echo $type;
                        echo $type2;
                        echo $type3;
                        
                        if($results)
                        {
                        	while($array= mysql_fetch_assoc($results)){
                        		echo '<br>';
                        		print $array['School Name'];
                        		echo '</br>';
                        	}
                        }
                        else
                        {
                        	echo "NO RESULTS FOUND";
                        }
                        
                        mysql_close();
                        
                        ?>

                        MOD EDIT: Username/password removed from code (in case they were valid).

                          @ masonite:

                          $results= mysql_query("SELECT Type, Disicipline, State FROM Schools WHERE Type = '$type'");
                          

                            @ magc:

                            header('Location:http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'index.php');
                            

                              Thanks, that got rid of the error...it is running the script right but I still can get the query to display selected results even when I take out the variable and use the value.

                              $results= mysql_query("SELECT * FROM Schools WHERE Type = 'IHSA'");

                              I checked the table and that is what exactly what the value all caps...I am assuming that I am suppose to use the name of the field exactly as it is written? that is the name of the field "Type" written exactly the same.

                              I am confused...probably something stupid I am missing!

                                ok, so I figured out why it wasn't working with the syntax I was using now I can preform queries and they work even the variables containg the valuses. My problem now seems to be that I need to combine basically three queries together. I could go about this a really long very complex way but I was wanting to instead nest the queries together into one. I am using mysql 4.1 and from what I have read the following code is what my query would look like. Can anyone tell me if they see any sytax errors/problems or confirm that this should be the right way to write this query? Thanks!

                                $results= mysql_query(“SELECT * FROM Schools WHERE Western= 
                                
                                “\$westernDiscipline\” OR English= “\$EnglishDisicipline”\ OR Fences= 
                                
                                “\$FencesDisicipline”\ AND 
                                
                                (SELECT * FROM Schools WHERE NCAA= “\$NCAAtype\” OR IHSA= 
                                
                                “\$IHSAtype”\ OR OTHER= “\$OTHERtype”\ ) AND 
                                
                                (SELECT * FROM Schools WHERE State= “\$state\” OR State= 
                                
                                “\$state2”\ OR State= “\$state3”\)”);
                                
                                  masonite wrote:

                                  Can anyone tell me if they see any sytax errors/problems

                                  Yes, there are two errors repeated throughout that code:

                                  1. You can't use "curly quotes" (or directional quotes) in PHP code or MySQL queries; only the standard " quote character will work. I'm curious; what editor are you using that is inserting these curly quotes? Looks like you should ditch that editor for a decent one.

                                  2. If you use double quotes as your string delimiter, any literal double quotes you wish to appear in the string must be escaped with a backslash; otherwise, PHP will think that you're trying to end the string and chaos will ensue.