Php Mysql_insert_id()无法从第一个查询中获取值并在第二个查询中使用。两个查询都用于插入,但在两个不同的表中

Php Mysql_insert_id()无法从第一个查询中获取值并在第二个查询中使用。两个查询都用于插入,但在两个不同的表中,php,mysql,Php,Mysql,我想使用MySQL\u insert\u id从第一个查询中获取一个值,该值以PropertyImageID的名称自动递增,这是我的PropertyImageID表中的最后一列,我的第二个表中也有PropertyImageID相同的值,即propertyimages第一个表列,并在第二个查询中使用它在第二个表中插入值 但它给出了以下错误信息: 警告:mysql\u insert\u id()要求参数1为 资源,布尔值在..第31行中给出 以下是我的代码(我没有在查询中编写自动递增列): 无标题

我想使用MySQL\u insert\u id从第一个查询中获取一个值,该值以PropertyImageID的名称自动递增,这是我的PropertyImageID表中的最后一列,我的第二个表中也有PropertyImageID相同的值,即propertyimages第一个表列,并在第二个查询中使用它在第二个表中插入值

但它给出了以下错误信息:

警告:mysql\u insert\u id()要求参数1为 资源,布尔值在..第31行中给出

以下是我的代码(我没有在查询中编写自动递增列):


无标题文件
PropertyName:

属性状态:

属性ID:



更改此选项

$id=mysql_insert_id($propertyqueryrun) or die(mysql_error());


无需传递查询参数,它只需要可选的链接参数

无需在
mysql\u insert\u id()
中传递参数。您可以使用获取上次插入的
id
,而无需传递
$propertyqueryrun

$id = mysql_insert_id() or die(mysql_error());

您应该在insert查询之后声明它,并且为它指定了错误的参数

<?php
    require_once('db.php');
    @$PropertyName=$_POST['pname'];
    @$PropertyStatus=$_POST['pstatus'];
    @$PropertyID=$_POST['propertyid'];
    if(isset($_FILES['file_upload']))
    {

    $propertyquery="INSERT INTO properties(PropertyID,PropertyName,PropertyStatus) 
    VALUES('$PropertyID', '$PropertyName', '$PropertyStatus')";
    $propertyqueryrun=mysql_query($propertyquery) or die(mysql_error());
   $insert_id=mysql_insert_id();
      if($propertyqueryrun)
         {
         echo '<br><br> The Property Information Insertion was Successfully';
         }
              else
         {
                  echo '<br><br> Property Insertion Failed';
         }

    $shuff=str_shuffle("ABD6565LSLFKDSAJFD");

    mkdir("upload/$shuff");

    $files=$_FILES['file_upload'];


    for($x = 0; $x < count($files['name']); $x++)
    {
      $name=$files['name'][$x];

      $tmp_name=$files['tmp_name'][$x];

         if(move_uploaded_file($tmp_name, "upload/$shuff/".$name))
         {
         $id= $insert_id;

         $imagequery="INSERT INTO propertyimages(PropertyImageID,ImageName, 

    ImagePath)   VALUES('$id','$name','$name')";

             $imagequeryrun=mysql_query($imagequery);

             echo 'Image '. $name .' Uploaded Successfully <br>';
         }
         else
         {
             echo 'uploading images failed failed';
         }

    }

    }
    ?>

mysql\u insert\u id()我找不到这意味着
mysql\u查询
失败。@YadavChetan在浏览器中使用ctrl+f
$id=mysql\u insert\u id($propertyqueryrun)
你读过有关的文档吗?我按你写的方式编辑代码,但我得到了“列计数与第1行的值计数不匹配”;然后插入querytry时出错现在我已经编辑了queryya,收到了一百万谢谢,但是每当我在框中输入错误的值,并且它在DB中检查验证时,一个数字被自动跳过,当我下次插入有效值时,它跳过一个。。如何解决这个问题??????@user2279037您应该在进入数据库之前进行验证
$id = mysql_insert_id() or die(mysql_error());
<?php
    require_once('db.php');
    @$PropertyName=$_POST['pname'];
    @$PropertyStatus=$_POST['pstatus'];
    @$PropertyID=$_POST['propertyid'];
    if(isset($_FILES['file_upload']))
    {

    $propertyquery="INSERT INTO properties(PropertyID,PropertyName,PropertyStatus) 
    VALUES('$PropertyID', '$PropertyName', '$PropertyStatus')";
    $propertyqueryrun=mysql_query($propertyquery) or die(mysql_error());
   $insert_id=mysql_insert_id();
      if($propertyqueryrun)
         {
         echo '<br><br> The Property Information Insertion was Successfully';
         }
              else
         {
                  echo '<br><br> Property Insertion Failed';
         }

    $shuff=str_shuffle("ABD6565LSLFKDSAJFD");

    mkdir("upload/$shuff");

    $files=$_FILES['file_upload'];


    for($x = 0; $x < count($files['name']); $x++)
    {
      $name=$files['name'][$x];

      $tmp_name=$files['tmp_name'][$x];

         if(move_uploaded_file($tmp_name, "upload/$shuff/".$name))
         {
         $id= $insert_id;

         $imagequery="INSERT INTO propertyimages(PropertyImageID,ImageName, 

    ImagePath)   VALUES('$id','$name','$name')";

             $imagequeryrun=mysql_query($imagequery);

             echo 'Image '. $name .' Uploaded Successfully <br>';
         }
         else
         {
             echo 'uploading images failed failed';
         }

    }

    }
    ?>