View Single Post
  #1 (permalink)  
Old 09-28-06, 06:54 AM
Tjobbe Tjobbe is offline
Newbie Coder
 
Join Date: Sep 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Inserting data to mysql table using php

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
-- 
-- 
Hostlocalhost
-- Generation TimeSep 282006 at 11:53 AM
-- Server version5.0.24
-- PHP Version5.1.4
-- 
-- 
Database: `testing`
-- 

-- --------------------------------------------------------

-- 
-- 
Table structure for table `entries`
-- 

CREATE TABLE `entries` (
  `
idint(4NOT NULL auto_increment,
  `
titletext NOT NULL,
  `
contenttext NOT NULL,
  `
datedatetime 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'); 
Reply With Quote