I'm trying to make a PHP self submitting form which inserts row into a MySQL table. Here is the code
<?php
if(isset($_POST['submit']))
{
$con = mysql_connect("localhost","calendar","calendar");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ecalendar", $con);
$start = $_POST['start'];
$end = $_POST['end'];
$title = $start.'-'.$end;
$sql="INSERT INTO events (title, description, evdate) VALUES ('$title','$_POST[description]','$_POST[evdate]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
}
?>
<html>
<head>
<title>Form Input Data</title>
<link rel="stylesheet" href="/jquery/jquery-ui.css" />
<script src="/jquery/jquery-1.8.3.js"></script>
<script src="/jquery/jquery-ui.js"></script>
<script src="/jquery/jquery.ui.timepicker.js"></script>
<script>
$(function () {
$("#evdate").datepicker();
});
$(function () {
$("#start").timepicker();
});
$(function () {
$("#end").timepicker();
});
</script>
</head>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p>Interval Orar</p>
<input type="text" id="start" name="start" />
<input type="text" id="end" name="end" />
<p>Data
<br />
<input type="text" id="evdate" name="evdate" />
</p>
<p>Eveniment
<br />
<textarea name='description'></textarea>
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>
I can fill in the form, click on the button, but nothing happens. Not even an error. Any ideas?
Change the following like
<input type="submit" value="Submit">
to
<input type="submit" value="Submit" name="submit">
you are inserting only if submit named data is there
ie
if(isset($_POST['submit']))
您不能在提交表单输入上没有名称的情况下使用 $_POST['submit'] ,因此请使用输入来检查表单是否已设置。
if(isset($_POST['start']) && isset($_POST['end']) && isset($_POST['evdate']) && isset($_POST['description']))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.