我有两个类型为"time"的输入(开始和结束时间)。使用PHP,我想将这些值插入到一个名为"allocatedate"的表中。这个表有两列——starttime和endtime。两者都属于时间类型。迄今为止编写的代码:HTML和PHP:
<input type="time" name="st1" /><br/><input type="time" name="et1"/>
<input type="submit" name="allot" class="gobutton" value="Allot Dates"/>
if(isset($_POST['allot']))
{
$c="$_POST[st1]";
$d="$_POST[et1]";
mysql_query("insert into allotdate values('$c','$d')");
if(mysql_affected_rows()>0)
{
echo "<script>alert('You have successfully alloted')</script>";
}
}
但这是行不通的。没有插入任何值,也没有弹出警报消息。有什么建议吗?
更改以下行:
$c="$_POST[st1]";
$d="$_POST[et1]";
至
$c=$_POST['st1'];
$d=$_POST['et1'];
您试图插入一个包含值$_POST[st1]
而不是实际发布值的字符串。
您需要一个表单和一个php标记,但我认为您已经有了,如果没有的话,您不是很聪明,但您可以使用sql日期函数来了解更多关于sql日期的信息
http://www.w3schools.com/sql/sql_dates.asp
尝试如下:
<form method="POST">
<input type="time" name="st1" /><br/><input type="time" name="et1"/>
<input type="submit" name="allot" class="gobutton" value="Allot Dates"/>
</form>
<?php
if(isset($_POST['allot']))
{
$c=$_POST['st1'];
$d=$_POST['et1'];
mysql_query("insert into allotdate values('$c','$d')");
if(mysql_affected_rows()>0)
{
echo "<script>alert('You have successfully alloted')</script>";
}
}