duanji1899 2013-12-03 11:18
浏览 52

尝试将其插入数据库时​​,无法识别我的用户ID会话cookie

I have a customer details form I am trying to insert into my Customer table. The insertion isn't working, but I've identified that it's the session cookie at fault, by changing the $user_ID to a '1' and then it successfully inserted into the database. I'd really appreciate help in identifying where I've gone wrong with setting or calling my session cookie, or what I should do to get it to work. Thanks.

Setting the session cookie on login:

$sql = "SELECT User_ID, Username, Password, User_Level
        FROM Account
        WHERE Username = '$username' AND  Password = '$password'";

    $record = mysql_query($sql);

    $row = mysql_fetch_array($record);

if(mysql_num_rows($record) == 0){
    die(header("location: LoginFailed.html"));


}else if(mysql_num_rows($record) == 1){
    $row = mysql_fetch_array($record);
    $_SESSION["User_ID"] = $row["User_ID"];
    $_SESSION["User_Level"] = $row["User_Level"];
    header("location:Home.html");

}
    else{$row = mysql_fetch_array($record);

    $_SESSION["User_ID"] = $row["User_ID"];
    $_SESSION["User_Level"] = $row["User_Level"]; 
    header("location: Home.html");
}

mysql_close();

Assigning the session cookie to a variable in php:

session_start();
$user_ID = $_SESSION['User_ID'];

The insertion code used:

    INSERT INTO Customer (User_ID, Forename, Surname, Address1, Address2, Town, Country, Postcode, Phone_No, Mobile, dob, Emergency_Name, Emergency_Number, Nationality, Profession, Academic_Qual, Volunteer_Reason) 
VALUES ('$user_ID', '$regForename', '$regSurname', '$regAddress1', '$regAddress2', '$regTown', '$regCountry', '$regPostcode', '$regPhone', '$regMobile', '$regDOB', '$regEmergencyName', '$regEmergencyPhone', '$regNationality', '$regProfession', '$regQualification', '$regVolunteer')";

I tried an echo of the sql code and the User_ID is blank so it is failing to obtain it, at all. Really appreciate your help.

  • 写回答

1条回答 默认 最新

  • dongqu4443 2013-12-03 11:29
    关注

    according your description,When ‘echo’ SQL , the User_ID is blank, you need check the variable $user_ID has value , and should also check table Customer field Use_ID‘s type , it’s int or varchar ? it can be null ? it's unique ? If you do not know what i say, you can post your table structure.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line