如何从会话中保存数据

时间:2018-05-14 20:10:45

标签: php session

会话从页面索引发送到页面插入表单访问只是主键而不是电子邮件保存在另一个表中。请帮我。在页面索引中显示会话的所有代码

的index.php

    if(isset($_POST['login']))
{
    $email=$_POST['email'];
    $password=md5($_POST['password']);
    $sql ="SELECT EmailAddress,cpassword FROM tblcompany WHERE EmailAddress=:email and cpassword=:password";
    $query= $dbh -> prepare($sql);
    $query-> bindParam(':email', $email, PDO::PARAM_STR);
    $query-> bindParam(':password', $password, PDO::PARAM_STR);
    $query-> execute();
    $results=$query->fetchAll(PDO::FETCH_OBJ);
    if($query->rowCount() > 0)
    {
        $_SESSION['alogin']=$_POST['email'];
        echo "<script type='text/javascript'> document.location = 'dashboard.php'; </script>";
    } else{

        echo "<script>alert('Invalid Details');</script>";

    }

}

Insert.php

if(isset($_POST['submit']))
{
    $RegistrationNumber=$_POST['RegistrationNumber'];
    $ModelCode=$_POST['ModelCode'];
    $DailyHireRate=$_POST['DailyHireRate'];
    $VehicleYear=$_POST['VehicleYear'];
    $VehicleColour=$_POST['VehicleColour'];
    $SeatCapacity=$_POST['SeatCapacity'];
    $vimage1=$_FILES["vimage1"]["name"];
    $vimage2=$_FILES["vimage2"]["name"];
    $vimage3=$_FILES["vimage3"]["name"];
    $companyid=$_SESSION['alogin'];
    move_uploaded_file($_FILES["vimage1"]["tmp_name"],"img/vehicleimages/".$_FILES["vimage1"]["name"]);
    move_uploaded_file($_FILES["vimage2"]["tmp_name"],"img/vehicleimages/".$_FILES["vimage2"]["name"]);
    move_uploaded_file($_FILES["vimage3"]["tmp_name"],"img/vehicleimages/".$_FILES["vimage3"]["name"]);


    $sql="INSERT INTO tblvehicle(RegistrationNumber,ModelCode,DailyHireRate,VehicleYear,VehicleColour,SeatCapacity,Vimage1,Vimage2,Vimage3,CompanyID) VALUES(:RegistrationNumber,:ModelCode,:DailyHireRate,:VehicleYear,:VehicleColour,:SeatCapacity,:vimage1,:vimage2,:vimage3,:companyid)";
    $query = $dbh->prepare($sql);
    $query->bindParam(':RegistrationNumber',$RegistrationNumber,PDO::PARAM_STR);
    $query->bindParam(':ModelCode',$ModelCode,PDO::PARAM_STR);
    $query->bindParam(':DailyHireRate',$DailyHireRate,PDO::PARAM_STR);
    $query->bindParam(':VehicleYear',$VehicleYear,PDO::PARAM_STR);
    $query->bindParam(':VehicleColour',$VehicleColour,PDO::PARAM_STR);
    $query->bindParam(':SeatCapacity',$SeatCapacity,PDO::PARAM_STR);
    $query->bindParam(':vimage1',$vimage1,PDO::PARAM_STR);
    $query->bindParam(':vimage2',$vimage2,PDO::PARAM_STR);
    $query->bindParam(':vimage3',$vimage3,PDO::PARAM_STR);
    $query->bindParam(':companyid',$companyid,PDO::PARAM_STR);
    $query->execute();
    $lastInsertId = $dbh->lastInsertId();
    if($lastInsertId)
    {
        $error="Something went wrong. Please try again";
    }
    else
    {
        $msg="Vehicle posted successfully";
    }

}

如何从会话中访问数据而不是电子邮件,但id作为主键保存在另一个表中。修订版

0 个答案:

没有答案
相关问题