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
to
you are inserting only if submit named data is there
ie