为什么当我在编码中添加SESSION_START时它不会起作用。 [英] Why when I add SESSION_START in my coding it wont function.
本文介绍了为什么当我在编码中添加SESSION_START时它不会起作用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的索引页面中添加SESSION START后,当我点击我的登录但它会停留在我的登录页面而不是我的索引页面
请帮助我
我尝试过:
这是我的登录页码< br $>
< title > 登录
@import url(css / styles.css);
< center >
< div class = 容器 >
< < span class =code-leadattribute> div class = container-fluid >
< div class = b >
< h1 > RB COUNSELING < / h1 >
< / div >
< h2 < span class =code-keyword>> 欢迎使用RB咨询< / h2 >
< p >
还不是会员?< a href = home.php > 注册< / a > < / p >
< 表 border = 1 width = 300 height = 150 > < tbody > < tr > < td > 用户名:< / td > < td < span class =code-keyword>> < / td > < / tr > < tr > < td > 密码< / td > < td > ; < / td > < / tr > < tr > < td colspan = 5 align = cente r > < / td > < / tr > < / tbody > < / table >
< / div > < / div > < / center >
<? php
session_sta室温();
mysql_connect( localhost, root, )或 die(mysql_error());
mysql_select_db( registration)或 die(mysql_error());
if (isset($ _ POST [' 登录']))
{
$ username = $ _ POST [' 名称跨度>];
$ pass = $ _ POST [' password'];
if($ username == ' ')
{
echo alert('请输入用户名')跨度>;
exit();
}
if($ pass == ' ')
{
echo alert ('请输入密码');
exit();
}
其他{
$ query = ' SELECT * FROM`user`其中`username` ='。$ username。' 和`password` ='。$ pass。' ';
$ r = mysql_query($ query);
if (mysql_num_rows($ r)> 0){
$ _SESSION [' 用户名'] = $ username ;
header( location:index.php);
} else {
echo ' 您的密码和用户名不匹配';
}
}
}
?>
这是我的索引页代码
< !doctype html >
* {margin:0px; padding:0px;}
#main {border:1px solid black;宽度:450像素;高度:500像素;保证金:24px auto;}
#message_area {width:98%;边框:1px纯蓝色;身高:440px;}
<? Php session_start();
if(isset($ _ SESSION [' username'])){
echo ' Welcome'。$ _ SESSION [ ' username'];
echo ' < a href = logout.php>退出< / a>< br>';
} else {
header( location:login1.php);
}
?>
< div id = main >
< div id = message_area >
< / div >
<? Php
mysql_connect( localhost, root, )或 die(mysql_error());
mysql_select_db( registration)或 die(mysql_error());
if(isset($ _ POST [' submit' ])){
$ message = $ _ POST [' 消息跨度>];
$ query = ' INSERT INTO`message`(`id`,`message`, `username`)
VALUES(,'。$ message。' , '。$ _ SESSION [' username']。' )';
if(mysql_query($ query)){
echo ' < h4 style =color:red>'。$ _ SESSION [' username']。' < / h4>';
echo ' < p>'.$message.' < / p>';
}
}
?>
< / div >
解决方案
_POST [' 登录']) )
{
username =
_POST [' 名称跨度>];
after i add SESSION START in my index page when i click my login buttuon it will stay at my login page and not go to my indexpage
PLEASE HELP ME
What I have tried:
this is my loginpage code
<title>Login
@import url("css/styles.css");
<center>
<div class="container">
<div class="container-fluid">
<div class="b">
<h1>RB COUNSELING</h1>
</div>
<h2>Welcome to RB Counseling</h2>
<p>
Not yet a member?<a href="home.php">Sign Up</a></p>
<table border="1" width="300" height="150"><tbody><tr> <td>Username:</td> <td></td></tr><tr> <td>Password</td> <td></td></tr><tr> <td colspan="5" align="center"></td></tr></tbody></table>
</div></div></center>
<?php
session_start();
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("registration") or die (mysql_error());
if (isset($_POST['Login']))
{
$username=$_POST ['name'];
$pass=$_POST ['password'];
if($username=='')
{
echo "alert('Please enter the username')";
exit();
}
if($pass=='')
{
echo "alert('Please enter the password')";
exit();
}
else{
$query='SELECT * FROM `user` where `username`="'.$username.'" and `password`="'.$pass.'"';
$r = mysql_query($query);
if (mysql_num_rows ($r) > 0){
$_SESSION['username'] = $username;
header("location:index.php");
}else{
echo 'your password and username do not match';
}
}
}
?>
this is my indexpage code
<!doctype html>
*{margin:0px; padding:0px;}
#main{border:1px solid black; width:450px; height:500px; margin:24px auto;}
#message_area{width:98%; border:1px solid blue; height:440px;}
<?Php session_start();
if(isset($_SESSION['username'])){
echo 'Welcome '.$_SESSION['username'];
echo '<a href="logout.php">Log out</a><br>';
}else{
header("location:login1.php");
}
?>
<div id="main">
<div id="message_area">
</div>
<?Php
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("registration") or die (mysql_error());
if(isset($_POST['submit'])){
$message =$_POST['message'];
$query='INSERT INTO `message` (`id`,`message`,`username`)
VALUES ("","'.$message.'","'.$_SESSION['username'].'")';
if(mysql_query($query)){
echo '<h4 style="color: red">'.$_SESSION['username'].'</h4>';
echo '<p>'.$message.'</p>';
}
}
?>
</div>
解决方案
_POST['Login'])) {
username=
_POST ['name'];
这篇关于为什么当我在编码中添加SESSION_START时它不会起作用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文