dongyue6199 2015-11-11 21:06
浏览 19

PHP和SQL无法正确返回[关闭]

I'm trying to pull a three-character string from an SQL database and store it as a session, but it isn't working correctly.

Here is where I request the SQL query and set the session

$verified_query = mysql_query("SELECT verified FROM `members` WHERE username = '$myusername'");
$verified = mysql_result($verified_query, 0); // 0 is the index of the field, not the row

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION["myusername"] = $myusername;
$_SESSION["mypassword"] = $mypassword;
$_SESSION["verified"] = $verified;
header("location:index.php");
}
else {
echo "Wrong Username or Password";
}
?>

And here is where I try to get the session:

    <?php
session_start();
if(!$_SESSION["myusername"]){
include("./assets/inc/nli-home.inc.php");
}
else {
include("./assets/inc/connect.inc.php"); 
include("./assets/inc/header.inc.php");
if ($_SESSION["verified"] == "no") {
include("./assets/inc/settings.inc.php"); 
}
else {
}
if ($_SESSION["verified"] == "yes") {
    include("./assets/inc/settings-admin.inc.php"); 
}
else {}

include("./assets/inc/header2.inc.php"); 
include("./assets/inc/footer.inc.php");
}
?>
<script>console.log("<?php echo $_SESSION['verified'] ?>");</script>
  • 写回答

1条回答 默认 最新

  • dpa31905 2015-11-11 21:11
    关注
    $verified = mysql_result($verified_query, 0); // 0 is the index of the field, not the row
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($verified); <- Error was here
    
    评论

报告相同问题?

悬赏问题

  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表