Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: blank screen when no requests!

  1. #1
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Question blank screen when no requests!

    on my friends request screen, when i have no new friend requests, it echoes a blank screen, i have tried tirelessly to insert an 'else' statement to echo 'You have no new friend requests' but failed everytime.

    i was wondering if u guys could help?
    this is newfriends.php:
    PHP Code:
    <?
    include("include/session.php");
    session_start(); // starts sessions
    include "config.php"// inlcudes config

    if ($session->logged_in) { //checks user is logged in
    switch ($_GET[friends]) { //allows multiple pages
    default:
    $get mysql_query"SELECT * FROM `friend_requests` WHERE `username` = '$session->username' "); //gets requests
    while ($reqs mysql_fetch_array($get))
    {

    echo ( 
    "<font color='black' face='Arial'><u><b>Friend Requests</b></u></font><br><br>
    <font color='#003399' face='Arial'><b>
    $reqs[by]</b></font><b></b> wants to be friends with you!<br>
    [<a href='newfriends.php?friends=accept&user=
    $reqs[by]'>Accept</a>]
    [<a href='newfriends.php?friends=delete&user=
    $reqs[by]'>Ignore</a>]
    [<a href='userinfo.php?user=
    $reqs[by]' target='blank'>View Profile</a>]" ); //displays requests and shows accept delete links
    }
    break;


    case 
    'accept'//accept page
    if ($_GET[user]) { //get username

    $add mysql_query"INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '$session->username') "); // add to your friends list
    $add2 mysql_query"INSERT INTO `friends` (`friendname` , `username`) VALUES ('$session->username' , '$_GET[user]') "); // fix friend bug
    $delete mysql_query"DELETE FROM `friend_requests` WHERE `by` = '$_GET[user]'"); // deletes friend request
    echo ( "$_GET[user] has been added as a friend! [<a href='userinfo.php?user=$reqs[by]' target='blank'>View Profile</a>] [<a href='newfriends.php'>More Requests?</a>] [<a href='index.php'>Home</a>]" ); // echos the completion
    }
    break; 
    //ends accept page

    case 'delete'// delete page
    if ($_GET[user]) { //gets username
    $delete mysql_query"DELETE FROM `friend_requests` WHERE `by` = '$_GET[user]' "); // deletes friend request
    echo ( "$_GET[user]'s request has been Ignored!
    [<a href='index.php'>Home</a>] " 
    ); // echos completion
    }
    break; 
    //ends delete page
    // ends switch
    } else {
    echo ( 
    "You need to be logged in!" ); // not logged in
    }
    ?>
    any help would be appreciated! thanx
    Last edited by liamallan; 04-15-2010 at 08:02 PM.

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

    Default

    Is the "blank screen" due to no output or to an error?
    Sometimes PHP will not reach the end of the code and not display ANYTHING.

    Add to the end of your code echo 'it works'; so that you can see if it is working, or if there is a problem with the PHP. If it gets all the way to the end, then it is time to debug the script specifically; if not, there is a bigger problem.
    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

  3. #3
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    yeah, echoed 'it works' with no problem

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

    Default

    What are all of these actions? I mean, what is $_GET['friends'] and in which case(s) is it not working? It's hard to fix a lot of code with little information.

    Where do you want to insert "you have no friends"?


    The switch statement is hard to read. Usually if statements are simpler and easier to use unless the switch is simple. Switches get VERY messy once there is a lot going on inside them.

    Also, in a switch statement the default is supposed to go at the end of everything. Maybe that's part of it? I don't know if it must go at the end, but I know that it can go at the end-- case, case, ...., default
    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

  5. #5
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    the code works fine, only that there is nothing to echo 'no requests' if the user has no new requests. this section below echoes the friend request and accept, delete and view profile links:
    PHP Code:
    while ($reqs mysql_fetch_array($get))
    {

    echo ( 
    "<font color='black' face='Arial'><u><b>Friend Requests</b></u></font><br><br>
    <font color='#003399' face='Arial'><b>
    $reqs[by]</b></font><b></b> wants to be friends with you!<br>
    [<a href='newfriends.php?friends=accept&user=
    $reqs[by]'>Accept</a>]
    [<a href='newfriends.php?friends=delete&user=
    $reqs[by]'>Ignore</a>]
    [<a href='userinfo.php?user=
    $reqs[by]' target='blank'>View Profile</a>]" ); //displays requests and shows accept delete links
    }
    break; 
    i was thinking the else statement would be in this section of code, i dont know if it would be before the break or after.

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Would mysql_num_rows work?
    PHP Code:
    if(mysql_num_rows($query) <= 0
    Or would it be
    [php]
    PHP Code:
    if(mysql_num_rows($query) <= -1
    djr33 I need your help... haha
    Jeremy | jfein.net

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

    Default

    if (mysql_num_rows($query)==0)
    http://www.php.net/manual/en/functio...l-num-rows.php

    It returns false on failure. This means if == 0/False, so that should work. Alternatively, if (mysql_num_rows($query)>=1) or >0, depending on what you want to do.
    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

  8. #8
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    thanx for that guys it now echoes 'you have no new friend requests' if a user has none, but now i get a blank error screen if a user has a request.
    this is the code i have now:
    PHP Code:
    while ($reqs mysql_fetch_array($get))

    $get mysql_query"SELECT * FROM `friend_requests` WHERE `username` = '$session->username' ");
    if (
    mysql_num_rows($get)==0){
        echo (
    "<font color='black' face='Arial'><u><b>Friend Requests</b></u></font><br><br>You have no new friend requests");
      }
    else{
        echo ( 
    "<font color='black' face='Arial'><u><b>Friend Requests</b></u></font><br><br>
    <font color='#003399' face='Arial'><b>
    $reqs[by]</b></font><b></b> wants to be friends with you!<br>
    [<a href='newfriends.php?friends=accept&user=
    $reqs[by]'>Accept</a>]
    [<a href='newfriends.php?friends=delete&user=
    $reqs[by]'>Ignore</a>]
    [<a href='userinfo.php?user=
    $reqs[by]' target='blank'>View Profile</a>]" ); //displays requests and shows accept delete links
    }
    break; 
    considering what you said earlier daniel, there must be something wrong in the code between echoing 'you have no new friend requests' and echoing the actual friend request.
    any ideas?

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

    Default

    if (...) { //this works }
    else { //this does not work }

    That doesn't make sense. What if you replace the echo with echo 'test'; to be sure there is no problem with the contents of that echo.
    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
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    it cant be the echo, still getting blank error screen after changing to test.

    this is the full code:
    PHP Code:
    <?
    if ($session->logged_in) { //checks user is logged in
    switch ($_GET[friends]) { //allows multiple pages
    default:
    $get mysql_query"SELECT * FROM `friend_requests` WHERE `username` = '$session->username' "); //gets requests
    while ($reqs mysql_fetch_array($get))

    $get mysql_query"SELECT * FROM `friend_requests` WHERE `username` = '$session->username' ");
    if (
    mysql_num_rows($get)==0){
        echo (
    "<font color='black' face='Arial'><u><b>Friend Requests</b></u></font><br><br>You have no new friend requests");
      }
    else{
        echo ( 
    "<font color='black' face='Arial'><u><b>Friend Requests</b></u></font><br><br>
    <font color='#003399' face='Arial'><b>
    $reqs[by]</b></font><b></b> wants to be friends with you!<br>
    [<a href='newfriends.php?friends=accept&user=
    $reqs[by]'>Accept</a>]
    [<a href='newfriends.php?friends=delete&user=
    $reqs[by]'>Ignore</a>]
    [<a href='userinfo.php?user=
    $reqs[by]' target='blank'>View Profile</a>]" ); //displays requests and shows accept delete links
    }
    break;


    case 
    'accept'//accept page
    if ($_GET[user]) { //get username

    $add mysql_query"INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '$session->username') "); // add to your friends list
    $add2 mysql_query"INSERT INTO `friends` (`friendname` , `username`) VALUES ('$session->username' , '$_GET[user]') "); // fix friend bug
    $delete mysql_query"DELETE FROM `friend_requests` WHERE `by` = '$_GET[user]'"); // deletes friend request
    echo ( "$_GET[user] has been added as a friend! [<a href='userinfo.php?user=$reqs[by]' target='blank'>View Profile</a>] [<a href='newfriends.php'>More Requests?</a>] [<a href='index.php'>Home</a>]" ); // echos the completion
    }
    break; 
    //ends accept page

    case 'delete'// delete page
    if ($_GET[user]) { //gets username
    $delete mysql_query"DELETE FROM `friend_requests` WHERE `by` = '$_GET[user]' "); // deletes friend request
    echo ( "$_GET[user]'s request has been Ignored!
    [<a href='index.php'>Home</a>] " 
    ); // echos completion
    }
    break; 
    //ends delete page
    // ends switch
    } else {
    echo ( 
    "You need to be logged in!" ); // not logged 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
  •