Jump to content

Simple insert won't work


rawdata
Go to solution Solved by rawdata,

Recommended Posts

Can anyone see where I have erred? No errors of any kind.

Here's the form:

<form name="news" action="updateNews.php" method="post">
	<p>Click "Clear" Button to remove old events.</p>
	<input type="submit" id='delete' name="delete" value='Clear' /><br /><br /><br />
	<input type="text" name="dateof" /> Enter date of Event (abbreviate month)<br />
	<input type="text" name="event" /> Enter name of Event<br />
	<input type="text" name="title" /> Enter time of Event and misc. info.<br /><br />
	<input type="submit" name="add" value="Add Event" /><br /><br />
</form>


Here's my php:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

//Hook up
include('db.php');

//Delete old news

if(isset($_POST['delete'])){
	$query = "TRUNCATE TABLE `news` ";
	$result = mysqli_query($link,$query)
	or die('Error deleting table.');
}


if(isset($_POST['add'])){
//Get the goods
	$dateof = $_POST['dateof'];
	$event = $_POST['event'];
	$title = $_POST['title'];

	
//Insert the goods
	$query = "INSERT INTO news (dateof, event, title)
	VALUES('$dateof', '$event', '$title')";
	$result = mysqli_query($link, $query) or die('Update Failed' .mysqli_error($link));
}

db.php is just my connection file:

<?php
/*  Database Information - Required!!  */
/* -- Configure the Variables Below --*/
$dbhost = 'localhost';
$dbusername = '';
$database = '';
$dbpasswd = '';
/* Let's get connected*/
$link = mysqli_connect("$dbhost", "$dbusername", "$dbpasswd", "$database");

/* Now check that we're connected */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.