Right, a simple one, but I can't for the life of me figure it out, I've looked at a few dozen tutorials and code snippets but for some reason the data I want to enter will not display as I want it to.
Basically, I have a file with two fields, title and content, on submitting the form it goes to insert.php which "should" add the data to the table, but it does not.
I'd like the id to increase each time an entry is added and for the date to be autosubmitted too, is this possible?
The files are below, if anyone could point out the obvious then I'd be most grateful!
Tjobbe
index.php
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<form action="insert.php" method="post">
Title: <input type="text" name="title" /><br />
Content: <input type="text" name="content" /><br />
<input type="submit" />
</form>
</BODY>
</HTML>
insert.php
PHP Code:
<?
include "dbconnect.php";
$title="$_POST['$title]";
$content="$_POST['$Scontent]";
$sqlquery = "INSERT INTO entries VALUES('$title','$content')";
$results = mysql_query($sqlquery);
print "<html><body><center>";
print "<p>You have just entered this record<p>";
print "title : $title<br>";
print "content : $content<br>";
print "</body></html>";
?>
dbconnect.php
PHP Code:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'inflight';
$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die('Error connecting to mysql');
$dbname = 'testing';
mysql_select_db($dbname);
?>
my table, the entries in there are what i added manually through phpmyadmin:
PHP Code:
-- phpMyAdmin SQL Dump
-- version 2.9.0-rc1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 28, 2006 at 11:53 AM
-- Server version: 5.0.24
-- PHP Version: 5.1.4
--
-- Database: `testing`
--
-- --------------------------------------------------------
--
-- Table structure for table `entries`
--
CREATE TABLE `entries` (
`id` int(4) NOT NULL auto_increment,
`title` text NOT NULL,
`content` text NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;
--
-- Dumping data for table `entries`
--
INSERT INTO `entries` (`id`, `title`, `content`, `date`) VALUES
(13, 'fg adfg ae rth a', 'arth arth aetrh erg aehtra ergehet aretgh erg arehgaehteha ret\r\n\r\n\r\n<b>dafg adf ga</b>ad fg adfg adfg ad\r\na afdgadfg<br />RG ASDFGASDGASDFG', '2006-09-28 11:22:51'),
(14, 'yjt steyhj astr ytyjketyuawrt wytyw', 'rty wnrty wretwyty bwrty bwrtywrtywtry', '2006-09-28 11:31:18');