Hi, I've been staring at this for hours, and can't see where im going wrong, can someone just have a look and see if they can see what it is.
Basically, I have three pages, one of which is a form where the user enters the title of book they are searching for, this links to the 2nd page which returns all the books from the ts_module_book table which matches the search term the user entered on page 1.
The code for the second page is this
<html> <head> <title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
$_GET = $HTTP_GET_VARS;
$_POST = $HTTP_POST_VARS;
$vars = array_merge ( $_GET, $_POST );
$search = $vars[search];
?>
<body bgcolor="#ffffff" text="#000000">
<table width="100%" border="0" bgcolor="" height="435">
<tr>
<td align="left" bgcolor="#ffffcc" height="47">
<p align="center"><font color="#003300" size="3"><b>University Of Leeds</b></font><font color="#003300" size="2"><b><br>
School Of Computing</b></font><font color="#003300" size="3"></font></p>
</td>
<td height="47" valign="top" bgcolor="#ffffcc">
<div align="right"><font size="6" color="#003300"><b>Student BOOK EXCHANGE</b></font></div>
</td>
</tr>
<tr valign="top">
<td width="20%" height="339"> <br>
<?php include("menu.php"); ?>
<p> </p><p> </p></td>
<td width="100%" bgcolor="" height="339">
<p align="right">
<?php include("smallInclude.php"); ?>
</p>
<table width="98%" border="0" align="center" height="112">
<tr>
<td valign="top" height="315"><b><font size="2" color="#003300">The
following books have been returned for your search criteria "<?php echo $search; ?>"</font></b> <br><br>
<?php
include("connectBookdb.php");
$query = pg_query("select * from ts_module_books where book_title LIKE '%$search%' order by book_title ASC");
$row = 0;
$numrows = pg_numrows($query);
echo ("<table border=1 width='95%'>");
echo ("<tr><td width='40%'>Book Title</td><td width='30%'>Author</td><td width='15%'>Publisher</td><td width='10%'> </td></tr>");
if ($numrows == 0 )
{
printf ("no books");
}
else
{
while ($row < $numrows)
{
$data = pg_fetch_row ($query, $row);
print "<tr><td>{$data[4]}</td><td>{$data[3]}</td><td>{$data[5]}</td><td>
<a href=\"addDataToDatabase.php?title={$data[4]}&auth={$data[3]}&pub={$data[5]}&pubYear={$data[6]}&id={$data[0]}\">Sell Book</a>
</td></tr>";
$row++;
}
}
printf ("</table>");
pg_close();
?>
<br>
</td>
</tr>
<!--</table>-->
</td>
</tr>
<tr valign="top">
<td colspan="2" ><br><hr>
</td>
<table width="98%" border="0" align="center" height="112">
</table>
</tr>
</table>
</body>
</html>
On this second page with all the results output into a table, there is a hyperlink for each result which when clicked outputs on the next page - page 3, more information about that record.
<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 (mod_book_id, asking_price, condition, description) VALUES ('$id', '$askingPrice', '$condition', '$textfield')");
$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>
However, it won't insert into the database! When i enter the details in the form - price, condition and description. when i submit it, and then check my postgres database, nothing has been inserted into the table.
Any ideas? I know its probably really simple, but its driving me up the wall!!!!
Help!
ps - For reference, the two tables are:
ts_module_detail (id, module_code, author, book_title, publisher, pub_year)
advert2 (advert_id, username, mod_book_id, asking_price, condition, description, date_added)
module_book_id, is the foreign key relating to id in ts_module_detail.