Ver Mensaje Individual
  #28 (permalink)  
Antiguo 22/01/2013, 15:26
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Consulta de Campos en tablas.

Cita:
Iniciado por GatorV Ver Mensaje
Pues con ese código solamente estas haciendo un echo del INSERT, tienes que realizar el insert usando mysql_query, no solamente imprimirlo en pantalla...
Perdona, asi tampoco me funciona:
Código PHP:
Ver original
  1. <?php require_once('Connections/conexion.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38. $id_aviso=$_POST['id_aviso'];
  39. $localidad = $_POST['localidad'];
  40. $provincia= $_POST['provincia'];
  41. $calle = $_POST['calle'];
  42. $numero = $_POST['numero'];
  43. $edificio= $_POST['edificio'];
  44. $puerta = $_POST['puerta'];
  45. $piso = $_POST['piso'];
  46. $letra= $_POST['letra'];
  47. $email = $_POST['email'];
  48. $NUM_DIR = $_POST['NUM_DIR'];
  49. $total = count($localidad);
  50. for ($i = 0; $i < $total; $i++) {
  51.         $local = $localidad[$i];
  52.         $prov = $provincia[$i];
  53.         $call = $calle[$i];
  54.         $nume = $numero[$i];
  55.         $edif = $edificio[$i];
  56.         $puer = $puerta[$i];
  57.         $pis = $piso[$i];
  58.         $letr = $letra[$i];
  59.         $emai = $email[$i];
  60.  
  61.    $insertSQL = sprintf("INSERT INTO dir_usuarios (local,prov,call,nume,edif,puer,pis,letr,emai,id_aviso,NUM_DIR)VALUES (%s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s)",
  62.                        GetSQLValueString($_POST['local'], "text"),
  63.                        GetSQLValueString($_POST['prov'], "text"),
  64.                        GetSQLValueString($_POST['call'], "text"),
  65.                        GetSQLValueString($_POST['nume'], "text"),
  66.                        GetSQLValueString($_POST['edif'], "text"),
  67.                        GetSQLValueString($_POST['puer'], "text"),
  68.                        GetSQLValueString($_POST['pis'], "text"),
  69.                        GetSQLValueString($_POST['letr'], "text"),
  70.                        GetSQLValueString($_POST['emai'], "text"),
  71.                        GetSQLValueString($_POST['id_aviso'], "int"),
  72.                        GetSQLValueString($_POST['NUM_DIR'], "text"));
  73.  
  74. mysql_select_db($database_conexion, $conexion);
  75. $usuarios = mysql_query($insertSQL, $conexion) or die(mysql_error());
  76. }
  77. mysql_select_db($database_conexion, $conexion);
  78. $query_usuarios = "SELECT *
  79. FROM usuarios WHERE id_aviso='$id_aviso'";
  80. $usuarios = mysql_query($query_usuarios, $conexion) or die(mysql_error());
  81. $row_usuarios = mysql_fetch_assoc($usuarios);
  82. $totalRows_usuarios = mysql_num_rows($usuarios);
  83.  
  84.  
  85. mysql_select_db($database_conexion, $conexion);
  86. $query_Recordset2 = "SELECT * FROM dir_usuarios where id_aviso='$id_aviso' AND NUM_DIR='1'";
  87. $Recordset2 = mysql_query($query_Recordset2, $conexion) or die(mysql_error());
  88. $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  89. $totalRows_Recordset2 = mysql_num_rows($Recordset2);
  90.  
  91.  
  92. ?>

Me da error:
Código HTML:
Ver original
  1. 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 'call,nume,edif,puer,pis,letr,emai,id_aviso,NUM_DIR)VALUES (NULL, NULL, NULL, NUL' at line 1

Última edición por satjaen; 22/01/2013 a las 15:34