会话出错,它不起作用

时间:2015-05-30 10:38:45

标签: php

当我添加会话时(这是我第一次)我做错了什么因为它无法正常工作

这是comprobar_provisional.php的代码

 <?php
session_start()
$user = "Javier";
$password = "HolaJavier";
include 'inc/header.php';
include 'inc/funciones.php';
?>

<?php
$nombre = $_POST["nombre"];
$contraseña = $_POST["pass"];
if ($nombre != $user) {
    echo "El usuario es incorrecto";
}
elseif ($contraseña != $password) {
    echo "La contraseña no es correcta";
} 
else {
$_SESSION['Logueado'] == TRUE;
echo "<center><h1>". $user. ": Bienvenido al Panel de Control</h1></center>";
   echo '<form action="logout.php" method="post">
<input type="submit" value="salir"></form>';
   echo '<center>
<h4>Añadir Imagen</h4><hr>
<form method="POST" action="accion.php">
<div class="form-group">
Nombre: <input type="text" name="titulo"></input>
Link a Imagen: <input type="text" name="link"></input>
<input type="submit" name="enviar" value="Enviar"></input>
</div>
</form>
<center><hr><h3> ID + IMAGEN</h3>';
$x = 1;
      while($x<=36 AND list($circuit_id, $circuit) = each($circuits)){
        echo circuitos($circuit_id, $circuit);}
echo '
<h4>Eliminar Imagen</h4><hr>
<form method="POST" action="accion2.php">
Escribe ID <input type="text" name="id"></input>
<input type="submit" name="enviar2" value="Enviar"></input>';}
?>
<?
include '../inc/footer.php';
?> 

这是accion.php的代码

 <?php
    session_start();
    if($_SESSION['Logueado'] == TRUE) {
include 'inc/header.php';

$id = $_POST['id'];
$titulo = $_POST['titulo'];
$link = $_POST['link'];
$servername = "localhost";
$username = "ab";
$password = "123456";
$dbname = "ab";
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = "INSERT INTO circuito (nombre, image)
    VALUES ('$titulo', '$link')";
    // use exec() because no results are returned
    $conn->exec($sql);
    echo "Nueva imágen añadida correctamete.";
    echo '<br><a href="javascript:history.back()">
    <style type="text/css">   
    a:link   
    {   
    text-decoration:none;
    color:black
    }</style>
               <input type="button" value="Regresar"></input></a>';

$conn = null;

include '../inc/footer.php';
} else {
    echo "You didnt do login";
    }
?> 

当我这样做时,登录显示:你没有登录。

2 个答案:

答案 0 :(得分:2)

您的代码有

$_SESSION['Logueado'] == TRUE;

这是一个比较。你打算写的是

$_SESSION['Logueado'] = TRUE;

这是一项任务。

答案 1 :(得分:1)

在你的 comprobar_provisional.php

替换

else {
$_SESSION['Logueado'] == TRUE;

else {
$_SESSION['Logueado'] = TRUE;