hance2105 Posted June 1, 2013 Share Posted June 1, 2013 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 } ?> Quote Link to comment Share on other sites More sharing options...
cpd Posted June 2, 2013 Share Posted June 2, 2013 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 User is on the addprod.php page that displays a form with an action value of "add_prod.php" or similar. 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. 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.