dpus81500574 2017-02-24 10:56
浏览 60

如何使用mysqli在mysql数据库中插入数据,数据检查在同一个“日期”中没有相同的“id”

guy's i need your help. im trying to make an insert form with php with this condition.

"id cant be same in same date"

my database name is : "ssl",
table name is : "try"
with table col: "id", "date", "name", "city"

im have try a lot to make this but still get some eror. but when i delete the php script for checking it can running well..

please help me. im really apreciated when you give me an example of that.

sorry for my english and sorry im still newbie and need study more for something like this

this my script for insert

<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "silo");


// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}


// Attempt insert query execution
$sql="Insert into termocouple 
        Select * from temp1";
if(mysqli_query($link, $sql)){
    echo "Data inserted successfully.";
} else{
    echo "Data inserted Failed " . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?>
  • 写回答

1条回答 默认 最新

  • dphdh395195 2017-02-24 11:34
    关注

    can i just use something like this? i get from Copy rows from one table to another, ignoring duplicates

    <?php
    $sql="INSERT INTO termocouple
    SELECT no,tanggal,silo,... 
    FROM temp1
    WHERE NOT EXISTS(SELECT * 
                     FROM destTable 
                     WHERE (temp1.no=termocuple.no and
                           temp1.tanggal=termocouple.s_tanggal...etc.)
                     )";
                     ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大