Hi,am new in php and appreciate your help in this matter....tried to save the record below into mysql database but couldn't.The field are blank and the Targetid field is always 0.Below is the coding...Please advise...Tqvm

<form action="progress1.php" method="post">
<p> Quantitative Progress: <input type="text" name="Quanprogress1"></p>
 <p>Qualitative Progress: <input type="text" name="Qualprogress1"></p>
 <p>Comment to support Progress: <input type="text" name="Comment1"></p>
 <input type="text" id="Targetid" name="Targetid" value="" >
<input type="submit">
 // Check connection

 if (mysqli_connect_errno()) {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();

if (isset($_POST['submit'])) //&& ($_POST['submit'] == "Submit")){`

 // escape variables for security
$Quanprogress1 = mysqli_real_escape_string($con, $_POST['Quanprogress1']);
$Qualprogress1 = mysqli_real_escape_string($con, $_POST['Qualprogress1']);
$Comment1 = mysqli_real_escape_string($con, $_POST['Comment1']);

   $Targetid =0;

   if (isset($_POST['Targetid'])) {

   $Targetid = $_POST['Targetid'];

 $sql="INSERT INTO progress (Quanprogress1, Qualprogress1,Comment1,Targetid)  
 VALUES ('$Quanprogress1', '$Qualprogress1', '$Comment1', '$Targetid')";

if (!mysqli_query($con,$sql)) {

die('Error: ' . mysqli_error($con));


echo "1 record added";





Can you let us know what the error is you are getting when you run this? Do you have a form passing to your $_POST variables? If nothing is passing to the $_POST variables, there would be nothing to add to the database.

Hi Borzoi,

Thanks for your reply...fyi the Targetid field is passed from the generalsum form...there is no error message when i click submit button...but when i check the database there is no data saved while the Targetid field remains 0....Thanks a lot for your advise...

The script above should have at least more than 2 errors.

this alone will give an error

if (isset($_POST['submit'])) //&& ($_POST['submit'] == "Submit")){`

because this part has been commented out and it will break the if statement

//&& ($_POST['submit'] == "Submit")){`

if you uncomment the above, this will give you another error


the back quote will definitely give you an error.

and this

<input type="submit">

cannot be process, because it lacks the name attribute. It has to be something like this

<input type="submit" name="submit" value="Submit">

Not until you changed your form submit codes, you will not be able to use this

if (isset($_POST['submit'])){

    //do whatever


the ['submit'] part of the codes refers to the name attribute of the submit button.

One last thing, and I hope would be the last is the OR expression.

 || ($_POST['submit'] == "Submit"))

The script will only allow you to have this kind of expression if the form submit button has been defined like this.

 <input type="submit" name="submit" value="Submit">

Fix your code first then add this on progress1.php




    // var_dump($_POST);


the above should give you form data array submitted through POST.