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
https://forums.phpfreaks.com/topic/77019-solved-if-statments-trouble/
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!

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.