Hi,
I'm struggling to get an update working.
I have page one which has a table containing a hyperlink that passes information over to page 2.
On page 2 when i change the information and then click submit, instead of inserting the updated data into the database it just refreshes and doesn't insert into db.
Has anyone got any ideas why??
Thanks!
Lou
On page 1 I have the following code:
<?php
include("connectBookdb.php");
$query = pg_query("select ts_module_books.book_title, ts_module_books.author,
ts_module_books.publisher, ts_module_books.pub_year, advert.asking_price, advert.condition, advert.description, advert.username, advert.date_added, advert.advert_id FROM
ts_module_books INNER JOIN advert on ts_module_books.id=advert.mod_book_id
WHERE advert.username = '{$_SERVER['PHP_AUTH_USER']}';
");
$row = 0;
$numrows = pg_numrows($query);
if ($numrows == 0 )
{
echo ("You have no adverts. <br>Please <a href=\"http://wwwdev.comp.leeds.ac.uk/ctxlm/addAdvert.php\">Click here if you wish to add an advert.</a>");
}
else
{
echo ("<font size='4'>This page shows the books you currently have for sale.</font><br><br>");
echo ("<table border=1 width='100%' cellpadding=6>");
echo ("<tr bgcolor='#003300'><td width='40%'><b><font color='#ffffff'>Book Title</font></b></td>
<td width='30%'><b><font color='#ffffff'>Author</font></b></td>
<td width='10%'><b><font color='#ffffff'>Price</font></b></td>
<td width='20%'><font color='#ffffff'><b></b></font></td>
<td width='20%'><font color='#ffffff'><b></b></font></td></tr>");
while ($row < $numrows)
{
$data = pg_fetch_row ($query, $row);
printf ("
<tr><td>%s</td>
<td>%s</td>
<td>£%s</td>
<td>
<a href=\"editAdvert.php?title=
{$data[0]}&auth={$data[1]}&pub={$data[2]}
&pubYear={$data[3]}&askprice={$data[4]}
&condition={$data[5]}&description={$data[6]}
&username={$data[7]}&date={$data[8]}\">EDIT
</a>
</td>
<td>
<a href=\"delete.php?id={$data[9]}\">DELETE</a>
</td>
</tr>", $data[0], $data[1], $data[4]);
$row++;
}
}
printf ("</table>");
pg_close();
?>
The hyperlink for EDIT when clicked on goes to this page, which outputs information about the advert, and allows the user to edit the condition, price and description
<?php
include("connectBookdb.php");
if($_POST['submit'])
{
$sql = "UPDATE advert SET asking_price='$askprice',
condition='$condition', description='$description' WHERE advert_id=$id";
$result = mysql_query($sql);
$result = pg_exec("$sql");
echo "Thank you! Information updated.\n";
}
else
{
$id = $_GET['id'];
$title = $_GET['title'];
$author = $_GET['auth'];
$publisher = $_GET['pub'];
$pubYear = $_GET['pubYear'];
$askprice = $_GET['askprice'];
$date = $_GET['date'];
$condition = $_GET['condition'];
$description = $_GET['description'];
$username = $_GET['username'];
?>
<div align="center">
<font size=6>Edit Advert</font><br><br><br>
<b>Title</b>: <?php echo $title ?><br>
<b>Author: </b> <?php echo $author ?><br>
<b>Publisher: </b> <?php echo $publisher ?><br>
<b>Publication Year: </b> <?php echo $pubYear ?><br>
<form method="post"action="<?php echo $PHP_SELF?>">
Asking Price:<input type="Text"name="price" value="<?php echo $askprice ?>"<br><br>
Condition:<input type="Text" name="condition" value="<?php echo $condition ?>"><br>
Condition:<input type="text" name="description" value=<?php echo $description ?>"><br><br>
<input type="Submit" name="update" value="Update information"></form>
</div>
<?
}
?>
Page one contains the following informationg: