Jump to content

[SOLVED] If Statments trouble.


liquid79

Recommended Posts

My code is below, the problem is if it finds the username in the datbase it displays the message fine, but if it doesnt find it it just shows a blank white page they dont move on to the else statment. Im not sure what im doing wrong. Any Help would be great trying to make it work for a few days now with not much luck. Thanks!

 

<?php
require_once ('settings.php');
checkLogin('1 2');
session_start();

if ($_SESSION['logged_in']):


    $username1 = get_username($_SESSION['user_id']);

    $sql = mysql_query("SELECT * FROM details_temp2 WHERE username = '$username1'");
    while ($row = mysql_fetch_object($sql)) {

        // Check to see if there is a match of details and display yes, no or Contact an admin! when $completed is called.

        if ($row->username == $username1) {

            echo '<font color="#FF2A2A"><h2>ERROR: You have already Sumbited your details please use the <em><a href="update_property.php" class="white_link"> Update details link</a></em> to make changes. Thankyou</h2>
</font>'; // Error Message If it finds the username in the database


        } else {

            echo ' <font color="#FF2A2A">Welcome you can carry on <p> All details etc here</font>'; // if it finds no details it will allow the person to carry on.
        }
    }

endif; ?>

Link to comment
Share on other sites

ok thanks guys im still only learning PHP but getting there slowly! Is it possible you could give me an example where the {} should go on my first if statement? ( i have removed the endif) I have added the if (mysql_num_rows($sql) > 0); after my sql query as suggested but should i now echo something also to check it ? My code now:

 

<?php

session_start();

require_once ('settings.php');

 

 

$username1 = get_username($_SESSION['user_id']);

 

$sql = mysql_query("SELECT * FROM details_temp2 WHERE username = '$username1'");

if (mysql_num_rows($sql) > 0);

while ($row = mysql_fetch_object($sql)) {

 

    // Check to see if there is a match of details with the session username and display which is the case.

 

    if ($row->username == $username1) {

 

        echo '<font color="#FF2A2A"><h2>ERROR: You have already Sumbited your details please use the Update details link to make changes.</h2>

</font>'; // Error Message If it finds the username in the database

 

 

    } else {

 

        echo ' <font color="#FF2A2A">Welcome you can carry on '; // if it finds no details it will allow the person to carry on.

    }

}

?>

 

Thanks again!

Link to comment
Share on other sites

try

<?php
session_start();
require_once ('settings.php');


$username1 = get_username($_SESSION['user_id']);

$sql = mysql_query("SELECT * FROM details_temp2 WHERE username = '$username1'");
if (mysql_num_rows($sql) > 0){
while ($row = mysql_fetch_object($sql)) {

    // Check to see if there is a match of details with the session username and display which is the case.

    if ($row->username == $username1) {

        echo '<font color="#FF2A2A"><h2>ERROR: You have already Sumbited your details please use the Update details link to make changes.</h2>
</font>'; // Error Message If it finds the username in the database


    }
else {

        echo ' <font color="#FF2A2A">Welcome you can carry on '; // if it finds no details it will allow the person to carry on.
    }
}
}
else{
echo "No results Found.";
}
?>

 

Make sense?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.