Web Hosting Talk







View Full Version : serious help needed


Gamenati
05-28-2003, 10:02 PM
ok, this ones a little rough...

when someone click on a link to post a comment, it takes them to a page where --if they are signed in-- they enter it, but if there not signed in, it displaies a login thing

THE PROBLEM: (this happens to everyone but me) it asks them to sign in everytime, and when the hit submit to sign in, it says "you are already signed in"

the code:


<?
session_start() ;
?>


<?php

if (!$id) {
echo "No news selected." ;
}
else {

$db = mysql_connect ("localhost", "gamenati_revolve", "rmb1990") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("gamenati_everything");


$sql = "SELECT * FROM news WHERE newsid LIKE '$id' " ;
$results = mysql_query($sql) ;

$data = mysql_fetch_array($results) ;

if ($_SESSION['username']) {
$url = "/news/postcom.php?id={$id}" ;

?>
Comment for "<? echo "<a href='/news/fullstory.php?id={$id}' class='nav'>".$data['title']."</a>"; ?>":<form method="post" action="/news/postcom2.php?id=<? echo $id; ?>"><br>
<textarea style="color:000000;background:71C60C;border: 0px #000000 solid" cols="50" rows="4" name="com"></textarea><p>

<center><input type="submit" value="Submit" style="color:000000;background:71C60C;border: 0px #000000 solid"> <input type="reset" value="Reset" style="color:000000;background:71C60C;border: 0px #000000 solid"></form>
<?
}
else {
?>

<table border="0" width="488" cellpadding="0" cellspacing="0"><form method="post" action="/users/signin2.php?url=<? echo $url; ?>">
<tr><td width="244"><font color="71C60C">Username</font></td><td width="244"><input style="color:000000;background:71C60C;border: 0px #000000 solid" type="text" size="20" name="username"></td></tr>
<tr><td width="244"><font color="71C60C">Password</font></td><td width="244"><input style="color:000000;background:71C60C;border: 0px #000000 solid" type="password" size="20" name="password"></td></tr>
<tr><td align="center" width="488" colspan="2"><br><input style="color:000000;background:71C60C;border: 0px #000000 solid" type="submit" value="Signin"> <input style="color:000000;background:71C60C;border: 0px #000000 solid" type="reset" value="Reset"></td></tr>
</form></table>

<?
}
}
?>




which takes them to this page:



<?


session_start() ;
?>
<?php



$username = $_POST['username'] ;
$password = $_POST['password'] ;



if (!$_SESSION['username']) {


session_register("username") ;
session_register("password") ;
}
else {
$in = 1 ;
}

?>


<?php

if (!$in) {
$password = md5($password) ;
$db = mysql_connect ("localhost", "gamenati_revolve", "rmb1990") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("gamenati_everything");

$sql = "SELECT usernumber, username, password FROM users1
WHERE username = '$username'
AND password = '$password' " ;

$results = mysql_query($sql) ;
$data = mysql_fetch_array($results) ;

if (!$data['username']) {
echo "Either your username or password is incorrect." ;
session_unregister("username") ;
session_unregister("password") ;
}
else {
if (!$url) {
$url = "/home.php" ;
}
echo "You have successfully signed in. <a href='{$url}' class='nav'>Continue &middot;></a>" ;
}
}
else {
echo "You are already signed in." ;
}

?>





Thank you so much if you can help!!!!!!

Gamenati
05-29-2003, 03:21 PM
anyone? am i not being specific enough?

Rich2k
05-29-2003, 06:13 PM
I don't know if it's relevant in this case but the PHP manual states that you shouldn't mix $_SESSION with session_register()