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> </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>
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> </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>