hi there! im having a problem with making an order form. i want to display the products from a database and beside the product names, the customer could enter the quantity he wants to order. when the submit button is clicked, there comes the error.

im a newbie in php so i dont know how to resolve the errors. can anyone please help me?? thanks in advance!

here is the code:

<?php

$quantity = $_POST['quantity'];
$prod_desc = $_POST['prod_desc'];

if (!isset($_POST['submit'])) {

  global $database;
 
  $sql = 'SELECT * FROM #__products';
  $db = $database;
  $db->setQuery( $sql );
  $rows = $db->loadObjectList();
  
  '<form action="<?php echo $PHP_SELF;?>" method="post">' ;
  
 	echo '<table>
  <col width="65" />
  <col width="300" />
  <col width="49" />
  <col width="46" />';
  	 
	echo '<tr><td align="center">'."Product ID".'</td><td align="center">' ."Product Description". '</td><td align="center">' ."Price". '</td><td align="center">'."Quantity".'</td></tr>';
	
  	foreach ( $rows as $row ) {
    	echo '<tr><td align="center">'. $row->prod_id .'</td><td>' . $row->prod_desc . '</td><td align="right">' . $row->prod_price . '</td><td><input name="quantity" type="text" size="5"></td></tr>';
	} 
	
	echo '<tr><td align="center">'.''.'</td><td align="center">' .''. '</td><td align="center">' .''. '</td><td align="center">'.'<input type="submit" name="submit" value="submit" />'.'</td></tr>';
    
	echo '</table>';
	
	'</form>';

}else{
	
	echo "You ordered ". $quantity . " " . $prod_desc . ".<br />";

	echo "Thank you!";
}

?>

What is the error messgae you are getting?

Why are you putting global in the if statement. That doesn't need to be there.

You are also trying to get $_POST variables without them being set since the form hasn't been submitted. This will throw a warning of undefined index.

This code:

'<form action="<?php echo $PHP_SELF;?>" method="post">' ;

and

'</form>';

don't have "echo" on it. You are trying to use $PHP_SELF which will only work if you have register_globals on. You also don't need the opening and closing php tags inside that echo.

Why are you putting global in the if statement. That doesn't need to be there.

You are also trying to get $_POST variables without them being set since the form hasn't been submitted. This will throw a warning of undefined index.

This code:

'<form action="<?php echo $PHP_SELF;?>" method="post">' ;

and

'</form>';

don't have "echo" on it. You are trying to use $PHP_SELF which will only work if you have register_globals on. You also don't need the opening and closing php tags inside that echo.

Thanks! But what should i put inside the action=" "? all i want to happen is after the customer clicked the submit button, the page will display the products he ordered with their quantities. then they will be saved to the database.

example: You ordered 5 cakes and 10 chocolates.
(then these will be inserted into order_table in the database.)

Thanks for your patience!

you can also give the page name in you action where you want to move your action e.g

<form action="proceed_order.php" method="post">
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.