-1
$sql = "INSERT INTO memberadd (username,password,profilepic) VALUES ('$username','$password','$profilepic')";

上面的代码是注册图片上传

$imagedataprofile = "INSERT INTO imagedbgallery (postid,imageupload) VALUES ('$postid','$profilepic')";

上面的代码试图将数据传递到另一个表

我的 memberadd 表(下)

用户名(PK) | 用户名 | 密码 | 用户照片

我的 imagedbgallery 表(下)

imageid(PK) | 用户名 | 图片上传

我试图实现的事情是,当用户插入记录时: memberadd 表将显示

1 | tommy | 12345 |tommyprofile.png

并且在 imagedbgallery 表中将显示

1,1,tommyprofile.png

==================================================== ========================= 但是当我尝试运行代码时,

memberadd 表将显示

1 | tommy | 12345 |tommyprofile.png

并且在 imagedbgallery 表中将显示

1,0,tommyprofile.png
4

1 回答 1

0

只需在您的 memberadd 表中设置 userid(PK) 自动增量,然后执行查询

 $sql = "INSERT INTO memberadd (username,password,profilepic) VALUES ($username, $password, $profilepic)";
 mysql_query($sql);

现在使用此查询获取最后插入的 id

$lastId = mysql_insert_id();

现在传入这个 id

$imagedataprofile = "INSERT INTO imagedbgallery (imageid, postid,imageupload) VALUES ($lastId, $postid, $profilepic)";
于 2018-10-12T07:08:44.990 回答