Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    hmg
    hmg is offline
    New Coder
    Join Date
    Apr 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    parse error, unexpected T_ENCAPSED_AND_WHITESPACE

    I am pretty new to PHP, and need some help.

    I am getting the following error:

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ... on line 26

    The script that I am having a problem with follows:

    <?php
    $host = "localhost";
    $login_name = "hmg";
    $password = "passhmg";

    //Connecting to MYSQL
    $link=MySQL_connect("$host","$login_name","$password");

    //Select the database we want to use
    MySQL_select_db("mydb",$link) or die("Could not select database");
    $date=$_POST['orderdate'];
    $result = mysql_query("SELECT max(event_num) FROM events WHERE date = '$date', $link);

    $num_rows = mysql_num_rows($result);

    //Code to check if statement executed properly increment event_num if found
    if ($num_rows > 0 )
    {
    $maxevt = mysql_result($result,0)
    $event_num = $maxevt + 1;
    } else {
    $event_num = 1;
    }
    $short_desc=$_POST['ShortDesc'];
    $long_desc=$_POST['LongDesc'];

    //Name query $sql
    $sql = "INSERT INTO events (date, event_num, short_desc, long_desc) VALUES ('$date', '$event_num', '$short_desc', '$long_desc')";


    //Execute query and get result
    $result = mysql_query($sql);


    //Code to check if statement executed properly and display MailUpd.htm
    if ($result) {
    echo "<script>alert('Information updated')</script>";
    } else {
    $db_error = mysql_error();
    echo("An error has occured: $db_error");
    }
    mysql_close($link);
    ?>

  • #2
    New Coder
    Join Date
    Aug 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this line u forgot to close with "
    should be
    PHP Code:
    $result mysql_query("SELECT max(event_num) FROM events WHERE date = '$date', $link"); 
    instead of
    PHP Code:
    $result mysql_query("SELECT max(event_num) FROM events WHERE date = '$date', $link); 

  • #3
    hmg
    hmg is offline
    New Coder
    Join Date
    Apr 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks!

    I copied the script from an earlier one I had written and accidentally deleted the quote.

    For future reference, did you just review the code by eye or is there some other trick to find these types of errors?

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    PHP Code:
    $result mysql_query("SELECT max(event_num) FROM events WHERE date = '$date', $link);

    $num_rows = mysql_num_rows($result); 
    if you enclose code in [php ] tags (without the space...) then it highlights the code, making it obvious you missed something. You can text text-editors that understand PHP, and can highlight accordingly- might be worth using one.

  • #5
    hmg
    hmg is offline
    New Coder
    Join Date
    Apr 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    The editor that I use does highlights key words,etc. in HTML, PHP, ASP etc., but not syntactic errors. Could you suggest a better editor that highlights these errors?

    BTW, the script (evtinp.php) is initiated from a different HTML page with: Method="post" action="evtinp.php". However, this causes the alert box (Information updated) after update to appear on a blank screen, rather than the initiating HTML page. I've tried combining the two (HTML and PHP script) into one PHP file with the HTML first, followed by the PHP code with </body> ending the HTML and <?php
    beginning the PHP. This causes the Insert to automatically execute with blank data.

    How can I get the alert box to appear on the HTML page after the Insert has taken place?

  • #6
    New Coder
    Join Date
    Aug 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can put both in the php by checking if data has been posted

    PHP Code:
    <?php
    if ($_SERVER['REQUEST_METHOD'] == "POST") {
    The code you just posted here
    }
    else {
    ?>
    YOUR HTML HERE
    <?php
    }
    ?>
    btw dreamweaver is pretty neat for php

  • #7
    hmg
    hmg is offline
    New Coder
    Join Date
    Apr 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Thanks. I now have both files combined into one, but the alert box is still appearing on a blank screen.

    The code from the bootom of the PHP through the beginning of the HTML looks like this:

    //Name query $sql
    $sql = "INSERT INTO events (date, event_num, short_desc, long_desc) VALUES ('$date', '$event_num', '$short_desc', '$long_desc')";


    //Execute query and get result
    $result = mysql_query($sql);


    //Code to check if statement executed properly and display alert box
    if ($result) {
    echo "<script>alert('Information updated')</script>";
    } else {
    $db_error = mysql_error();
    echo("An error has occured: $db_error");
    }
    mysql_close($link);
    }
    else {
    ?>
    <html>
    <head>
    <title>Enter Calendar Items</title>

    .
    .

    Can I get the alert box ,i.e. alert('Information updated'), to appear on the HTML page.

    Thanks..


  •  

    Posting Permissions

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