我正在尝试插入用户输入的SO-NUMBER的当前时间和日期。这里我在IF..ELSE循环中遇到问题,
如果我也选择“qccheck”选项,它只更新数据库中的一列,即“samplerecived”列
下面分别是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>
insert.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”,则只有“samplerecived”列用当前时间戳更新
现在我需要的是,如果用户在网页中选择“qccheck”选项而不是在数据库中,则“qccheck”列应该使用当前时间戳更新。
如果用户在网页中选择“samplerecived”选项而不是在数据库中,则“samplerecived”列应使用当前时间戳更新。
请在脚本中纠正问题,先谢谢你们。
答案 0 :(得分:1)
这是你的要求吗?
<?php
$option = $_POST['options'];
if($option == 'Sample Recived')
// Update timestamp of sample recieved
else
// Update timestamp of qccheck
答案 1 :(得分:1)
你的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();
?>