PHP - Ayuda con este codigo PHP+MySql

 
Vista:
sin imagen de perfil

Ayuda con este codigo PHP+MySql

Publicado por joel (1 intervención) el 10/11/2014 16:44:26
Lo que pasa es esto, quiero leer un documento de Excel (apenas voy empezando) Entonces mi codigo esta asi:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ingresaMaestros</title>
</head>
 
<body onLoad="Siguiente()">
 
<?
require("configuracion.php");
require("funciones.php");
 
include ('Classes/PHPExcel.php');
include ('Classes/PHPExcel/Reader/Excel2007.php');
 
 
$objPHPExcelReader = new PHPExcel_Reader_Excel2007();
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
 
$objPHPExcelReader = $objReader->load("CLAVE_MAESTRO_NOMBRE_APELLIDOS.xlsx");
$objPHPExcelReader->setActiveSheetIndex(0);
 
		$filasInfo=$filas=$objPHPExcelReader->getActiveSheet()->getHighestRow();
		$columnas=$highestColumn=$objPHPExcelReader->getActiveSheet()->getHighestColumn();
 
		$columnasLetras=letrasaNumeroExcel($columnas);
		$filas=$filas+1;
 
			for($i=1;$i<=$filasInfo;$i++){
 
					$claveMaestro = $objPHPExcelReader->getActiveSheet()->getCell("A".$i)->getValue();
					$nombreMaestro = $objPHPExcelReader->getActiveSheet()->getCell("B".$i)->getValue();
					$apellidoMaestro = $objPHPExcelReader->getActiveSheet()->getCell("C".$i)->getValue();
    				$status=1;
 				echo "<br/> claveMaestro=$claveMaestro NombreMaestro=$nombreMaestro  ApellidoMaestro=$apellidoMaestro";
 
 
 $sql_con= "SELECT  * from maestros  where claveMaestro='$claveMaestro', NombreMaestro='$nombreMaestro', ApellidoMaestro='$apellidoMaestro'";
			$res_con=mysql_query($sql_con,$con) or die ("$sql_con ".mysql_error());
			$objeto_con= mysql_fetch_object($res_con);
			$IDGrado=$objeto_con->IDGrado;
 
			//	echo "<br/> ClaveMateria= $claveMateria    Materia= $Materia   IDGrado=$IDGrado";
 
   $sql="insert into maestros (claveMaestro, nombreMaestro, apellidoMaestro, status) values ('$claveMaestro', '$nombreMaestro', '$apellidoMaestro', $status)";
   $res=mysql_query($sql,$con) or die ("ERROR EN EL INSERT ".mysql_error());
 
		}?>
 
</body>
</html>


PERO al momento de leerlo e insertarlo en mi base de datos me sale este error:


claveMaestro=13435 NombreMaestro=KARLA ApellidoMaestro=VERTIZ GPESELECT * from maestros where claveMaestro='4355', NombreMaestro='KARLA', ApellidoMaestro='VERTIZ YUIX' You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' NombreMaestro='KARLA', ApellidoMaestro='VERTIZ FELIX'' at line 1


Lo que pienso es que por los espacios en el excel me manda ese error pero no se jaja agradeceria bastante su ayuda! Gracias :D
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 12
Ha aumentado su posición en 15 puestos en PHP (en relación al último mes)
Gráfica de PHP

Ayuda con este codigo PHP+MySql

Publicado por Rafael (40 intervenciones) el 11/11/2014 15:52:03
La sentencia con la que tratas de leer esta mal escrita:

Pones:
1
SELECT * from maestros where claveMaestro='4355', NombreMaestro='KARLA', ApellidoMaestro='VERTIZ YUIX'

Lo cual es incorrecto debe ser algo como:
1
SELECT * from maestros where claveMaestro='4355' AND NombreMaestro='KARLA' AND ApellidoMaestro='VERTIZ YUIX'

Vaya que en el WHERE la estructura de los campos no se concatena con comas, si no con operadores ya sea AND u OR...

Ojo que no son los espacios en el Excel.

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar