Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Connect to server and database
- $host = "localhost"; // Mysql hostname
- $username = "root"; // Mysql username
- $password = ""; // Mysql password
- $database = "events"; // Name of mysql database
- $table ="events";
- $dbc = mysqli_connect($host, $username, $password);
- mysqli_select_db($dbc, $database);
- if (!$dbc) {
- trigger_error ('Could not connect to MySQL: ' . mysqli_connect_error() );
- }
- if(isset($_POST['submit'])) //ask if the form has been submitted
- {
- $submit = $_POST['submit'];
- $title = $_POST['title'];
- $where = $_POST['where'];
- $date = $_POST['date'];
- $time = $_POST['time'];
- //define the variables used in the query to add the data to the database
- if (($submit) && ($title) && ($where) && ($date) && ($time)){
- $q = "INSERT INTO $table (title, where, date, time) VALUES ('$title', '$where', '$date', '$time')";
- $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
- echo "Posted!";
- //If everything ran well then run the INSERT INTO query and show 'Posted'.
- }
- } else { //if the form has not yet been submitted, show the form
- echo "<br />";
- echo "<form method='post' action='index.php'>";
- echo "<input type='text' name='title' value='Event Title' class='styledtextbox'>";
- echo "<input type='text' name='where' value='Where?' class='styledtextbox'>";
- echo "<input type='text' name='date' value='Date (dd/mm/yy)' class='styledtextbox'>";
- echo "<input type='text' name='time' value='Time' class='styledtextbox'>";
- echo '<p>Now press the Submit button to have your event immediately added to the Home Page!</p>';
- echo "<input type='submit' value='Add Event' name='submit'>";
- echo 'Thank you for adding your event!';
- echo "</form>";
- echo "</p>";
- // The error says:
- // Notice: Query: INSERT INTO events (title, where, date, time) VALUES ('Event Title', 'Where?', 'Date (dd/mm/yy)', 'Time')
- MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where, date, time) VALUES ('Event Title', 'Where?', 'Date (dd/mm/yy)', 'Time')' at line 1 in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 34
- //However then posts:
- // Posted!
- // Meaning it thinks it has added to data to the db, however it hasn't. :/
- }
- ?>
- <!--End Main Content for admin.php-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement