Jump to content

encountering issue when submitting form


hance2105
Go to solution Solved by 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
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.

Link to comment
Share on other sites

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 by l0gic
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.