View Full Version : inserting problem

04-08-2004, 03:48 PM
Hi, I have a form which will allow users to add data to the database.
For testing purposes I have changed the SQL query so it posts static information to test it is inserting into the database.
The sql query works fine in postgres, but when i run it on the php page, it doesn't insert into the table.

the query is this:

$sql = ("INSERT INTO advert2 (username, mod_book_id, asking_price, condition, description, date_added)
VALUES ('isxlm', '2231', '45', 'Good', 'second time now', 'now');");
$result = pg_exec($sql);

Can anyone see why this isn't working??? Here is the entire page:

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="1">
<td width="20%"><?php include("menu.php"); ?></td>
<td width="80%">

echo "Thank you! Information entered.\n";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"1; URL=addDataToDatabase.php\">";
$test = "$askingPrice$position$textfield";
if($test != "")
$sql = ("INSERT INTO advert2 (username, mod_book_id, asking_price, condition, description, date_added) VALUES ('isxlm', '2231', '45', 'Good', 'second time now', 'now');");
$result = pg_exec($sql);
echo "<br>Error you have not completed the form";


$title = $_GET['title'];
$author = $_GET['auth'];
$publisher = $_GET['pub'];
$pubYear = $_GET['pubYear'];
$id = $_GET['id'];

echo "<h1>Please enter further details for your advert</h1>";

echo "<hr>";
echo "<b>Book Details</b><br><br>";
echo "<b>Title</b> : $title<br>";
echo "<b>Author</b> : $author<br>";
echo "<b>Publisher</b> : $publisher<br>";
echo "<b>Year</b> : $pubYear<Br>";


<form method="post" action="<? echo $PHP_SELF?>">
Asking Price:<INPUT TYPE="text" NAME="askingPrice" SIZE="30"><br><br>
Condition of book:
<select name="condition">
<option value="Like new">Like New
<option value="Good">Good
<option value="Fair">Fair
<option value="Worn">Worn
<option value="Worn">Excellent

Additional Comments:<br><textarea name="textfield" cols="50" rows="5"></textarea> <br><br>

<input type="Submit" name="submit" value="Enter information"></form>


04-08-2004, 04:06 PM
Take the first semi-colon off


04-08-2004, 04:12 PM
I took the first semi-colon off

but it hasn't made a difference, it's still not posting to the database.

any ideas?

04-08-2004, 04:16 PM
Try taking the variable off the query
$result =

Apart from that I can't see anything obvious, is there a function to show an error with that database? I only know mysql's, mysql_error()

04-08-2004, 04:45 PM
for more info
<?echo pg_result_error($result);?>

I suspect it will have something to do with the quoting of integer values & I doubt that the 'now' command will work when quoted ?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum