Jump to content

clicking on ok button that appears when submitting form should return the add product page


hance2105

Recommended Posts

i have a php page where i add products to my database table tbl_product on clicking on button add product a javascript pop up message is displayed with a message and an ok button...which code can be used so that when i click on the ok button it returns me the add_prod.php page to add another product

 

here is my addprod.php which is linked to the add_prod.php

 

<?php
 
if(isset($_POST['button'])){
 
include('db_connect.php');
 
$prod_name=$_POST['prod_name'];
$prod_brand=$_POST['prod_brand'];
$prod_desc=$_POST['prod_desc'];
$prod_price=$_POST['prod_price'];
$cat=$_POST['cat'];
$subcat=$_POST['subcat'];
$prod_w_c=$_POST['prod_w_c'];
$prod_photo=$_POST['prod_photo'];
 
$sql="INSERT INTO tbl_product(prod_name, prod_brand, prod_desc, prod_price, cat, subcat, prod_w_c, prod_photo) VALUES('$prod_name', '$prod_brand', '$prod_desc', '$prod_price', '$cat', '$subcat', '$prod_w_c', '$prod_photo')";
 
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
else 
{
}
?>
 
<script type="text/javascript">
    alert("Product successfully added...!!!");
    </script>
 
<?php
 
}
 
?>

You really don't make sense but I think I've got the gist of what you're asking. If you want responses to a problem you should really spend more time writing your post, use code tags for any code you include and not describe a bulk of the problem in the topic title.

 

The problem

You want to return a user to the "add product" page after they've just added a new product.

 

The process

  1. User is on the addprod.php page that displays a form with an action value of "add_prod.php" or similar.
  2. add_prod.php creates a new record in the database for the new product and redirects to the addprod.php after the process is complete.
  3. addprod.php displays a success/error message dependent on the outcome.

 

Is this correct?

 

Don't use JavaScript to display a success message. Instead, use a session to store a success message and display it on the next page. You can then use the header function to redirect, i.e. header("Location: ... ").

 

Furthermore, you need to sanitise your data as you are open to SQL injection at the minute. I strongly suggest you reconsider your file names as well as they're very confusing. A large system with this sort of file naming would confuse the crap out of me.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.