0

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?

2 Answers 2

3

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']))
Sign up to request clarification or add additional context in comments.

Comments

0

You cant use $_POST['submit'] without having a name on the submit form input, so use the inputs to check if the form is set.

            if(isset($_POST['start']) && isset($_POST['end']) && isset($_POST['evdate']) && isset($_POST['description']))

1 Comment

Also, in your query, you need to add quotes to your superglobals, $_POST[\'desription\']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.