这对我来说是一个持续存在的问题,在我插入我的数据库中的表后,我获取了刚刚使用$ user_id_number = mysqli_insert_id($ dbc)生成的ID;
我需要获取该值并将其插入到我刚刚插入的表中但是插入到不同的列中,这是我的代码
if (mysqli_num_rows($data) == 0) {
// The username is unique, so insert the data into the database
$query1 = "INSERT INTO user_register (user_email, user_password, register_date_time) VALUES ('$user_email', SHA('$user_password1'), NOW())";
mysqli_query($dbc, $query1);
//Grab the primary id key that was just created
$user_id_number = mysqli_insert_id($dbc);
//store Id key in variable for new directory name
$directory_name = 'user_id_'.$user_id_number;
//use id key to name directory
mkdir($directory_name);
//Add the new directory name in user_register table
$query2 = "UPDATE `user_register` SET `client_folder`= [$directory_name] WHERE user_id = $user_id_number";
mysqli_query($dbc, $query2);
它执行第一次插入,创建了目录但是没有继续将目录名更新到表中?!!?我也试过插入并获得相同的结果......任何想法?
ps ...我正在尝试创建一个新的目录,该目录使用来自主ID的信息命名,然后可以稍后调用,以便我可以在该目录中放置一个新目录
答案 0 :(得分:0)
由于$directory name
是一个字符串,您需要用引号括起来
client_folder = '$directory_name' WHERE user_id = $user_id_number";
//^here //^and here
答案 1 :(得分:0)
$ query2 =“更新user_register
设置client_folder
= [ $ directory_name * ] * WHERE user_id = $ user_id_number”;
删除“[”和“]”
答案 2 :(得分:-1)
更新查询:
$query2 = "UPDATE `user_register` SET `client_folder`= '$directory_name' WHERE user_id = $user_id_number";