Php 从我的登录脚本中的多个表中提取

Php 从我的登录脚本中的多个表中提取,php,Php,截至:2013年6月4日下午7:37 CST,我们无法解决此问题 我有一个脚本,可以让我的用户登录并从数据库表中提取信息。现在,它从一个表中提取附属机构信息,并获取多个项目 我希望它能从附属机构信息和附属机构任务中提取,现在我只是在$会话['company\u name']=$row['company\u name']上方添加了以下内容并将所需代码添加到我的页面以响应它,但什么都没有发生 //pull from another table in the database

截至:2013年6月4日下午7:37 CST,我们无法解决此问题

我有一个脚本,可以让我的用户登录并从数据库表中提取信息。现在,它从一个表中提取附属机构信息,并获取多个项目

我希望它能从
附属机构信息
附属机构任务
中提取,现在我只是在
$会话['company\u name']=$row['company\u name']上方添加了以下内容
并将所需代码添加到我的页面以响应它,但什么都没有发生

//pull from another table in the database 
                        $res = mysql_query("SELECT * FROM `affiliate_tasks` WHERE `username` = '".$username."'");

                        $_SESSION['task_name'] = $row['task_name'];
                        $_SESSION['due_date'] = $row['due_date'];
                        $_SESSION['status'] = $row['status'];
这是完整的脚本:

<?php

include "scripts/user_managment/connect.php";


    //If the user has submitted the form
    if($_POST['submit']){
        //protect the posted value then store them to variables
        $username = protect($_POST['username']);
        $password = protect($_POST['password']);

        //Check if the username or password boxes were not filled in
        if(!$username || !$password){
            //if not display an error message
            echo '<meta http-equiv="Refresh" content="0;url=http://www.green-panda.com/website/panda/affiliates/login.php?msg=' . urlencode(base64_encode('A username and password is required!')) . '">';
        }else{
            //if the were continue checking

            //select all rows from the table where the username matches the one entered by the user
            $res = mysql_query("SELECT * FROM `affiliate_information` WHERE `username` = '".$username."'");
            $num = mysql_num_rows($res);

            //check if there was not a match
            if($num == 0){
                //if not display an error message
                echo '<meta http-equiv="Refresh" content="0;url=http://www.green-panda.com/website/panda/affiliates/login.php?msg=' . urlencode(base64_encode('The username and/or password does not match!')) . '">';
            }else{
                //if there was a match continue checking

                //select all rows where the username and password match the ones submitted by the user
                $res = mysql_query("SELECT * FROM `affiliate_information` WHERE `username` = '".$username."' AND `password` = '".$password."'");
                $num = mysql_num_rows($res);

                //check if there was not a match
                if($num == 0){
                    //if not display error message
                    echo '<meta http-equiv="Refresh" content="0;url=http://www.green-panda.com/website/panda/affiliates/login.php?msg=' . urlencode(base64_encode('The username and/or password does not match!')) . '">';
                }else{
                    //if there was continue checking

                    //split all fields fom the correct row into an associative array
                    $row = mysql_fetch_assoc($res);

                    //check to see if the user has not activated their account yet
                    if($row['active'] != 1){
                        //if not display error message
                        echo '<meta http-equiv="Refresh" content="0;url=http://www.green-panda.com/website/panda/affiliates/login.php?msg=' . urlencode(base64_encode('You have not yet activated your account!')) . '">';
                    }else{
                        //if they have log them in

                        //set the login session storing there id - we use this to see if they are logged in or not
                        $_SESSION['uid'] = $row['id'];

                        //pull from another table in the database 
                        $res = mysql_query("SELECT * FROM `affiliate_tasks` WHERE `username` = '".$username."'");

                        $_SESSION['task_name'] = $row['task_name'];
                        $_SESSION['due_date'] = $row['due_date'];
                        $_SESSION['status'] = $row['status'];

                        //get the users informaiton
                        $_SESSION['company_name'] = $row['company_name']; //get the company name 
                        $_SESSION['first_name'] = $row['first_name'];
                        $_SESSION['last_name'] = $row['last_name'];
                        $_SESSION['email_address'] = $row['email_address'];
                        $_SESSION['check_payable_to'] = $row['check_payable_to'];
                        $_SESSION['add_line_1'] = $row['add_line_1'];
                        $_SESSION['add_line_2'] = $row['add_line_2'];
                        $_SESSION['city'] = $row['city'];
                        $_SESSION['state'] = $row['state'];
                        $_SESSION['zip'] = $row['zip'];
                        $_SESSION['main_phone'] = $row['main_phone'];
                        $_SESSION['mobile_phone'] = $row['mobile_phone'];
                        $_SESSION['affiliate_since_date'] = $row['affiliate_since_date'];
                        $_SESSION['direct_deposit'] = $row['direct_deposit'];
                        $_SESSION['paper_check'] = $row['paper_check'];
                        $_SESSION['username'] = $row['username'];  //gets the username
                        $_SESSION['password'] = $row['password']; //get the password
                        $_SESSION['profile_pic_src'] = $row['profile_pic_src']; //gets the profile pic
                        $_SESSION['website_url'] = $row['website_url']; //gets the website
                        $_SESSION['account_balance'] = $row['account_balance']; 
                        $_SESSION['domain_count'] = $row['domain_count'];
                        $_SESSION['earning_count'] = $row['earning_count'];
                        $_SESSION['received_count'] = $row['received_count'];
                        $_SESSION['referrals_count'] = $row['referrals_count'];

                        //update the online field to 50 seconds into the future
                        $time = date('U')+50;
                        mysql_query("UPDATE `affiliate_information` SET `online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'");

                        //redirect them to the affiliate_informationonline page
                        echo '<meta http-equiv="Refresh" content="0;url=http://www.green-panda.com/website/panda/affiliates/index.php?msg=' . urlencode(base64_encode('You have successfully logged in!')) . '">';
                    }
                }
            }
        }
    }

    ?>

