根据用户输入

时间:2015-07-16 05:05:19

标签: php html mysql database

我想在用户从菜单中选择的相应列中插入所选的状态时间戳 简要说明
从数据库开始,我创建了像下面的snap这样的列 enter image description here 最初用户将插入sonumber和状态,现在我需要数据库来更新数据库中的当前时间和日期,剩余列初始化为零。
下一个用户将选择更新选项,此处用户将输入so-number以及新状态(来自下拉列表)。现在我需要数据库用当前时间更新新状态并存储在特定状态列中。

从插入页面开始保存为" insert.html"和" insert.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 type="text"  name="status" id="status">

<option value="Sample Recived">Sample Recived</option>
<option value="Mol Bio Extraction">Mol-Bio Extraction</option>
<option value="Extraction QC">Extraction QC</option>
<option value="Library Prep">Library Prep</option>
<option value="Library QC">Library QC</option>
<option value="Sequencing">Sequencing</option>
<option value="Data check">Data Check</option>
<option value="Re-Sequencing">RE-Sequencing</option>
<option value="QC Check">QC Check</option>
<option value="Analysis Started">Analysis Started</option>
<option value="Analysis Completed">Analysis Completed</option>
<option value="Report">Report</option>
<option value="Outbound">Outbound</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'];

$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();
}
$result = mysqli_query($conn, "INSERT INTO $dbname.statusinfo (soid, dept ) VALUES ( '$so','$dp')") 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();

?>  

现在在更新脚本下面,保存为&#34; update.html&#34;,&#34; update.php&#34;分别

<form action="update.php" method="post" name="form2">
<p>
<lable>ENTER SO NUMBER</lable>
<input type="text"  name="soid" id="soid" required>

<p>
<lable>SELECT STATUS</lable>
<select type="text"  name="status" id="status">

<option value="Sample Recived">Sample Recived</option>
<option value="Mol Bio Extraction">Mol-Bio Extraction</option>
<option value="Extraction QC">Extraction QC</option>
<option value="Library Prep">Library Prep</option>
<option value="Library QC">Library QC</option>
<option value="Sequencing">Sequencing</option>
<option value="Data check">Data Check</option>
<option value="Re-Sequencing">RE-Sequencing</option>
<option value="QC Check">QC Check</option>
<option value="Analysis Started">Analysis Started</option>
<option value="Analysis Completed">Analysis Completed</option>
<option value="Report">Report</option>
<option value="Outbound">Outbound</option>


</select>
</p>

<p><button><img src="http://icons.iconarchive.com/icons/icons8/windows-8/32/User-Interface-Available-Updates-icon.png"  height="50" /> UPDATE</button></p>
</form>

update.php

<?php
 $so = $_POST['soid'];
 $st = $_POST['samplerecived'];
 $st1 = $_POST['molbioextraction'];
$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();
}
   switch ($st):

case $st:$result = mysqli_query($conn, "UPDATE statusinfo SET `samplerecived`= CURTIME()  WHERE soid='$so' ") or die(mysqli_error($conn));
    break;
case $st1:$result1 = mysqli_query($conn, "UPDATE statusinfo SET  `molbioextraction`= CURTIME() WHERE soid='$so' ") or die(mysqli_error($conn));
    break;
echo "Updated sucessfully with So Number $so Current Status is set to $st ";

  $conn->close();

   ?>

请帮助我这样做,如果你们需要更多信息,请随时提出 提前致谢

1 个答案:

答案 0 :(得分:1)

如果我正确理解您的问题,您只需要插入用户选择的字段,而另一个字段要么为NULL或某个默认值。

您拥有设置为CURRENT_TIMESTAMP的所有字段的默认值。这就是为所有字段分配当前时间戳的默认值的原因。删除默认值,允许它们为NULL(或设置除CURRENT_TIMESTAMP以外的某个默认值),您的问题将得到解决。