Jump to content

encountering issue when submitting form


hance2105

Recommended Posts

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";
}
 
}
 
?>
Link to comment
https://forums.phpfreaks.com/topic/278704-encountering-issue-when-submitting-form/
Share on other sites

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.

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>";

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.