您实际上没有使用
$res
将其转换为
$row

插入

$row =  mysql_fetch_assoc($res);
在这两条线之间应该可以修复它。 如果不是,则SQL存在问题

同时避免使用mysql,而是使用PDO或mysqli_

更新:

试一试

           $aff_tasks = mysql_query("SELECT * FROM `affiliate_tasks` WHERE `username` = '".$username."'");
          $row_tasks =  mysql_fetch_assoc($aff_tasks);
                        $_SESSION['task_name'] = $row_tasks['task_name'];
                        $_SESSION['due_date'] = $row_tasks['due_date'];
                        $_SESSION['status'] = $row_tasks['status'];

您应该只连接表

SELECT *
FROM `affiliate_information` a_i
LEFT JOIN `affiliate_tasks` a_t ON a_i.`username` = a_t.`username`
WHERE a_i.`username` = 'SomeUsername'

如果您现在正在从头开始编写代码,请尝试使用PDO或mysqli。根据我的经验,这样做更容易操作。是的,添加它将从数据库返回行,而不仅仅是返回查询的标识符。我需要在何处插入
$row=mysql\u fetch\u row($res)这将导致从数据库中完全没有任何内容被拉入我的页面。包括以前已经存在的常规内容。我正在使用GoDaddy,但在我的文件中看不到它。我在控制面板中找到了错误日志。但似乎什么都没有。我将尝试添加@user2371301 left join was missing这是它给我的信息:'解析错误:语法错误,在/home/content/38/10473938/html/website/panda/affiliates/scripts/user_management/login.php中出现意外的T_字符串,位于第55行'@user2371301,为了让事情变得更清楚,我添加了php-sou你有干净的sql。
SELECT *
FROM `affiliate_information` a_i
LEFT JOIN `affiliate_tasks` a_t ON a_i.`username` = a_t.`username`
WHERE a_i.`username` = 'SomeUsername'