gpt4 book ai didi

php - 如何在php中使用时间戳

转载 作者:行者123 更新时间:2023-11-27 23:41:39 25 4
gpt4 key购买 nike

我正在尝试插入用户正在输入的 SO-NUMBER 的当前时间和日期。我在 IF..ELSE 循环中遇到问题,
如果我也选择“qccheck”选项,它只会更新数据库中的一列,即“samprecived”列。
下面分别是 html 和 php 的脚本。

<form id="form1" name="form1" method="post" action="insert.php" >
<p>
<lable>ENTER SO NUMBER</lable>
<input type="text" name="soid" id="soid" maxlength="6" required>
<p>
<lable>SELECT DEPARTMENT</lable>
<select type="text" name="dept" id="dept">

<option value="NGS Analysis">NGS Analysis</option>
<option value="E-Array">E-Array</option>
<option value="Micro-Array">Micro-Array</option>
<option value="NGS Data">NGS Data</option>
</select>
</p>
<p>
<lable>SELECT STATUS</lable>
<select name="options">
<option value="Sample Recived" name="samplerecived">Sample Recived</option>
<option value="QC Check" name="qccheck">QC Check</option>

</select>
</p>
<p><button><img src="http://brandonmadeawebsite.com/images/art/icons/insert_icon.png" height="50" />INSERT</button></p>
</form>

插入.php

<?php
$so = $_POST['soid'];
$dp = $_POST['dept'];
$selected = $_POST['samplerecived'];
$selected1 = $_POST['qccheck'];

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "status";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $conn->connect_error);
exit();
}

if($selected = 1){
$result = mysqli_query($conn,"INSERT INTO $dbname.statusinfo (soid, dept, samplerecived) VALUES ('$so','$dp',NOW())")or die(mysqli_error($conn));

}

else{
$result = mysqli_query($conn,"INSERT INTO $dbname.statusinfo (soid, dept, qccheck) VALUES ('$so','$dp',NOW())")or die(mysqli_error($conn));

}
echo "Inserted sucessfully with So Number <u><b>$so</b></u> Corresponding Status is <u><b>$st</b></u>";
$conn->close();
?>

我得到的输出是
如果用户还选择“qccheck”,则只有“samprecived”列会更新当前时间戳。
现在我需要的是,如果用户在网页中选择“qccheck”选项而不是在数据库中,则只有“qccheck”列应该更新为当前时间戳。
如果用户在网页中选择“samprecived”选项而不是在数据库中,则只有“samprecived”列应该更新为当前时间戳。

请纠正脚本中的问题,在此先感谢大家。

最佳答案

你的 php 脚本应该是这样的

<?php
$so = $_POST['soid'];
$dp = $_POST['dept'];
$selected = $_POST['options'];

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "status";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $conn->connect_error);
exit();
}

if($selected == 'Sample Recived'){
$result = mysqli_query($conn,"INSERT INTO $dbname.statusinfo (soid, dept, samplerecived) VALUES ('$so','$dp',NOW())")or die(mysqli_error($conn));

}

else{
$result = mysqli_query($conn,"INSERT INTO $dbname.statusinfo (soid, dept, qccheck) VALUES ('$so','$dp',NOW())")or die(mysqli_error($conn));

}
echo "Inserted sucessfully with So Number <u><b>$so</b></u> Corresponding Status is <u><b>$st</b></u>";
$conn->close();
?>

关于php - 如何在php中使用时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31453731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com