Hi, I am creating php to get input from a logged in user using html form in cart
ID: 3638283 • Letter: H
Question
Hi,
I am creating php to get input from a logged in user using html form in cart.php. The input is price of product. When the user clicks a link or button, I want to update the price in SQL with its id number.
Following is the code I got so far. This doesn't work becuse 'amount' in form is undefined.
cart.php
<html><body><?phpsession_start();$page='member.php';include('connect.php');
if(isset($_GET['add'])){ $itspage=pg_query('select auction.title, auction.itemdescription, bid.amount from auction inner join bid on bid.id=auction.id where auction.id='.$_GET['add']); while($itspage_row=pg_fetch_assoc($itspage)){ echo '<p>'.$itspage_row['title'].'<br />'.$itspage_row['itemdescription'];?>
<form action="test.php">Current Bid: <?php echo $itspage_row['amount'];?>Your bid: <input type="text" name="amount"><?php echo '<p>'.'<a href="test.php?add='.$_GET['add'].'">Place bid</a><br />';?></form><?php }}
function products(){ $query=pg_query('select auction.id, bid.id, auction.title,auction.itemdescription,bid.amount from auction, bid where auction.id=bid.id;'); if(pg_num_rows($query)==0){ echo "There are no products to display!"; } else{ while($get_row=pg_fetch_assoc($query)){ echo '<p>'.$get_row['title'].'</a>'.'<br />'.$get_row['itemdescription'].'<br />'.number_format($get_row['amount'],2).' '.'<a href="cart.php?add='.$get_row['id'].'">Bid</a></p>'; } }}?></body></html>
test.php
<?phpsession_start();include('connect.php');$page='cart.php';
$amount=$_REQUEST['amount'];$query=pg_query('update bid set amount='.$amount.' where id='.$_GET['add']);?>
When I run it, it gave me 2 errors:
Notice: Undefined index: amount
Warning: pg_query(): Query failed: ERROR: syntax error at or near "where" LINE 1: update bid set amount= where id=2 ^
*id=2 because I chose a product its id is 2.
I don't know why requesting 'amount' from table doesn't work. I tried to put submit button instead of link, but it also didn't work with my knowledge.
Can you please give me some advice to this problem?
Thank you.
Explanation / Answer
There is syntax error after where in sql query. Give proper quotation after id. Rest all is ok
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.