Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting drop down value into MySQL table
    primarykey
    data
    text
    <p>I have a site, where people are supposed to be able to arrange meetings with users within the system. However I'm having some difficulties getting the start and endtime from my form to appear in my mysql database, where I'm using the timestamp format for saving the values. Could somebody help me figuring out where I'm going wrong?</p> <pre><code>&lt;?php $page_title = "Create event"; //Check if the form has been submitted if (isset($_POST['submitted'])) { $errors = array(); //Initialize an error array // Check for event name if (empty($_POST['event_name'])) { $errors[] = 'You have not given your event a name.'; } else { $en = trim($_POST['event_name']); } // Check for event location if (empty($_POST['location'])) { $errors[] = 'You have not determined where the meeting is taking place.'; } else { $l = trim($_POST['location']); } if (empty($_POST['starttime'])) { $errors[] = 'You have not determined when the meeting is starting.'; } else { $s = trim($_POST['starttime']); } if (empty($_POST['endtime'])) { $errors[] = 'You have not determined when the meeting is ending.'; } else { $e = trim($_POST['endtime']); } if (empty($errors)) { // If everything is ok // Create the event in the database // require_once ('../mysqli_connect.php'); // DB connect // Make the query $host="mysql.itu.dk"; $username="tklo"; $password="Cave57Waits49"; $db_name="project_cluster"; $tbl_name="events"; mysql_connect("$host", "$username", "$password") or die ("cannot connect"); mysql_select_db("$db_name") or die ("cannot select database"); $sql="INSERT INTO $tbl_name (event_name, location, starttime, endtime)VALUES('$en', '$l', '$s', '$e')"; $result=mysql_query($sql); if($result){ echo "Succesfull"; echo "&lt;BR&gt;"; echo "&lt;a href='newevent.php'&gt;Back to main page&lt;/a&gt;"; } else { echo "ERROR"; } mysql_close(); } else { echo '&lt;h2&gt;Error!&lt;/h2&gt; &lt;p class="error"&gt;The following error(s) occured:&lt;br /&gt;'; foreach ($errors as $msg) { // Print each error echo " - $msg&lt;br /&gt;\n"; } } } ?&gt; &lt;form action="newevent.php" method="post"&gt; &lt;p&gt;Name your event: &lt;input type="text" name="event_name" value="&lt;?php if(isset($_POST['event_name'])) echo $_POST['event_name']; ?&gt;" /&gt;&lt;/p&gt; &lt;p&gt;Where is your meeting taking place: &lt;input type="text" name="location" value="&lt;?php if(isset($_POST['location'])) echo $_POST['location']; ?&gt;" /&gt;&lt;/p&gt; &lt;p&gt;Beginning of the event &lt;input type="text" name="starttime" value="&lt;?php if(isset($_POST['starttime'])) echo $_POST['starttime']; ?&gt;" /&gt;&lt;/p&gt; &lt;p&gt;End of the event &lt;input type="text" name="endtime" value="&lt;?php if(isset($_POST['endtime'])) echo $_POST['endtime']; ?&gt;" /&gt;&lt;/p&gt; &lt;input type="submit" value="GO" /&gt; &lt;input type="hidden" name="submitted" value="TRUE" /&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload