hance2105 Posted June 3, 2013 Share Posted June 3, 2013 i have a php form to add product to my database, on clicking on the submit button all details entered are sent to the database without any issue, but the alert message that product has been successfully added is not displayed and there are 2 fields that are not cleared when the form is submitted and displayed again. this is my code <?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 { echo "<script>alert('Product successfully added'</script>)"; echo "<script language=javascript>history.back(1);</script>"; echo "go back"; } } ?> Quote Link to comment Share on other sites More sharing options...
RonnieCosta50 Posted June 3, 2013 Share Posted June 3, 2013 Try taking the echos out of php mode. echo " ?> <script>alert('Product successfully added'</script>) <?php "; Quote Link to comment Share on other sites More sharing options...
RonnieCosta50 Posted June 3, 2013 Share Posted June 3, 2013 As for your 2 fields that don't clear when you submit form and the page reloads... I'm assuming your in the testing phase of your website and you probably do what I do when I test. Check that you didn't accidentally forget to delete the initial value of both of those textboxes. I always set initial values so that I don't have to keep filling in the form to make sure it is adding to the database. When you finished the adding to database code, it is likely that you forgot to delete the initial values. I don't see anything in your code that could do that by itself. Quote Link to comment Share on other sites More sharing options...
l0gic Posted June 3, 2013 Share Posted June 3, 2013 echo "alert('Product successfully added')";..or.. echo "alert('Product successfully added')";Bit of spot the difference, might not be your current problem though. Quote Link to comment Share on other sites More sharing options...
l0gic Posted June 3, 2013 Share Posted June 3, 2013 (edited) echo "alert('Product successfully added')";..or.. echo "alert('Product successfully added')";Bit of spot the difference, might not be your current problem though. Eh, it took script tags out.. echo "<script>alert('Product successfully added'</script>)"; echo "<script>alert('Product successfully added')</script>"; Edited June 3, 2013 by l0gic Quote Link to comment Share on other sites More sharing options...
hance2105 Posted June 3, 2013 Author Share Posted June 3, 2013 thnx l0gic..that solved the issue @ ronniecosta50 there are no initial values set for both fields...the fields keep the desc i entered and the category i selected previously when adding a product Quote Link to comment Share on other sites More sharing options...
Solution hance2105 Posted June 4, 2013 Author Solution Share Posted June 4, 2013 i was able to sort this one out..thnx for ur help..... 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.