We help IT Professionals succeed at work.
Get Started

Trouble inserting data in mysql  using php and ajax.

IvetteM
IvetteM asked
on
736 Views
Last Modified: 2008-02-14
I`ve created a form where i draw checkboxes of days and checkboxes of months. The idea is to asign those days lets say monday, tuesday, and friday for the months january, march, and december. I use a if condition to verify if monday has been checked and then another if to checked the months. But when i verify the database it only inserts the monday, tuesday and friday just for january and not for the other 2 months.

Here is part of my code, i've only attach the part where it receives the posts.  Any help is appreciated.

 
$corte=substr($_POST['idmed'] ,-4, strlen($_POST['idmed'] )-0);
	$fechareg = date("Y-m-d h:i:s");
	
		if($con->conectar()==true){
		
	if ($_POST['chkm']=="true"){
		
			if($_POST['chken']=="true"){//January
				$query_Insert= "INSERT INTO cit_distribucion (codigo,iddistribucionmed,idtipocon,idrangohoras,idempleado,primera,subsecuente,mes,yrs,dia,IdUsuarioReg,FechaHoraReg) VALUES ('0',concat('L','$corte'),'EXT','".$_POST['txtrgs']."','".$_POST['idmed']."','".$_POST['cantprim']."','".$_POST['cantsub']."',1,'".$_POST['txtyr']."',2,'0','$fechareg')";
				$query = @mysql_query($query_Insert) or die('La consulta falloó: ' . @mysql_error());
			}
			
			if($_POST['chkfb']=="true"){//February
				$query_Insert= "INSERT INTO cit_distribucion (codigo,iddistribucionmed,idtipocon,idrangohoras,idempleado,primera,subsecuente,mes,yrs,dia,IdUsuarioReg,FechaHoraReg) VALUES ('0',concat('L','$corte'),'EXT','".$_POST['txtrgs']."','".$_POST['idmed']."','".$_POST['cantprim']."','".$_POST['cantsub']."',2,'".$_POST['txtyr']."',2,'0','$fechareg')";
				$query = @mysql_query($query_Insert) or die('La consulta falloó: ' . @mysql_error());
			}
			if($_POST['chkmz']=="true"){//March
				$query_Insert= "INSERT INTO cit_distribucion (codigo,iddistribucionmed,idtipocon,idrangohoras,idempleado,primera,subsecuente,mes,yrs,dia,IdUsuarioReg,FechaHoraReg) VALUES ('0',concat('L','$corte'),'EXT','".$_POST['txtrgs']."','".$_POST['idmed']."','".$_POST['cantprim']."','".$_POST['cantsub']."',3,'".$_POST['txtyr']."',2,'0','$fechareg')";
				$query = @mysql_query($query_Insert) or die('La consulta falloó: ' . @mysql_error());
			}
	
	}//End of the if for Monday
				
if ($_POST['chkt']=="true"){//Ini for Tuesday
				
		if($_POST['chken']=="true"){//January
				$query_Insert= "INSERT INTO cit_distribucion (codigo,iddistribucionmed,idtipocon,idrangohoras,idempleado,primera,subsecuente,mes,yrs,dia,IdUsuarioReg,FechaHoraReg) VALUES ('0',concat('M','$corte'),'EXT','".$_POST['txtrgs']."','".$_POST['idmed']."','".$_POST['cantprim']."','".$_POST['cantsub']."',1,'".$_POST['txtyr']."',3,'0','$fechareg')";
				$query = @mysql_query($query_Insert) or die('La consulta falloó: ' . @mysql_error());
			}	
			if($_POST['chkfb']=="true"){//February
				$query_Insert= "INSERT INTO cit_distribucion (codigo,iddistribucionmed,idtipocon,idrangohoras,idempleado,primera,subsecuente,mes,yrs,dia,IdUsuarioReg,FechaHoraReg) VALUES ('0',concat('M','$corte'),'EXT','".$_POST['txtrgs']."','".$_POST['idmed']."','".$_POST['cantprim']."','".$_POST['cantsub']."',2,'".$_POST['txtyr']."',3,'0','$fechareg')";
				$query = @mysql_query($query_Insert) or die('La consulta falloó: ' . @mysql_error());
			}
			if($_POST['chkmz']=="true"){//March
				$query_Insert= "INSERT INTO cit_distribucion (codigo,iddistribucionmed,idtipocon,idrangohoras,idempleado,primera,subsecuente,mes,yrs,dia,IdUsuarioReg,FechaHoraReg) VALUES ('0',concat('M','$corte'),'EXT','".$_POST['txtrgs']."','".$_POST['idmed']."','".$_POST['cantprim']."','".$_POST['cantsub']."',3,'".$_POST['txtyr']."',3,'0','$fechareg')";
				$query = @mysql_query($query_Insert) or die('La consulta falloó: ' . @mysql_error());
			}
 
	}

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE