Php 在id为自动递增的数据库中插入值

Php 在id为自动递增的数据库中插入值,php,mysql,post,Php,Mysql,Post,我想上传一个图像到数据库,并将值id、markerID(字符串,非唯一)、imagename(文本)、note(文本)和likes(int)添加到我的表钉板中 这是我的php Scirpt: if (isset($_POST["image"]) && isset($_POST["markerID"])) { $data = $_POST["image"]; $markerID = $_POST["markerID"]; $ImageName = $id."

我想上传一个图像到数据库,并将值id、markerID(字符串,非唯一)、imagename(文本)、note(文本)和likes(int)添加到我的表钉板中

这是我的php Scirpt:

if (isset($_POST["image"]) && isset($_POST["markerID"])) {
    $data = $_POST["image"];
    $markerID = $_POST["markerID"];
    $ImageName = $id.".png";
    $filePath = "CEimages/".$ImageName;
    echo "file ".$filePath;

    if (file_exists($filePath)) {
        unlink($filePath); //delete old file
    }

    $myfile = fopen($filePath, "w") or die("Unable to open file!");
    file_put_contents($filePath, base64_decode($data));

    //id, markerId, image, note, likes
    mysql_query("INSERT INTO pinboard VALUES ('', '{$markerID}', '{$ImageName}', '', '')") or die ('Could not save entry: '.mysql_error());
}
问题是我在哪里设置了$ImageName。我希望ImageName与id相等,因此它是uniqe。但是,当我添加这些值时(id是自动递增的),id会在以后设置。
如果行插入到同一脚本中,如何将ImageName设置为ID?

第一次插入记录时不使用out image name,而不是更新image path后的记录


获取您的最后一个id
mysql_insert_id()

第一次插入记录时不使用图像名称,而不是更新图像路径后插入的记录


获取您的最后一个id
mysql_insert_id()

第一次插入记录时不使用图像名称,而不是更新图像路径后插入的记录


获取您的最后一个id
mysql_insert_id()

第一次插入记录时不使用图像名称,而不是更新图像路径后插入的记录


获取您的最后一个id
mysql_insert_id()

您可以在插入查询之前使用
mysql\u insert\u id()
获取最后一个插入的id,然后可以将其递增并保存为图像名称

但是,如果应用程序同时运行多个操作,那么这不是理想的方法


此外,您应该使用mysqli或PDO而不是mysql。

您可以在插入查询之前使用
mysql\u insert\u id()
获取最后插入的id,然后可以将其递增并保存为图像名称

但是,如果应用程序同时运行多个操作,那么这不是理想的方法


此外,您应该使用mysqli或PDO而不是mysql。

您可以在插入查询之前使用
mysql\u insert\u id()
获取最后插入的id,然后可以将其递增并保存为图像名称

但是,如果应用程序同时运行多个操作,那么这不是理想的方法


此外,您应该使用mysqli或PDO而不是mysql。

您可以在插入查询之前使用
mysql\u insert\u id()
获取最后插入的id,然后可以将其递增并保存为图像名称

但是,如果应用程序同时运行多个操作,那么这不是理想的方法


另外,您应该使用mysqli或PDO而不是mysql。

如果图像名称等于id,为什么还要存储它呢?
$ImageName=$id.“.png”
do?如果图像名称等于id,为什么还要存储它呢?
$ImageName=$id.“.png”
do?如果图像名称等于id,为什么还要存储它呢?
$ImageName=$id.“.png”
do?如果图像名称等于id,为什么还要存储它呢?
$ImageName=$id.“.png”做?谢谢你,新代码:
if(isset($\u POST[“image”]){$data=$\u POST[“image”];$markerID=$\u POST[“markerID”];mysql\u查询(“插入到钉板值('''.'''.''','');$id=mysql\u INSERT\u-id();$ImageName=$id.“.png”;$filePath=“CEimages/“$ImageName;echo”文件“$filePath;如果(文件存在($filePath)){unlink($filePath);}$myfile=fopen($filePath,“w”);file_put_contents($filePath,base64_decode($data));mysql_query(“更新钉板集图像='$ImageName'其中id='$id');}
谢谢,新代码:
if(isset($\u POST[“image”]){$data=$\u POST[“image”];$markerID=$\u POST[“markerID”]);mysql_query查询(“插入插接板值(“”,{$markerID},“”,“”,“”)”;$id=mysql_INSERT_id();$ImageName=$id.“.png”;$filePath=“CEimages/”$ImageName;echo“file”。$filePath;如果(file_存在($filePath)){unlink($filePath);}$myfile=fopen($filePath,“w”);file_放入内容($filePath,base64_解码($data));mysql查询(”更新钉板集image='$ImageName',其中id='$id'');
谢谢,新代码:
if(isset($\u POST[“image”]){$data=$\u POST[“image”];$markerID=$\u POST[“markerID”];mysql_查询(“插入钉板值('''.'''.'''.'','');$id=mysql=mysql_INSERT_id;$ImageName=$id.“.png”;$filePath=“CEimages/“$ImageName;echo”file.“$filePath;if(file_exists($filePath)){unlink($filePath)}$myfile=fopen($filePath,“w”);file_put_contents($filePath,base64_decode($data));mysql_query(“更新插接板设置图像='$ImageName'其中id='$id');}
谢谢,新代码:
if(isset($\u POST[“image”])){$data=$\u POST[“image”]$markerID=$\u POST[“markerID”];mysql_query(“插入插接板值(''''{$markerID}',''''','''','');$id=mysql_插入_id();$ImageName=$id.“.png”;$filePath=“CEimages/”$ImageName;echo“文件”。$filePath;如果(file_存在($filePath)){unlink($filePath);$myfile=fopen($filePath,“w”);文件内容($filePath,base64_decode($data));mysql_查询(“更新钉板集图像='$ImageName'其中id='$id');}