hello to *..
I am new in php can you please help me here!
cant insert my data into my database.

<?php
error_reporting (E_ALL ^ E_NOTICE); 
$add = $_POST['add']; //Add button
$date = $_POST['date'];
$project = $_POST['project'];
$task = $_POST['task'];
$originated = $_POST['originated'];
$incharge = $_POST['incharge'];
$deadline = $_POST['deadline'];
$status = $_POST['status'];
$comment = $_POST['comment'];
$fin = $_POST['fin'];

if ($add)
{
	
	if(is_array($incharge))
		{
		foreach($incharge as $val2)
			{
				$con = mysql_connect ("localhost","root","");
				if (!$con)
				{
					die ('Not connected to DB' . mysql_error());
				}
				
				mysql_select_db ("profound_master", $con);
				$sql = "INSERT INTO bulletin  VALUES ('','$date','$project','$task','$originated','$val2','$deadline','$status','$comment','$fin')"; 
				
				if (!mysql_query ($sql, $con));
				{
					die ('Error Sir' . mysql_error()); //I am stock here.
					
				}
				echo "1 record added";
				
				mysql_close($con);			
			}
		}
}
?>

Thanks in advance.

I got it sir!
But now when i click the add button this are always comes out "Error Sir" which is this one die ('Error Sir' . mysql_error());

but when i tried to look for my database everything what i inserted was there. Can you please help me to fix my problem?

Thank you so much. This forum is very helpful.

God bless.

<?php
error_reporting (E_ALL ^ E_NOTICE); 
$add = $_POST['add']; //Add button
$date = $_POST['date'];
$project = $_POST['project'];
$task = $_POST['task'];
$originated = $_POST['originated'];
$incharge = $_POST['incharge'];
$deadline = $_POST['deadline'];
$status = $_POST['status'];
$comment = $_POST['comment'];
$fin = $_POST['fin'];
//If add button click
if ($add)
{
	//This is for checkbox group
	if(is_array($incharge))
		{
		foreach($incharge as $val2)
			{
				$tstring = implode(', ' , $incharge);
				
				//Database Connection
				$con = mysql_connect ("localhost","root","");
				if (!$con)
				{
					die ('Not connected to DB' . mysql_error());
				}
				//Selecting Database
				mysql_select_db ("profound_master", $con);
				//Adding of data to te Database
				$sql = "INSERT INTO bulletin VALUES ('','$date','$project','$task','$originated','$tstring','$deadline','$status','$comment','$fin')"; 
				
				
				if (!mysql_query ($sql, $con));
				{
					die ('Error Sir' . mysql_error()); //I always stop here.
					
				}
				echo "1 record added";
				
				mysql_close($con);			
			}
		}
}
?>

The problem is foreach operation db is connected to and closed, so i change the code to this;

<?
error_reporting (E_ALL ^ E_NOTICE); 
$add = $_POST['add']; //Add button
$date = $_POST['date'];
$project = $_POST['project'];
$task = $_POST['task'];
$originated = $_POST['originated'];
$incharge = $_POST['incharge'];
$deadline = $_POST['deadline'];
$status = $_POST['status'];
$comment = $_POST['comment'];
$fin = $_POST['fin'];

//Database Connection
$con = mysql_connect ("localhost","root","") or die ('Not connected to DB' . mysql_error());	//to avoid uneccessary connection for each operation
mysql_select_db ("profound_master", $con);	//Selecting Database

//If add button click
if ($add)
{
	//This is for checkbox group
	if(is_array($incharge))
		{
		foreach($incharge as $val2)
			{
				$tstring = implode(', ' , $incharge);
				
				
				//Adding of data to te Database
				$sql = "INSERT INTO bulletin VALUES ('','$date','$project','$task','$originated','$tstring','$deadline','$status','$comment','$fin')"; 
				
				
	mysql_query ($sql, $con)) or die ('Error Sir' . mysql_error()); //I always stop here.
					
				echo "1 record added";
							
			}
		}
}

mysql_close($con);	//to avoid colsing db foreach operation
?>

Note how your error massage if blocks were condensed to;

$con = mysql_connect ("localhost","root","") or die ('Not connected to DB' . mysql_error());

and

mysql_query ($sql, $con)) or die ('Error Sir' . mysql_error());

respectively.

commented: useful +5

Try what faroukmuhammad suggested. and Remove the semicolon; from your line 35.

commented: This is the actual issue, well spotted +13

The problem is foreach operation db is connected to and closed...

Can you explain why you think this would be the issue ? The code, however inefficient, is still correct. (The semi-colon as mentioned by Karthik_pranas is the real issue.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.