Ir al contenido


Foto

registrar datos en mysql con php


  • Por favor identifícate para responder
8 respuestas en este tema

#1 Venezolano

Venezolano

    Member

  • Miembros
  • PipPip
  • 15 mensajes

Escrito 18 julio 2012 - 01:02

<?php
$con=mysql_connect("localhost","root","");
$bd="victoria2006";

?>


<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
 
  $insertSQL = sprintf("INSERT INTO persona (Nombre, Apellido1, Apellido2, Cedula, idsexo, Edad, Direccion, MenoresC, idTipoPersona, IdCondicionEspecial, IMensual, TMienbros, idVivienda) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                     
  GetSQLValueString($_POST['Nombre'], "text"),
                      GetSQLValueString($_POST['Apellido1'], "text"),
  GetSQLValueString($_POST['Apellido2'], "text"),
                      GetSQLValueString($_POST['Cedula'], "text"),
                      GetSQLValueString($_POST['Descripcion'], "text"),
  GetSQLValueString($_POST['Edad'], "text"),
                      GetSQLValueString($_POST['Direccion'], "text"),
                      GetSQLValueString($_POST['MenoresC'], "text"),
                      GetSQLValueString($_POST['Descripcion'], "text"),
                      GetSQLValueString($_POST['Descripcion'], "text"),
  GetSQLValueString($_POST['IMensual'], "text"),
  GetSQLValueString($_POST['TMienbros'], "text"),
  GetSQLValueString($_POST['Descripcion'], "text"));

  mysql_select_db($bd, $con);
  $Result1 = mysql_query($insertSQL, $bd) or die(mysql_error());
 
  $insertSQL="El usuario se registro satisfactoriamente";
 
}
mysql_select_db($bd, $con);
$query_rec_sexo = "SELECT * FROM sexo";
$rec_sexo = mysql_query($query_rec_sexo, $con) or die(mysql_error());
$row_rec_sexo = mysql_fetch_assoc($rec_sexo);
$totalRows_rec_sexo = mysql_num_rows($rec_sexo);

mysql_select_db($bd, $con);
$query_rec_tip = "SELECT * FROM tipopersona";
$rec_tip = mysql_query($query_rec_tip, $con) or die(mysql_error());
$row_rec_tip = mysql_fetch_assoc($rec_tip);
$totalRows_rec_tip = mysql_num_rows($rec_tip);

mysql_select_db($bd, $con);
$query_rec_coe = "SELECT * FROM condicionespecial";
$rec_coe = mysql_query($query_rec_coe, $con) or die(mysql_error());
$row_rec_coe = mysql_fetch_assoc($rec_coe);
$totalRows_rec_coe = mysql_num_rows($rec_coe);

mysql_select_db($bd, $con);
$query_rec_viv = "SELECT * FROM vivienda";
$rec_viv = mysql_query($query_rec_viv, $con) or die(mysql_error());
$row_rec_viv = mysql_fetch_assoc($rec_viv);
$totalRows_rec_viv = mysql_num_rows($rec_viv);

?>
  :  :|
  • 0

#2 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4.945 mensajes
  • LocationMéxico

Escrito 18 julio 2012 - 02:14

Creo que  no entendí tu pregunta....
  • 0

#3 Venezolano

Venezolano

    Member

  • Miembros
  • PipPip
  • 15 mensajes

Escrito 18 julio 2012 - 02:21

viste el codigo que esta arriba quiero saber por no guarda las datos en la base de datos
  • 0

#4 Venezolano

Venezolano

    Member

  • Miembros
  • PipPip
  • 15 mensajes

Escrito 18 julio 2012 - 02:23

lo tengo en este momento corriendo y no da error alguno pero cuando lleno los campos del form no guarda los registros en la base de datos
  • 0

#5 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4.945 mensajes
  • LocationMéxico

Escrito 18 julio 2012 - 02:57

ve colocando un echo "linea x";


para que valides hasta donde se ejecuta el código
  • 0

#6 Bish0p

Bish0p

    Advanced Member

  • Miembros
  • PipPipPip
  • 64 mensajes
  • LocationMéxico, DF

Escrito 18 julio 2012 - 03:11

HOla

en la  linea

mysql_query($insertSQL, $bd) or die(mysql_error());


estas poniendo como segundo parametro el nombre de tu base de datos en lugar de poner tu conexion


mysql_query($insertSQL, $con) or die(mysql_error());


Saludos
  • 0

#7 Delphius

Delphius

    Advanced Member

  • Administrador
  • 6.295 mensajes
  • LocationArgentina

Escrito 18 julio 2012 - 05:31

Venezolano no hacía falta crear una encuesta. Con abrir el tema o hilo, exponer tus dudas puntuales y el código basta para que los demás te vayan leyendo y asesorando.

Saludos,
  • 0

#8 Venezolano

Venezolano

    Member

  • Miembros
  • PipPip
  • 15 mensajes

Escrito 19 julio 2012 - 05:19

Bish0p hice lo que indicaste que podias estar mal pero no funciono de verdad estoy atorado con esto pero no se que mas hacer

  • 0

#9 Venezolano

Venezolano

    Member

  • Miembros
  • PipPip
  • 15 mensajes

Escrito 19 julio 2012 - 05:22

poliburro como colocaria ese echo linea por linea, este codigo tiene un echo pero tampoco lo muestra
  • 0




IP.Board spam blocked by CleanTalk.