Jump to content


new problems new headaches


1 reply to this topic

#1 replaya

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 18 July 2005 - 08:40 AM

Hiya,

I am trying to change between to urls on the index.php. Which will change from "Create An Account" to "Logout". Intially the index.php page will show the "Create an Account" url. When a user signs in it will then change to "Logout" url.
I have tried using the if and else statement but its not doing the desired output. can anyone help

Thanks for your help

**********Session start on index.php******************
<?php
session_start();
ob_start();
header("Cache-control: private"); //ie6 fix
require ($_SERVER['DOCUMENT_ROOT'].'project/config/db_connect.php');
?>

********code to check data in mysql database**************
<?php
if(isset($_POST['Login']) == 0 ) // login button clicked
echo "Guest"; // welcome guest
{
$query = "select * from customer where cust_username='" . $_POST ['cust_username'] . "' && cust_password='" . $_POST['cust_password'] . "'";

$result = mysql_query($query)
or die(mysql_error());

if(mysql_num_rows($result) == 1) {
$_SESSION['cust_username'] = $_POST['cust_username'];
$_SESSION['cust_password'] = $_POST['cust_password'];
$_SESSION['cust_firstname'] = $cust_firstname;
$_SESSION['logged'] = 1;

while($row = mysql_fetch_array($result)){
$cust_firstname = $row['cust_firstname']; echo $_SESSION['cust_firstname']; //changes from guest to firstname
}
}else{
exit();
}

}
?>
************Problem********using if & else - to change between the two*****
As you can see I ve numerous ways of getting to do what I want but it just not swtiching between the two
***************************************************
<?php
if(($_SESSION['logged']) == 0)
{
echo ' | <a href="newaccount.php">Create Account</a>';

}else{

if(($_SESSION['logged']) == 1)
echo ' | <a href="logout.php">Logout</a>';
}

// if(isset($_SESSION['logged']) == 0) {
// echo ' | <a href="newaccount.php">Create Account</a>';
// }
// if(isset($_SESSION['logged']) == 1) {
//echo ' | <a href="logout.php">Logout</a>';
// }
/* if((isset($_POST['Login']) == 0) && (empty($_POST['Login']) == '')) {
echo "<a href='index.php?action=REG&CODE=00'>";
echo "Create an account";
echo "</a>";
}else{

if(mysql_num_rows($result) == 1) {
$_SESSION['cust_username'] = $_POST['cust_username'];
$_SESSION['cust_password'] = $_POST['cust_password'];
$_SESSION['cust_firstname'] = $_cust_firstname;

echo "<a href='logout.php'>";
echo "Logout";
echo "</a>";
}
} */
?>

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 18 July 2005 - 06:41 PM

if(($_SESSION['logged']) == 0)
{ 
echo ' | <a href="newaccount.php">Create Account</a>'; 

}else{

if(($_SESSION['logged']) == 1)
echo ' | <a href="logout.php">Logout</a>';
}

Should be:
if($_SESSION['logged'] != 1)
{ 
echo ' | <a href="newaccount.php">Create Account</a>'; 
}else{
echo ' | <a href="logout.php">Logout</a>';
}

if that doesn't work, search php.net for sessions, they should be able to tell you a little more about how they work (and how you can go about what you're trying to do).

p.s. nifty little trick for ya.
echo "<a href='logout.php'>";
echo "Logout";
echo "</a>";
Can be changed to:
echo '<a href="logout.php">Logout</a>';






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users