dtwzwmv87399 2014-03-24 00:01
浏览 7
已采纳

如何检测用户是否接受了条款?

Basically I am writing a PHP and MYSQL script that will check whether a user has accepted the terms and conditions or not. In the databse every current user that has signed up is set to "unaccepted". When they log in the first page that they are directed to should have a scirpt on it that detects whether or not the status of the tos column in the users table is set to "accepted" or "unaccepted". If it is accepted they can continue, and if it is not they they will be forced to go to a page and accept them before they can continue to use the rest of my site. This is the code so far but it doesn't seem to be working. Any suggestions help.

<?php

$username=$_SESSION['username'];
$connect = mysql_connect('**', '**', '**', '**');
if (!$connect) 
{
    die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('**')) 
{
    die('Could not select database: ' . mysql_error());
}
$toschecker = mysql_query("SELECT `tos` FROM `users` WHERE `username` = '$username'");
if (!$toschecker) 
{
    die('Could not query:' . mysql_error());
}
mysql_close($connect);
$unaccepted='unaccepted';

if ($toschecker === $unaccepted)
{
    header('Location: accepttos.php');
}    
?>

For some reason this isn't directing them to the accepttos.php page. Thanks in advance.

  • 写回答

3条回答 默认 最新

  • dongzan9069 2014-03-24 00:11
    关注

    Change MySQL to MySQLi. Explanations are in the comments.

    <?php
    
    $username = $_SESSION['username'];
    $connect = mysqli_connect('Host', 'Username', 'Password', 'Database');
    if (!$connect) 
    {
        die('Could not connect: ' . mysql_error());
    }
    
    $toschecker = mysqli_query($connect,"SELECT `tos` FROM `users` WHERE `username` = '$username'"); /* SELECT TOS COLUMN */
    
    while ($row = mysqli_fetch_array($toschecker)) 
    {
        $tos = $row['tos']; /* STORE TO A VARIABLE THE FETCHED TOS */
    }
    
    $unaccepted = 'unaccepted';
    
    if ($tos == $unaccepted) /* COMPARE THE TOS VARIABLE IF UNACCEPTED */
    {
        header('Location: accepttos.php');
    }
    
    else {
        header('Location: acceptedTOS.php'); /*  IF TOS IS ACCEPTED. CHANGE THE LOCATION */
    }
    
    mysqli_close($connect);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错