Jump to content

Recommended Posts

Hi i got this page im working on for fun and I had it loggig in and the sessions working properly then it just stopped.

 

heres the code

 

db_connect();
session_start();

$name = $_POST["name"];
$direc = $_POST["director"];
$age = $_POST["age"];
$genre = $_POST["genre"];
$user = $_POST["username"];
$password = $_POST["password"];

if(isset($_SESSION["loggedin"]))
{
print'<form method="post" action="admin.php">
<fieldset>
<label for="name" id="name">Title:</label>
<input type="text" name="name" />

<label for="director" id="director">Director:</label>
<input type="text" name="director" />

<label for="genre" id="genre">Genre:</label>
<input type="text" name="genre" />

<label for="age" id="age">Age:</label>
<select name="age">
<option value="new">New</option>
<option value="recent">Recent</option>
<option value="old">Old</option>
</select>

<label></label>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</fieldset>
</form>';

if($_POST["name"] != "")
{

$sql = "insert into movies 
	(movie_name, movie_director, genre, age) 
	values ('$name','$direc','$genre','$age') ";

mysql_query($sql);

print"Success!";

}
}
else
{

print'<form method="post" action="admin.php">
<fieldset>
<label for="username" id="name">Username:</label>
<input type="text" name="username" />

<label for="password" id="director">Password:</label>
<input type="password" name="password" />

<label></label>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</fieldset>
</form>';

$pass = crypt($password, chicken);

if($_POST["username"] != "")
{

$sql = "select * from user where username = '$user' and password = '$pass'";

$r = mysql_query($sql);

if(mysql_affected_rows()==0)
{
print"Invalid user or pass!";
print"$user, $pass";
}
else
{

session_register('loggedin');

print"Session set!";

}
}
}
?>

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/112668-session-wont-register/
Share on other sites

put session_start(); before db_connect();

 

ACE

 

Unless he's trying to utilize session vars in db_connect(); that doesn't really matter.  All that really matters is that you have it before any output and before trying to utilize session vars. 

 

Hi i got this page im working on for fun and I had it loggig in and the sessions working properly then it just stopped.

 

You're going to have to be more specific than that.

 

Trying to navigate to another page and there's no session? Could mean that you don't have session_start(); at the new page.  session_start(); must be on any page you wish to have access. 

 

If you do have that squared away, do you have cookies enabled? If you do not have cookies enabled, the server has no idea what your session id is, so it can't access your session data.

 

If you have that squared away, be more specific about your problem.  Any error messages? At what point does it "stop working," and what does that mean? Blank values? Again, be more specific about your problem.

HI sorry for leaving stuff out

 

Everything goes on in this one admin page, you login and if there is a valid session i want it to show the other form not the login one.

 

Umm yer cookies are enabled.

 

No error messages it i put this into the section for setting session

print"Session set!";

and it says that so i dont know why it is not setting the session.

 

Well it was working unitl i tryed to make a logout page. when it stopped working i deleted that page and re wrote the admin one and it still didnt work.....

 

 

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.