...

View Full Version : inserting problem



forgodsake8
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:



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

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


<?php
include("connectBookdb.php");
if($_POST['submit'])
{
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);
}
else
{
echo "<br>Error you have not completed the form";
}
}

else
{

$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
</select><br><br>

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

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



</td>
</tr>
</table>
</body>
</html>

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

'now');");

forgodsake8
04-08-2004, 04:12 PM
I took the first semi-colon off
'now')");

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

any ideas?
thanks.

Nightfire
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()

firepages
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