Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2003
    Posts
    19

    Unanswered: Trouble with tag </html>

    I am using PHP in Dreamweaver so I hope I am in the right forum. I keep getting the following message when I try to view through the browser.

    "Parse error: parse error in C:\Inetpub\wwwroot\LeakTech\inventory.php on line 83"

    Line 83 is </html>

    There is a <html> at the begining. What am I missing or what should I look for?

    Richard M

  2. #2
    Join Date
    Feb 2004
    Posts
    533
    Quote Originally Posted by Richard m
    What am I missing or what should I look for?
    If you are in PHP Mode you must use the 'print' or 'echo' funtion to print test or html code to the screen.

    echo "/html";

    Your strings should be in quotes.
    Lines are ended with a semi-colin

    You switch into php with <?php
    and out of php with ?>

    <?php
    echo "I'm printing some text with php";
    ?>
    now Im in html mode
    </html>



    .
    ~

    Bill

  3. #3
    Join Date
    Jul 2004
    Location
    Mars
    Posts
    137

    Thumbs up

    Quote Originally Posted by Richard m

    "Parse error: parse error in C:\Inetpub\wwwroot\LeakTech\inventory.php on line 83"
    The reason for this error is that, there is a mismatch of string token in the PHP code. The mismatch can be bcoz of any of the following <?, (, {,.

    Also ensure that all opened quotes have a corresponding closed quote.

    I think line 83 is the last line in the code. Is it correct..?
    Sudar

    --
    My Blog

  4. #4
    Join Date
    Aug 2003
    Posts
    19
    Hello Bill,

    here is the code I have written and it is to test login when the submit button is pushed. The error comes at the last line </html>. I thought the code I had would help.

    Richard M

    <html>
    <head>
    <title><?php ?>Vistor must login to access their inventory<?php ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <body bgcolor="#FFFFFF" background="images/Pictures/background_2.bmp">
    <div align="center"><font color="#000000" size="+2" face="Times New Roman, Times, serif"><?php ?>You
    must login to veiw your inventory</font> <?php ?></div>
    <form name="form1" method="post" action="">
    <p> Username:
    <input type="text" name="textfield1">
    </p>
    </form>
    <form name="form2" method="post" action="">
    <p>Password:
    <input name="fPassword" type="password" id="fPassword">
    </p>
    </form>




    <input name="SubmitPassword" type="submit" onkeyUp="
    <?php
    /* Login program for customers of Company
    * login and passwords are stored in Customers database
    */
    session_start();
    include("aclamps.inc");
    switch (@$_GET['do'])
    {
    case "login":
    $connection = mysql_connect($host, $user, $password)
    or die ("Couldn't connect to server.");
    $db=mysql_select_db($database, $connection)
    or die("Couldn't connect to database.");
    $sql = "SELECT ccustomer FROM customers
    WHERE ccustomer ='$_POST[textfield1]'";
    $result = mysql_query($sql)
    or die("Couldn't execute query");
    $num = mysql_num_rows($result);
    if ($num == 1) // login name was found
    {
    $sql = "SELECT ccustomer FROM customers
    WHERE ccustomer ='$_POST[textfield1]'
    AND cpassword = cpassword($_POST[fpassword]')";
    $result2 = mysql_query($sql)
    or die("Couldn't execute query 2.");
    $num2 = mysql_num_rows($result2);
    if ($num2 > 0) // password is correct
    {
    $_SESSION['auth']="Yes";
    $logname=$_POST['textfield1'];
    $_SESSION['logname'] = $logname;
    $Today = date("Y-m-d h:m:s");
    $sql = "INSERT INTO (loginname, logintime)
    VALUES ('$logname','$today')";
    mysql_query($sql) or die("Can't execute query.");
    // header("location: Customers.php");
    }
    else // password is not correct
    {
    unset($do);
    $message="The Login Name. '$_POST[textfield1]'
    exists. But you have not entered the
    Correct password! Please try
    again.<br>";
    //include("login_form.inc");
    }
    }
    elseif ($num == 0) // login name not found
    {
    unset($d0);
    $message = "The Login Name you entered does not exist!
    Please try again.<br>";
    // include("login_form");
    }

    ?>
    ">
    </body>
    </html>

  5. #5
    Join Date
    Feb 2004
    Posts
    533
    I think your problem is with mixing the PHP and html in the way you have it or the way Dream weaver has generated it.

    You have 4 cases of this string "<?php ?>" in your page. this is an empty PHP tag and is not doing anything so you can delete it. You also have two form tags and the submit button is outside of the form tag.

    The submit button has PHP on the "onkeyup=" This may work, but not with this code, it's not the way I've seen it done. Sessions have to be set prior to any header output. I think you'll want to separate the login code to it's own file 'login.php' then have the form "action" event refer to 'login.php' It should look like this.
    HTML Code:
    <html>
    <head>
      <title>Vistor must login to access their inventory</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <body bgcolor="#FFFFFF" background="images/Pictures/background_2.bmp">
    <div align="center"><font color="#000000" size="+2" face="Times New Roman, Times, serif">You
    must login to veiw your inventory</font></div>
    <form name="form1" method="post" action="login.php">
      <p> Username:
        <input type="text" name="textfield1">
      </p>
      <p>Password:
        <input name="fPassword" type="password" id="fPassword">
      </p>
      <input name="SubmitPassword" type="submit" onkeyUp="">
    </form>
    </body>
    </html>
    You'll have to work on the login script separately. Check these links to learn about sessions and writing a login script.
    function.session-start.php
    A Session In The Cookie Jar


    .
    ~

    Bill

  6. #6
    Join Date
    Aug 2003
    Posts
    19
    Thanks Bill,

    I will not be working on this for a few days due to getting our bills out and Thanksgiving.

    I am new at this and have another question. When I link to the login page, where would this script go.

    I will be checking out those two links.

    Richard M

  7. #7
    Join Date
    Feb 2004
    Posts
    533
    Quote Originally Posted by Richard m
    I am new at this and have another question. When I link to the login page, where would this script go.
    The easiest is in the same directory as your calling form or index file. If you want to use another directory you will have to qualify the file path and name.

    .
    ~

    Bill

  8. #8
    Join Date
    Dec 2003
    Posts
    56
    I also notice 2 <body> tags. Not sure if this is a problem but you only need one

  9. #9
    Join Date
    Aug 2003
    Posts
    19
    Bill,

    I read the "A Session In The Cookie Jar" and picked up some ideas. The problem when the page opens, the user name and password text box shows but none of the code runs. I have uploaded the table with names and passwords to the server along with the code to run the page.

    I looked at your sample and the sample used in the Cookie Jar articale. I used the the Cookie Jar code to start with. I used MySQL to develop a table that has company and password name in it.

    When the page loads, does the code run automatically or does it run when the submit key is pressed?

    Here is the code as it is now. What did I miss?

    Richard M

    PHP Code:
    <?php
    if (isset($_POST['ccustomer']) || isset($_POST['cpassword'])) {
    // form submitted
    // check for required values
    if (empty($_POST['ccustomer'])) {
        die (
    "ERROR: Please enter username!");
    }
    if (empty(
    $_POST['cpassword'])) {
        die (
    "ERROR: Please enter password!");
    }

    // set server access variables
    $host "localhost";
    $user "ccustomer";
    $pass "cpassword";
    $db "customers";

    // open conection
    $connection mysql_connect($host$user$pass) or die ("Unable to connect!");

    // select database
    mysql_select_db($db) or die ("Unable to select database!");

    // create query
    $query "SELECT * FROM customers WHERE ccustomer = '" $_POST['ccustomer'] . "' AND pass = SHA1('" $_POST['cpassword'] . "')";

    // execute query
    $result mysql_query($query) or die ("ERROR in query: $query. " mysql_error());

    // see if any rows were returned
    if (mysql_num_rows($result) == 1) {
        
    // if a row was returned
        // authentication was successful
        // create session and set cookiewith username
        
    session_stat();
        
    header("Cache-control: private");  // added 11-29 go back to show data

        
    $_SESSION['auth'] = 1;
        
    setcookie("username"$_POST['ccustomer'], time()+(84600*30));
        echo 
    "Access granted!";
        }
    else {
        
    // no results
        // authentication failed
        
    echo "ERROR: Incorrect username or password!";
        }
        
        
    // free result set memory
        
    mysql_free_result($result);
        
        
    // close connection
        
    mysql_close($connection);
        }
        else {
        
    // no submission
        // display login form
        
    ?>
            <html>
            <head></head>
            <body>
            <form method="post" action="<?php echo $_server['PHP_SELF']; ?>"> 
            <div align="center">
            Username <input type="text" name="ccustomer" value="<?php echo $_COOKIE['username']; ?>"> 
    // This Notice appears in the username text box 
    // <br /><b>Notice</b>:  Undefined index:  username in 
    // <b>C:\Inetpub\wwwroot\LeakTech\customers\login1.php</b> on line 
    // <b>63</b><br />
            </div>
            <p align="center" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <div align="center">Password 
              <input type="password" name="cpassword">
            </div>
            <p align="center" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <div align="center">
              <input type="submit" name="submit" value="Log In">
            </div>
            </body>
            
            
            
            </html>
    <?php
    }
    ?>

  10. #10
    Join Date
    Feb 2004
    Posts
    533
    Your code will run when the submit button is clicked. In fact the form does not even have to be a PHP extn. it can be .html That is as long as you do not have php code mixed in the same page as your html. But in your test example you have html and php combined which is ok for testing/learning but bad for a production login. Make sure you are running from your localhost or defined alias if you are testing on the local machine. Simplify your code to see if PHP is workng. Example:
    PHP Code:
    <?php
    if (isset($_POST['ccustomer']) || isset($_POST['cpassword'])) {
    // form submitted
    // check for required values
    if (empty($_POST['ccustomer'])) {
        die (
    "ERROR: Please enter username!");
    }
    if (empty(
    $_POST['cpassword'])) {
        die (
    "ERROR: Please enter password!");
    }

    $ccustomer $_POST['ccustomer'];
    $cpassword =  $_POST['cpassword'];
     echo 
    $ccustomer "<br>";
     echo 
    $cpassword ;

        }
     else {
       
    // no submission
       // display login form

    ?>
            <html>
            <head></head>
            <body>
            <form method="post" action="<?php echo $_server['PHP_SELF']; ?>">
            <div align="center">
            Username <input type="text" name="ccustomer" value="<?php echo $_COOKIE['username']; ?>">

    <!-- // This Notice appears in the username text box
    // <br /><b>Notice</b>:  Undefined index:  username in
    // <b>C:\Inetpub\wwwroot\LeakTech\customers\login1.php</b> on line
    // <b>63</b><br /> -->

           </div>
            <p align="center" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <div align="center">Password
              <input type="password" name="cpassword">
            </div>
            <p align="center" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <div align="center">
              <input type="submit" name="submit" value="Log In">
            </div>
            </body>



            </html>
    <?php 
    }
    ?>

    .
    ~

    Bill

  11. #11
    Join Date
    Aug 2003
    Posts
    19
    Hello Bill,

    Since my code shows a problem at

    [php code]
    Username <input type="text" name="ccustomer" value="<?php echo $_COOKIE['username']; ?>">
    // This Notice appears in the username text box
    // <br /><b>Notice</b>: Undefined index: username in
    // <b>C:\Inetpub\wwwroot\LeakTech\customers\login1.ph p</b> on line
    // <b>63</b><br />
    [/php code]

    and that none of the code works, I figure it is not reading the table customers created in MySQL. I copied the table into the folder that has the login1.php code.

    So I checked this out and saw that I copied customers.frm and that the actual data was in customer1.txt file (this file does not have headers). So I copied that to my folder and uploaded it to the server. Still no luck.

    Now I question if the table was created properly from MySQL. Looking at the MySQL data, I think that the .frm lays out the pattern with column headers and the data is in a text file (no headers). So how do I get all this into the PHP code so it will reconize the data?

    Richard

  12. #12
    Join Date
    Feb 2004
    Posts
    533
    Quote Originally Posted by Richard m
    Since my code shows a problem at

    [php code]
    Username <input type="text" name="ccustomer" value="<?php echo $_COOKIE['username']; ?>">
    // This Notice appears in the username text box
    // <br /><b>Notice</b>: Undefined index: username in
    // <b>C:\Inetpub\wwwroot\LeakTech\customers\login1.ph p</b> on line
    // <b>63</b><br />
    [/php code]

    Richard
    You have to understand how you are switching in and out of PHP. Where this tag <?php starts PHP mode and this tag ?> ends php. Comments in PHP are 'commented' by /* */ or // and Html comments are noted like <!-- this is a comment --> what you are showing above does not use the correct syntax for the html mode of your code.

    As for database connectivity you will have to understand your environment and use the correct connect strings, paths etc. I think you need to brake this down. First make sure PHP is working on your server, then test the database connection. You'll have to check out your server and see what it has and how its configured. I can't advise you on all of this. It is something you are going to have to investigate and study on your own or find someone willing to give more time to the effort, or hire it out. DreamWeaver has some tools for writing PHP but I think you will also need to learn PHP and MySQL to make it all work. I've spent a lot of time reading and testing to learn PHP but for the most part I still consider myself beginner.

    Here is some code to check your PHP install, and get information about your server etc. Save this in a file 'test.php' save it to your server and run it.

    PHP Code:
    <?php
     
    echo 'PHP is working.<br>';
     echo 
    phpinfo();
    ?>

    .
    ~

    Bill

  13. #13
    Join Date
    Aug 2003
    Posts
    19
    Thanks Bill,

    I am starting to think that the problem is with the server or its me. I will be checking it out.

    Richard

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •