doujia9204 2015-02-03 04:01
浏览 20
已采纳

php无法正常使用html

<?php
  if(!isset($_SESSION['c_id']) || (!isset($_SESSION['s_id'])))
  {
  ?>
  Login/Register
  <ul>
  <li>
  <a href="register.php">
  Student Login
  </a>
  </li>
  <li>
  <a href="register.php">
  Student Registration
  </a>
  </li>
  <li>
  <a href="company_register.php"">
  Company Login
  </a>
  </li>
  <li>
  <a href="company_register.php">
  Company Registration
  </a>
  </li>
  </ul>
  </li>
  <?php
  } 
  else
  {
  ?>
  <a href="logout_exec.php>Logout
  </a>
  </li>
  <?php
  }
  ?>
  </ul>

This is my code snippet,

When the user is logged in, even then Logoutis not being displayed, as clear from the post if the SESSION IDs are not set means the user is not logged in, in that case the content pertaining to that condition is being displayed however not the other way round

The login_exec.php file

include ("db_conn.php");

function clean_input($data)
{
$data = stripslashes($data);
$data = trim($data);
$data = htmlspecialchars($data);
return $data;
}
//registration form data validation

if(!empty($_POST['Go']))
{
$email= $password= "";
$email= clean_input($_POST['email']);
$pass= clean_input($_POST['pass']);
$pass = hash("sha256", $pass);
$type= $_GET['type'];

global $query;

if($type=="student")
{
$query= "SELECT * FROM STUDENT WHERE email='$email' AND password='$pass'";
}

elseif($type=="company")
{
$query= "SELECT * FROM COMPANY WHERE email='$email' AND password='$pass'";
}
echo $query;
$query1= mysqli_query($dbhandle,$query);
if(!$query1)
{
echo 'MySQL Error: ' . mysqli_error();
        exit;
        }

$count= mysqli_num_rows($query1);

if($count==0)
{echo "No Data";
}
else
{
while($row=mysqli_fetch_assoc($query1))
if($type=="student")
{

session_start();
$_SESSION['sname']= $row['F_Name'].' '.$row['L_Name'];
$_SESSION['s_id']= $row['id'];
header('Location: /Internshala/index.php?s_id='.$_SESSION['s_id']);

}
elseif($type=="company")
{
session_start();
$_SESSION['cname']=$row['Name'];
echo $_SESSION['cname'];
$_SESSION['c_id']=$row['c_id'];
header('Location: /Internshala/index.php?c_id='.$_SESSION['c_id']);
}
}
}
  • 写回答

4条回答 默认 最新

  • dongling4383 2015-02-03 05:14
    关注

    Finally...

    If using OR operator , then even if one of the SESSION variables are not set, the script will display everything except else's block.

    And even after using the AND operator when Coding Horror suggested that the if(condition) is wrong, it won't work. But while discussing with Fred ii, I noticed the mismatch between <?php and ?> towards the end, which finally made me discover a missing " here <a href="logout_exec.php>Logout. So this was the reason for the havoc.

    All help is much appreciated.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输