PostgreSQL insert problems (newbie)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Caliber
Forum Newbie
Posts: 5
Joined: Sat Feb 08, 2003 1:14 pm

PostgreSQL insert problems (newbie)

Post by Caliber »

Hi, I'm very new at PHP-programming, but I've done some ASP in my past.
My problem is very simple; I want to add new rows to the table using a form.

My table:

Code: Select all

CREATE TABLE mtrade_forum (
	threadtopic varchar(40),
	threadcontent text,
	userid integer,
	createddate timestamp,
	lastreplydate timestamp,
	lastreplyby varchar(30),
	replies integer,
	replythread varchar(10),
	sticky boolean default 'f',
	threadid SERIAL PRIMARY KEY,
	FOREIGN KEY(userid)
		REFERENCES mtrade_members
);

My insert page: (is run from a page with a form that includes values for $threadtopic2 and $threadcontent2)

Code: Select all

<?php session_start();
include ("locked.php"); ?>

<?php
	include "dbconnect.php";

	INSERT INTO mtrade_forum VALUES (
		'$threadtopic2',	//threadtopic - The topic-field in the form
		'$threadcontent2',	//threadcontent - The content-field in the form
		'$sessuserid',		//userid - Userid from the session
		'$now',				//createddate - The date and time
		'$now',				//lastreplydate - The date and time
		'$sessuserid',		//lasteplyby - Userid from the session
		'0',				//replies - The value 0 (zero)
		'0'					//replythread - The value 0 (zero)
	);

?>

But when I run the code, I get a problem pointing to line 7 ("INSERT INTO mtrade_forum VALUES (")
It's probably something really dumb, but I don't know what it is.. Hope that someone can help me.

Thanx in advance
// Caliber
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

INSERT is not a php statement, you must use a statment to pass your query to your database.. hopefully you have pg_connect() in your dbconnect.php, and you want to do the insert statement with pg_query()

pg_query('INSERT INTO mytable (col1,col2) VALUES (''somedata'',''someotherdata'')');

and you can not have // comments in a query, i do believe that psql supports /* comments */ if you really need them..
Post Reply