Jump to content


Photo

if statements for submit


  • Please log in to reply
6 replies to this topic

#1 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 19 March 2006 - 08:25 AM

i was wondering about something.
i have a login script and ir runs on a frames page with a header and a contents.

i am wondering if i can use an if statement to refresh the page when a user logs in/logs out.

reson being that i want it to tell them if they are loggeg in at the header.

this is my code:

<?
SESSION_START();
header("Cache-control:private");
INCLUDE('functions.php');


echo("<table align='center'>
<form action='login.php?act=start' method='POST'>
<tr><td>Username:</td><td><input type='text' name='username'></td></tr>
<tr><td>Password:</td><td><input type='password' name='password'></td></tr>
<tr><td><input type='submit' name='submit' value='Login'></td>
</form>
<td>Or Just Sign Up <a href=\"register.php\">Now!!!</a></td></tr></table>");
if($_GET['act'] == "start") {
if(!$_POST['username'] || !$_POST['password']) {
echo("<a href=\"javascript:history.go(-1)\">Go back and fill out all fields, correctly!");
} else {
$passwordshow=$_POST['password'];
$username=$_POST['username'];
$password=$_POST['password'];
$check=mysql_query("SELECT * FROM `users` WHERE username = '$username' && password = '$password'")or die(mysql_error());
$CNumb=mysql_num_rows($check);

if($CNumb == '0') {
echo("<center>The username/password was invalid! Please Fix The Errors And Try Again and try again!</center>");
} else {
session_register('$username');
session_register('$password');
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;


echo "
<script language='javascript'>
window.location = \"members1.php\";
</script>"; }

}
}
?>
<body bgcolor="#000000" text="#FFFFFF"><center>LongSlong Productions Is Affiliated With LickMy9 And FishBoard Productions. All Rights Reserved Copyright 2006-2007

</body>

i am wonderin if i could have a:

if ($submit)
refresh here

or

have it go in this code part here:

else {
session_register('$username');
session_register('$password');
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;


echo "
<script language='javascript'>
window.location = \"members1.php\";
</script>

Refresh's Here"; }

}


Please Help.
Thanks In Advance

#2 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 19 March 2006 - 08:54 AM

yes you can do that but this code may work a little better


if(isset($_POST['submit'])){
header("Location: members1.php");
//or you can place your javascript here but his will do the same thing
} 

i hope this helps
The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way

#3 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 19 March 2006 - 10:46 AM

[!--quoteo(post=356368:date=Mar 19 2006, 03:54 AM:name=shortj75)--][div class=\'quotetop\']QUOTE(shortj75 @ Mar 19 2006, 03:54 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
yes you can do that but this code may work a little better


if(isset($_POST['submit'])){
header("Location: members1.php");
//or you can place your javascript here but his will do the same thing
} 

i hope this helps
[/quote]

how can i also make this refresh the page at the same time?

also another question
but now i am getting this error in my header:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/mike/public_html/functions.php:11) in /home/mike/public_html/header.php on line 9

Warning: Cannot modify header information - headers already sent by (output started at /home/mike/public_html/functions.php:11) in /home/mike/public_html/header.php on line 10

this is the code in my header:
<?
INCLUDE('functions.php'); 

  
//Main page for the login.
//you must login to be able to view this page


SESSION_START(); 
header("Cache-control:private"); 
INCLUDE('functions.php'); 
 

if($_SESSION['username'] && $_SESSION['password']) { 

$username=$_SESSION['username']; 

$sql_check = mysql_query("SELECT datejoined FROM users WHERE username='$username'"); 
$sql_check_num = mysql_num_rows($sql_check); 



while($a_row = mysql_fetch_array($sql_check))

$datejoined= $a_row["datejoined"];

echo "Welcome Back $username!..<br>";
echo "Member Since: $datejoined<br>";
echo "<A href='logout.php?sid=".$sid."' target='main'>Log Out</a>";
echo "<a href='/images.php' target='main'>Update Account Information</a>";


} else { 



echo " 
You Are Not Logged In<br><a href='/login.php' target='main'>Login</a>";

}

$sql = @mysql_query("SELECT userid FROM users") or die 

(mysql_error());

while($a_row = mysql_fetch_array($sql))

$currentmembers= $a_row["userid"];
echo "There Are Currently $currentmembers Registered Members<br>";

$sql = @mysql_query("SELECT username FROM users") or die 

(mysql_error());

while($a_row = mysql_fetch_array($sql))

$latestuser= $a_row["username"];
echo "Latest Member: $latestuser";

?>


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 March 2006 - 10:53 AM

if(isset($_POST['submit'])){
header("Location: members1.php");
//or you can place your javascript here but his will do the same thing
}
If you use the above code then it will redirect the user straight away to members1.php andy code after the header() fucntion will not be processed so you will not be able to make the page refresh! Why do you want the page to refresh?

#5 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 19 March 2006 - 11:05 AM

[!--quoteo(post=356384:date=Mar 19 2006, 05:53 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Mar 19 2006, 05:53 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if(isset($_POST['submit'])){
header("Location: members1.php");
//or you can place your javascript here but his will do the same thing
}
If you use the above code then it will redirect the user straight away to members1.php andy code after the header() fucntion will not be processed so you will not be able to make the page refresh! Why do you want the page to refresh?
[/quote]
i am wanting the page to refresh beacuase i have a frame page and when the user is not logged in the header will display that they are not logged in. and if they are it will display that they are logged in. but when working with frame pages the header (top page) never refresh's as only the main page (inside) changes. I would like to have it all refresh when they log in or log out.

#6 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 19 March 2006 - 11:17 AM

if this will help here is the link to my site [a href=\"http://www.longslongproductions.com\" target=\"_blank\"]http://www.longslongproductions.com[/a]
don't mind the name as it is only a comedy site

#7 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 19 March 2006 - 11:43 AM

this post is closed problem not resolved




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users