MySQL更新数据库错误

时间:2013-12-21 16:04:18

标签: mysql database

我试图这样做,当你按下按钮时,它会将'subscribe'的值更新为1,但由于某种原因,它不起作用。

<?php
session_start();
$userid = $_SESSION['userID'];
$username = $_SESSION['username'];
require '../../core/connect.php';

if ($_SESSION['userID']) {
    if (isset($_POST['subscribe'])) {

        $query2 = mysql_query("UPDATE `users` SET `subscribe`='1' WHERE `username`='".$username."'") or die(mysql_error());

        if ($query2) {
            header("Location: /index.php");
        } else {
            echo "An error occured. Your subscription failed! Please try again later.";
        }
    }else {
        echo "Error occured.";
    }
}else {
    echo "No session found.";
}
?>

我得到的错误是'错误发生。'

该字段是一个int,默认值为0

谢谢!

2 个答案:

答案 0 :(得分:1)

'发生错误'暗示

if(isset($_POST['subscribe'])) // is evaluating to false

使用

print_r($_POST) // and post the result

答案 1 :(得分:0)

if(isset($_SESSION['subscribe']))