如何修复错误“数据库/文件和会话”?

时间:2019-11-19 06:15:18

标签: php session mysqli

我的代码有错误。问题是,文件没有插入数据库表中,而是插入到位置文件夹中。我发现错误是由会话引起的,它没有从第一页获取用户ID,因此在另一页上也发生了同样的事情。你们有没有给我一些建议或帮助我容易找到错误(删除,更新等),代码如下:

第一页-注册表单页面(.php)

<?php

include "dbConnection.inc";

if(isset($_POST['signup']))
{
error_reporting(1);

    $Email=$_POST['email'];

    $que1="select * from `users` where Email='$Email'";
    $count1=$que1->num_rows;

    if($count1>0)
    {
        echo "<script>
                alert('There is an existing account associated with this email.');
            </script>";
    }
    else
    {
        $Name=$_POST["first_name"].' '.$_POST["last_name"];
        $gender=$_POST["gender"];
        $country=$_POST["country"];
        $work=$_POST["work"];
        $password=$_POST["password"];


        $query="INSERT INTO `users` (`user_id`, `Name`, `Email`, `gender`, `country`, `profession/occupation`, `Password`) VALUES (NULL, '$Name', '$Email', '$gender', '$country', '$work', '$password');";
        $cmd=$conn->query($query);

        session_start();
        $_SESSION['tempfbuser']=$Email;

        if ($cmd==true) {
            header("Location:completepro.php");
        } else {
            echo "<script>
                alert('Sign Up not successful, please try again');
            </script>";
            header("Location:signin.php");

        }

    }
}
?>

第二页-注册表单页面(.php)

<?php

    session_start();
    include "dbConnection.inc";

    error_reporting(1);
    if(isset($_SESSION['tempfbuser']))
    {
        $user=$_SESSION['tempfbuser'];
        $que1="select * from users where Email='$user' ";
        $rec="$que1->fetch_array();";
        $userid=$rec[0];


                if(isset($_POST['file1']) && ($_POST['file1']=='Upload'))
                {
                    $path = "twigp_users/".$user."/Profile/";
                    $path2 = "twigp_users/".$user."/Post/";
                    $path3 = "twigp_users/".$user."/Cover/";
                    mkdir($path, 0, true);
                    mkdir($path2, 0, true);
                    mkdir($path3, 0, true);

                    $img_name=$_FILES['pro_file']['name'];
                    $img_tmp_name=$_FILES['pro_file']['tmp_name'];
                    $prod_img_path=$img_name;
                    move_uploaded_file($img_tmp_name,"twigp_users/".$user."/Profile/".$prod_img_path);

                    $query="INSERT INTO `user_profile_pic` (`profile_id`, `user_id`, `image`) VALUES (NULL, '$userid', '$img_name');";
                    $cmd=$conn->query($query);
                }


                if(isset($_POST['file2']) && ($_POST['file2']=='Upload'))
                {
                    $path = "twigp_users/".$user."/Profile/";
                    $path2 = "twigp_users/".$user."/Post/";
                    $path3 = "twigp_users/".$user."/Cover/";
                    mkdir($path, 0, true);
                    mkdir($path2, 0, true);
                    mkdir($path3, 0, true);

                    $img_name=$_FILES['cvr_file']['name'];
                    $img_tmp_name=$_FILES['cvr_file']['tmp_name'];
                    $prod_img_path=$img_name;
                    move_uploaded_file($img_tmp_name,"twigp_users/".$user."/Cover/".$prod_img_path);
                        $query="INSERT INTO `user_cover_pic` (`cover_id`, `user_id`, `image`) VALUES (NULL, '$userid', '$img_name');";
                        $cmd=$conn->query($query);
                }

  }

?>

请帮助我找出错误,谢谢!!!

1 个答案:

答案 0 :(得分:-2)

检查以下代码

<?php

    session_start();
    include "dbConnection.inc";

    error_reporting(1);
    if(isset($_SESSION['tempfbuser']))
    {
        $user=$_SESSION['tempfbuser'];
        $que1="select * from users where Email='$user' ";
        $rec="$que1->fetch_array();";
        $userid=$rec[0];


                if(isset($_POST['file1']) && ($_POST['file1']=='Upload'))
                {
                    $path = "twigp_users/".$user."/Profile/";
                    $path2 = "twigp_users/".$user."/Post/";
                    $path3 = "twigp_users/".$user."/Cover/";
                    mkdir($path, 0, true);
                    mkdir($path2, 0, true);
                    mkdir($path3, 0, true);

                    $img_name=$_FILES['pro_file']['name'];
                    $img_tmp_name=$_FILES['pro_file']['tmp_name'];
                    $prod_img_path=$img_name;
                    move_uploaded_file($img_tmp_name,"twigp_users/".$user."/Profile/".$prod_img_path);

                    $query="INSERT INTO `user_profile_pic` (`profile_id`, `user_id`, `image`) VALUES (NULL, '$userid', '$img_name');";
                    $cmd=$conn->query($query);
                }


                if(isset($_POST['file2']) && ($_POST['file2']=='Upload'))
                {
                    $path = "twigp_users/".$user."/Profile/";
                    $path2 = "twigp_users/".$user."/Post/";
                    $path3 = "twigp_users/".$user."/Cover/";
                    mkdir($path, 0, true);
                    mkdir($path2, 0, true);
                    mkdir($path3, 0, true);

                    $img_name=$_FILES['cvr_file']['name'];
                    $img_tmp_name=$_FILES['cvr_file']['tmp_name'];
                    $prod_img_path=$img_name;
                    move_uploaded_file($img_tmp_name,"twigp_users/".$user."/Cover/".$prod_img_path);
                        $query="INSERT INTO `user_cover_pic` (`cover_id`, `user_id`, `image`) VALUES (NULL, $userid, $img_name);";
                        $cmd=$conn->query($query);
                }

  }

?>