Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Another error

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default Another error

    hey everyone,

    PHP Code:
    <?php

    require "database.php";
    $userfinal=$_COOKIE['ID_my_site'];  
    $user=$userfinal;
    echo 
    $user;






     if (isset(
    $_POST['submit'])) {

    echo 
    "Thanks";

    $title=$_POST['message_title'];
    $to=$_POST['message_to'];
    $content=$_POST['message_content'];
    $from=$_POST['message_from'];
    $time=$_POST['message_date'];


    $ck_reciever "SELECT username FROM users WHERE username = '".$to."'";

            
       
            if( 
    mysql_num_rowsmysql_query$ck_reciever ) ) == ){
    die(
    "The user you are trying to contact don\'t excist. Please go back and try again.<br> ");
    }





     else 
    {
    ?>     
     <form name="message" action="new_message.php" method="post">
     Title:  <input type="text" name="message_title"> <br>
     To:   <input type="text" name="message_to"> <br>
          Message: <br>
    <textarea rows="20" cols="50" name="message_content">
    </textarea>
    <?php
    echo '<input type="hidden" name="message_from" value="'.$user.'"><br>';
    ?>
    <input type="submit" name="submit" value="Submit">
    </form>

    <?php
     
    }
     
    ?>
    Causing this error

    ( ! ) Parse error: syntax error, unexpected $end in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\pm system\new_message.php on line 59


    Can't work out why. Any help?
    Last edited by keyboard; 08-25-2011 at 06:38 AM.

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    You never ended this line with a }:
    PHP Code:
    if (isset($_POST['submit'])) { 
    Try this:
    PHP Code:
    <?php

    require "database.php";
    $userfinal=$_COOKIE['ID_my_site'];  
    $user=$userfinal;
    echo 
    $user;






     if (isset(
    $_POST['submit'])) {

    echo 
    "Thanks";

    $title=$_POST['message_title'];
    $to=$_POST['message_to'];
    $content=$_POST['message_content'];
    $from=$_POST['message_from'];
    $time=$_POST['message_date'];


    $ck_reciever "SELECT username FROM users WHERE username = '".$to."'";

            
       
            if( 
    mysql_num_rowsmysql_query$ck_reciever ) ) == ){
    die(
    "The user you are trying to contact don\'t excist. Please go back and try again.<br> ");
    }





     else 
    {
    ?>     
     <form name="message" action="new_message.php" method="post">
     Title:  <input type="text" name="message_title"> <br>
     To:   <input type="text" name="message_to"> <br>
          Message: <br>
    <textarea rows="20" cols="50" name="message_content">
    </textarea>
    <?php
    echo '<input type="hidden" name="message_from" value="'.$user.'"><br>';
    ?>
    <input type="submit" name="submit" value="Submit">
    </form>

    <?php
     
    }
     
     }
     
    ?>
    - Josh

  3. #3
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    PHP Code:
    <?php

    require "database.php";
    $userfinal=$_COOKIE['ID_my_site'];  
    $user=$userfinal;
    echo 
    $user;







     if (isset(
    $_POST['submit'])) {

    echo 
    "Thanks";

    $title=$_POST['message_title'];
    $to=$_POST['message_to'];
    $content=$_POST['message_content'];
    $from=$_POST['message_from'];
    $time=$_POST['message_date'];


    $ck_reciever "SELECT username FROM users WHERE username = '".$to."'";

            
       
            if( 
    mysql_num_rowsmysql_query$ck_reciever ) ) == ){
    die(
    "The user you are trying to contact don\'t excist. Please go back and try again.<br> ");
    }


     
    $insert "INSERT INTO pmsys (to, from, title, message, date, ifread)
                 VALUES ('"
    .$to."', '".$from."', '".$title."', '".$content."', '".$date."', '".$ifread."')";
         
    $add_member mysql_query($insert);




     else 
    {
    ?>     
     <form name="message" action="new_message.php" method="post">
     Title:  <input type="text" name="message_title"> <br>
     To:   <input type="text" name="message_to"> <br>
          Message: <br>
    <textarea rows="20" cols="50" name="message_content">
    </textarea>
    <?php
    echo '<input type="hidden" name="message_from" value="'.$user.'"><br>';
    ?>
    <input type="submit" name="submit" value="Submit">
    </form>

    <?php
     
    }
     
     }
     
    ?>

    Somewhere it's causing this error

    ( ! ) Parse error: syntax error, unexpected T_ELSE in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\pm system\new_message.php on line 41

    I'm 99% sure it in here

    PHP Code:
     $insert "INSERT INTO pmsys (to, from, title, message, date, ifread)
                 VALUES ('"
    .$to."', '".$from."', '".$title."', '".$content."', '".$date."', '".$ifread."')";
         
    $add_member mysql_query($insert); 

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    It's caused by

    PHP Code:
    else 
    {
    ?>     
     <form name="messa 
    The error message provides you with a lot of information

    ( ! ) Parse error: syntax error, unexpected T_ELSE in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\pm system\new_message.php on line 41
    When is this suppose to execute if the condition is met or isnt?
    PHP Code:
     $insert "INSERT INTO pmsys (to, from, title, message, date, ifread)
                 VALUES ('"
    .$to."', '".$from."', '".$title."', '".$content."', '".$date."', '".$ifread."')";
         
    $add_member mysql_query($insert); 
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    If the form has been submitted, It will upload it to the database. Otherwise It will display the form.
    The error only started when I put this code in
    PHP Code:
     $insert "INSERT INTO pmsys (to, from, title, message, date, ifread) 
                 VALUES ('"
    .$to."', '".$from."', '".$title."', '".$content."', '".$date."', '".$ifread."')"
         
    $add_member mysql_query($insert); 

  6. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Okay so you just need to add a curly brace before the else


    PHP Code:
     $insert "INSERT INTO pmsys (to, from, title, message, date, ifread)
                 VALUES ('"
    .$to."', '".$from."', '".$title."', '".$content."', '".$date."', '".$ifread."')";
         
    $add_member mysql_query($insert);




     } else 

    Corrections to my coding/thoughts welcome.

  7. #7
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    PHP Code:
    ?php

    require "database.php";
    $userfinal=$_COOKIE['ID_my_site'];  
    $user=$userfinal;
    echo $user;







     if (isset($_POST['submit'])) {

    echo "Thanks";

    $title=$_POST['message_title'];
    $to=$_POST['message_to'];
    $content=$_POST['message_content'];
    $from=$_POST['message_from'];
    $time=$_POST['message_date'];


    $ck_reciever = "SELECT username FROM users WHERE username = '".$to."'";

            
       
            if( mysql_num_rows( mysql_query( $ck_reciever ) ) == 0 ){
    die("The user you are trying to contact don\'t excist. Please go back and try again.<br> ");


     $insert = "INSERT INTO pmsys (to, from, title, message, date, ifread) 
                 VALUES ('".$to."', '".$from."', '".$title."', '".$content."', '".$date."', '".$ifread."')"; 
         $add_member = mysql_query($insert); 




     } else  

    ?>     
     <form name="message" action="new_message.php" method="post">
     Title:  <input type="text" name="message_title"> <br>
     To:   <input type="text" name="message_to"> <br>
          Message: <br>
    <textarea rows="20" cols="50" name="message_content">
    </textarea>
    <?php
    echo '<input type="hidden" name="message_from" value="'.$user.'"><br>';
    ?>
    <input type="submit" name="submit" value="Submit">
    </form>

    <?php
     
    }
     
     }
     
    ?>
    Is that how it should look because when I open it the whole page is blank

  8. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    if you don't have the cookie set, or $_POST['submit'], then you should get a blank page.


    1) if there's no cookie, then $user will be empty, and echo will print nothing.

    2) then, if the form was not submitted (likely, as it was never displayed), the first if() will be FALSE, and execution will skip to the end of the script.

    3) you're done, and nothing happened.
    (I suspect your first if() conditional is supposed to end earlier than it does. Also, even if your form was submitted, you'd never insert any records because you die() right before the lines that query the db.)



    Honestly, I would try rewriting this after planning out the structure a little more. All of your php code should come as early as possible, and be mostly (preferably completely) done by the time you start outputting html. Make a step-by-step outline of what needs to happen in php (if you do so here, I'll be happy to offer advice), then put the html at the end.

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    In addition to Traq's advice, if you for some reason want a blank page in certain circumstances, then for testing it will be a good idea to add some sort of feedback to be sure the page is working. A blank page can mean the page is not processing at all (there is some major error in parsing the PHP) or that there is nothing to show (no error, just no content). To fix that, you can add a single line at the end of your script, <?php echo 'Hello World'; ?>. This way at the very least you know your script has no parse errors. But generally you should just follow what Traq said.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    PHP Code:
    echo "Thanks"
    Thats why I put that in

Bookmarks

Posting Permissions

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