Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从mysql字段中选择数据并将值用作php变量_Php_Mysql - Fatal编程技术网

从mysql字段中选择数据并将值用作php变量

从mysql字段中选择数据并将值用作php变量,php,mysql,Php,Mysql,我不熟悉php和mysql。我试图在一个名为users的mysql数据库中使用一个布尔值(tinyint)。如果“pay”字段的值为0,我想将用户发送到我的pay.php页面;如果值为1,并且登录详细信息正确,我想将用户发送到index.php。然而,无论数据库中的值是0还是1,代码都会将用户发送到pay.php。任何帮助都将不胜感激 $query = mysql_query("SELECT * FROM `users` WHERE username = '$username' AND pass

我不熟悉php和mysql。我试图在一个名为users的mysql数据库中使用一个布尔值(tinyint)。如果“pay”字段的值为0,我想将用户发送到我的pay.php页面;如果值为1,并且登录详细信息正确,我想将用户发送到index.php。然而,无论数据库中的值是0还是1,代码都会将用户发送到pay.php。任何帮助都将不胜感激

$query = mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$password'") or die (mysql_error()); // mySQL query

$r = mysql_num_rows($q); // Checks to see if anything is in the db.
$row = mysql_fetch_array($query);
if($row['paid'] == 0);{     //NOT WORKING!!!    
    header ("location:pay.php");// go to pay.php
    exit( );// Stops the rest of the script.
}

if ($r == 1) { // There is something in the db. The username/password match up.
    $_SESSION['logged'] = 1; // Sets the session.
    header ("location:index.php");// go to index.php
}
else { // Invalid username/password.
    exit("Incorrect username/password!"); // Stops the script with an error message.        
}
去掉那里的分号:

if($row['paid'] == 0){
去掉那里的分号:

if($row['paid'] == 0){

. 它们不再得到维护。看到了吗?相反,学习,并使用or-将帮助您决定哪一个。如果选择PDO,。请注意此
If($r==1){
If($r==1)的值是多少。它们不再被维护。请参阅?了解,然后使用或-将帮助您决定哪个。如果选择PDO,。请注意此
If($r==1){
r的价值是什么?$r好的!半天浪费在一个错误的分号上!试图投票支持你,但我没有足够的声誉!好的!半天浪费在错误的分号上!试图投票支持你,但我没有足够的声誉!