PHP and MYSQL sessions

592
<?php
require_once 'includes/config.php';
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE name='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");
}
$guest=1;
isset($_SESSION){
$guest=0;
}
else {
echo "Wrong Username or Password";
}?>

I have this code, but i don't know how to make an integer like... $guest or something like this, if $guest==1, the user is a guest else if $guest==0 the user is a logged member. I've tried with isset but i failed, can someone help me?

432

Answer

Solution:

try this :

if( $_SESSION['myusername'] != null && $_SESSION['myusername'] != "")
{
$guest=0;
}

and so on...

People are also looking for solutions to the problem: form with jquery ajax no picture coordinates from php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.