Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Another error

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

    Default

    but if the form is not submitted yet, then you won't see that. And the form won't be printed because you have it inside the same if() block. look over your code carefully (and I'd recommend indenting it properly to make it easier to read, and catch these kinds of mistakes):
    PHP Code:
    ?php //<--- you didn't start with <?php
    // that's another possible cause of your blank page

    require "database.php"
    $userfinal=$_COOKIE['ID_my_site'];   
    $user=$userfinal
    echo 
    $user//<-- if there is no cookie, then $user will be empty
    // and you won't see any output.

    // if this is the case, and you also don't see any errors,
    // (probably something like "Warning: undefined index 'ID_my_site'")
    // then you need to turn on error reporting


     
    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   
    //<-- this "else" closes "if mysql_num_rows([...]) === 0"
    // but we're _still_inside_ "if isset($_POST['submit'])"
    {  
    ?>      
     <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 
     
    }   //<-- this is where the else for "mysql_num_rows([....]) === 0" ends
      
     
    }  //<-- this is where "isset($_POST['submit'])" ends
    // as you can see, _nothing_happens_ if the form is not submitted,
    //  and you'll get a blank page.
     
    ?>

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

    Default

    Quote Originally Posted by traq View Post





    } else //<-- this "else" closes "if mysql_num_rows([...]) === 0"
    // but we're _still_inside_ "if isset($_POST['submit'])"
    {
    but when I change it to this

    PHP Code:
     } }else   //<-- this "else" closes "if mysql_num_rows([...]) === 0"
    // but we're _still_inside_ "if isset($_POST['submit'])"

    It comes up with this error

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

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

    Default

    On line 58 or 60 remove the closing bracket since you already closed it on 41, you should also adjust your syntax to use indents that would make this much easier to read.

    PHP Code:
     }  //<-- this is where "isset($_POST['submit'])" ends 


    Indented


    PHP Code:
    <?php
    // that's another possible cause of your blank page

    require "database.php"
    $userfinal=$_COOKIE['ID_my_site'];   
    $user=$userfinal
    echo 
    $user//<-- if there is no cookie, then $user will be empty
    // and you won't see any output.

    // if this is the case, and you also don't see any errors,
    // (probably something like "Warning: undefined index 'ID_my_site'")
    // then you need to turn on error reporting


    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 {
    // below is displayed if submit is not set
    ?>      
    <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 
    }   //<-- this is where the else for isset submit ends
    ?>
    You should also escape all of these
    PHP Code:
        $title=$_POST['message_title']; 
        
    $to=$_POST['message_to']; 
        
    $content=$_POST['message_content']; 
        
    $from=$_POST['message_from'];
        
    $time=$_POST['message_date']; 
    http://php.net/manual/en/function.my...ape-string.php
    http://en.wikipedia.org/wiki/SQL_injection
    Last edited by bluewalrus; 08-23-2011 at 03:59 PM.
    Corrections to my coding/thoughts welcome.

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

    Default

    The form isn't inserting anything into the sql database. Any help?

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

    Default

    please post the current version of the code you're working with, along with any output/errors.

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

    Default

    I think your conditional is off, this should do it

    PHP Code:
    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 {       
     
    $insert "INSERT INTO pmsys (to, from, title, message, date, ifread)  
            VALUES ('"
    .$to."', '".$from."', '".$title."', '".$content."', '".$date."', '".$ifread."')";  
            
    $add_member mysql_query($insert);  
        } 
    Assuming that SQL is checking if the user exisits.
    Corrections to my coding/thoughts welcome.

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

    Default

    ( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\pm system\new_message.php on line 20
    Call Stack
    # Time Memory Function Location
    1 0.0006 375632 {main}( ) ..\new_message.php:0
    2 0.0144 382488 mysql_num_rows ( ) ..\new_message.php:20


    Thats the error I got after changing the code you suggested, Blue Walrus.


    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']; 

        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 {        
     
    $insert "INSERT INTO pmsys (to, from, title, message, date, ifread)   
            VALUES ('"
    .$to."', '".$from."', '".$title."', '".$content."', '".$date."', '".$ifread."')";   
            
    $add_member mysql_query($insert);   
        }  


    } else {
    // below is displayed if submit is not set
    ?>      
    <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 
    }   //<-- this is where the else for isset submit ends
    ?>
    Thats the full code

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

    Default

    This thread is reaaally dragged out.

    Pay attention to this line:
    PHP Code:
    if( mysql_num_rowsmysql_query$ck_reciever ) ) == 
    Nowhere in your code is $ck_reciever declared, therefore mysql_query() is querying nothing, returning false (and a false value is passed as the parameter to mysql_num_rows(), which is why you're getting a an error that a boolean value is being passed as the parameter to mysql_num_rows().'

    I think when bluewalrus asked you to change the code, he assumed that you would leave the query in the code.

    Try this:
    PHP Code:
    <?php
    // that's another possible cause of your blank page

    require "database.php"
    $userfinal=$_COOKIE['ID_my_site'];   
    $user=$userfinal
    echo 
    $user//<-- if there is no cookie, then $user will be empty
    // and you won't see any output.

    // if this is the case, and you also don't see any errors,
    // (probably something like "Warning: undefined index 'ID_my_site'")
    // then you need to turn on error reporting


    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 {       
     
    $insert "INSERT INTO pmsys (to, from, title, message, date, ifread)  
            VALUES ('"
    .$to."', '".$from."', '".$title."', '".$content."', '".$date."', '".$ifread."')";  
            
    $add_member mysql_query($insert);  
        }  
    ?>      
    <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 
    }   //<-- this is where the else for isset submit ends
    ?>
    - Josh

  9. #19
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Hi everyone, I'm sorry this is taking so long. When I submit the form, nothing happens. It is still displaying my username, but the message isn't submitted. Also I can put anything I want into the to field of the form and it is not coming up with the , the user you are trying to contact does not excist,.

    PHP Code:
    <?php
    // that's another possible cause of your blank page

    require "database.php"
    $userfinal=$_COOKIE['ID_my_site'];   
    $user=$userfinal
    echo 
    $user//<-- if there is no cookie, then $user will be empty
    // and you won't see any output.

    // if this is the case, and you also don't see any errors,
    // (probably something like "Warning: undefined index 'ID_my_site'")
    // then you need to turn on error reporting


    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 {       
     
    $insert "INSERT INTO pmsys (to, from, title, message, date, ifread)  
            VALUES ('"
    .$to."', '".$from."', '".$title."', '".$content."', '".$date."', '".$ifread."')";  
            
    $add_member mysql_query($insert);  
        }  
    ?>      
    <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 
    }   //<-- this is where the else for isset submit ends
    ?>
    That's the current code. Any help?

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

    Default

    Well, following your code by the output that you said, the only logical possibility is that $ck_receiver doesn't return zero rows, which means that conditional that determines if it is zero defaults to the else, and attempts to execute your SQL syntax. But, it's not. Which means there is probably an SQL error blocking it from executing.

    Try adding or die(mysql_error()); to the end of your mysql_query() like so:
    PHP Code:
    $add_member mysql_query($insert) or die(mysql_error()); 
    - Josh

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
  •