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
 
}
 
?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.