query does not save records to the bd [closed]

-2

Well, what happens is that I'm making a form but I'm not saving the records in the database, I do not know what this table is for

<!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>Documento sin título</title>
</head>

<body>

<marquee bgcolor="#0000CC"> INGRESE SUS DATOS</marquee>
<form id="form1" name="form1" method="post" action="Datospersonales.php">
  <p>&nbsp;</p>
  <p><strong>DATOS PERSONALES </strong>  </p>
  <table width="353" border="0">
    <tr>
      <td>ID</td>
      <td><label for="id"></label>
      <input type="text" name="id" id="id" /></td>
    </tr>
    <tr>
      <td>NOMBRE</td>
      <td><label for="nombres"></label>
      <input type="text" name="nombres" id="nombres" /></td>
    </tr>
    <tr>
      <td>PATERNO</td>
      <td><label for="paterno"></label>
      <input type="text" name="paterno" id="paterno" /></td>
    </tr>
    <tr>
      <td>MATERNO</td>
      <td><label for="materno"></label>
      <input type="text" name="materno" id="materno" /></td>
    </tr>
    <tr>
      <td>ID CIIVIL</td>
      <td><label for="id_civil"></label>
      <input type="text" name="id_civil" id="id_civil" /></td>
    </tr>
    <tr>
      <td>DIRECCION</td>
      <td><label for="direccion"></label>
      <input type="text" name="direccion" id="direccion" /></td>
    </tr>
    <tr>
      <td>EMAIL PRINCIPAL</td>
      <td><label for="correop"></label>
      <input type="text" name="correop" id="correop" /></td>
    </tr>
    <tr>
      <td>EMAIL ALT.</td>
      <td><label for="correoa"></label>
      <input type="text" name="correoa" id="correoa" /></td>
    </tr>
    <tr>
      <td>CELULAR      </td>
      <td><label for="tcelular"></label>
      <input type="text" name="tcelular" id="tcelular" /></td>
    </tr>
    <tr>
      <td>TELEFONO CASA</td>
      <td><label for="tcasa"></label>
      <input type="text" name="tcasa" id="tcasa" /></td>
    </tr>
    <tr>
      <td>TELEFONO TRABAJO</td>
      <td><label for="ttrabajo"></label>
      <input type="text" name="ttrabajo" id="ttrabajo" /></td>
    </tr>
    <tr>
      <td>F.NACIMIENTO</td>
      <td><input type="date" name="f_nacimiento" id="f_nacimiento" /></td>
    </tr>
    <tr>
      <td>GENERO</td>
      <td><label for="genero"></label>
        <select name="genero" id="genero">
          <option value="1">Hombre</option>
          <option value="2">Mujer</option>
      </select></td>
    </tr>
    <tr>
      <td>PAIS </td>
      <td><select name="pais_nacimiento" id="pais_nacimiento">
        <option>Alemania</option>
        <option>Argentina</option>
        <option>Autralia</option>
        <option>Bahamas</option>
        <option>Belgica</option>
        <option>Belice</option>
        <option>Bolivia</option>
        <option>Brasil</option>
        <option>Camerun</option>
        <option>Canada</option>
        <option>Chile</option>
        <option>China</option>
        <option>Ciudad del vaticano</option>
        <option>Colombia</option>
        <option>Corea del norte</option>
        <option>Corea del sur</option>
        <option>Costa rica</option>
        <option>Croacia</option>
        <option>Cuba</option>
        <option>Dinamarca</option>
        <option>Ecuador</option>
        <option>Egipto</option>
        <option>El salvador</option>
        <option>Eslovaquia</option>
        <option>España</option>
        <option>Estados Unidos</option>
        <option>Filipinas</option>
        <option>Francia</option>
        <option>Grecia</option>
        <option>Guatemala</option>
        <option>Honduras</option>
        <option>India</option>
        <option>Irak</option>
        <option>Iran</option>
        <option>Irlanda</option>
        <option>Jamaica</option>
        <option>Madagascar</option>
        <option>Montenegro</option>
        <option>Mexico</option>
        <option>Nueva Zelanda</option>
        <option>Peru</option>
        <option>Uruguay</option>
      </select></td>
    </tr>
    <tr>
      <td>ESTADO</td>
      <td><select name="edo_nacimiento" id="edo_nacimiento">
        <option>Aguascalientes</option>
        <option>Baja California</option>
      </select></td>
    </tr>
    <tr>
      <td>NACIONALIDAD</td>
      <td><select name="nacionalidad" id="nacionalidad">
        <option>mexicano</option>
      </select></td>
    </tr>
    <tr>
      <td>IDENTIDAD</td>
      <td><select name="identidad" id="identidad">
        <option value="1">CURP</option>
        <option value="2">INE</option>
        <option value="3">IMSS</option>
        <option value="4">ISSSTE</option>
        <option value="5">ISSSTECALLI</option>
        <option value="6">CARTILLA</option>
      </select></td>
    </tr>
    <tr>
      <td>FOTO</td>
      <td><label for="foto"></label>
      <input type="text" name="foto" id="foto" /></td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p>
    <input type="submit" name="Enviar" id="Enviar" value="Enviar" />
  </p>
  <p>&nbsp;</p>
</form>

<body background="file:///C:/Users/Desktop/carpetas%20de%20cosas/desarrollo/conacyt2.png">


</body>
</html>

este seria el php con los post estan iguales a la base de datos todo los id 
<?php 
include("conexion4.php");   
  if($_POST){  
$id=$_POST['id'];
$nombres=$_POST['nombres'];
$paterno=$_POST['paterno'];
$materno=$_POST['materno'];
$id_civil=$_POST['id_civil'];
$direccion=$_POST['direccion'];
$correop=$_POST['correop'];
$correoa=$_POST['correoa'];
$tcelular=$_POST['tcelular'];
$tcasa=$_POST['tcasa'];
$ttrabajo=$_POST['ttrabajo'];
$f_nacimiento=$_POST['f_nacimiento'];
$genero=$_POST['genero'];
$pais_nacimiento=$_POST['pais_nacimiento'];
$edo_nacimiento=$_POST['edo_nacimiento'];
$nacionalidad=$_POST['nacionalidad'];
$identidad=$_POST['identidad'];
$foto=$_POST['foto'];

}

$query="insert into tb_personales(id,nombres,paterno,materno,id_civil,direccion,correop,correoa,tcelular,tcasa,ttrabajo,f_nacimiento,genero,pais_nacimiento,edo_nacimiento,nacionalidad,identidad,foto) values('$id','$nombres','$paterno','$materno','$id_civil','$direccion','$correop','$correoa','$tcelular','$tcasa','$ttrabajo','$f_nacimiento','$genero','$pais_nacimiento','$edo_nacimiento', '$nacionalidad','$identidad','$foto')";

mysqli_db_query("bd_conacyt",$query);

with this I connect to the bd

<?php

$con=mysqli_connect("localhost","root","") or die (mysqli_error());
$db=mysqli_connect("bd_conacyt",$con) or die (mysqli_error());   

/**
 * @author www.intercambiosvirtuales.org
 * @copyright 2016
 */


?>

I do not know what the problem is because the fields are the same made different types of queries and it does not save me. Greetings

    
asked by elbrujo200 29.11.2016 в 22:26
source

4 answers

1

Three things: 1.- Check your file of mysql_error.log, in the podras you can have more detail of the error. link

2.- Try to print some of the variables to ensure that if you are getting POST content, just to verify.

3.- Test your Query directly in your database manager, only with test data to see if everything is correct with your database engine.

    
answered by 29.11.2016 в 22:35
0

Create a variable called query and there you store your insert, then replace it like this:

 mysql_db_query("conacyt",$query);

It is better readable and it is also for you to do an echo of your query, copy it and execute that sql in your database administrator (commonly phpmyadmin), choosing your DB, then in the sql tab.

There you will know if it is your query that causes the error.

Another thing is this:

if(Enviar=="Enviar")

Where do you get Submit? Is it a constant? Or is it rather $ _POST ['Send']?

Also check your action on the form:

action="Datospersonales.php"

If you are pointing to the indicated place, it seems to be the same page.

Those two can be the causes.

Note: is a very obsolete code, from using tables to the mysql extension, maybe you consider renewing it because sooner or later it will stop working correctly.

    
answered by 29.11.2016 в 22:43
0

I think the error is in if(Enviar=="Enviar") the first send php assumes that it is an undefined constant, that send has to be a variable where you must assign the value of the summit button, use echo and die for you to do a simple debug and see where, you can use a debugger for php xdebug is an alternative.

    
answered by 29.11.2016 в 22:41
0

I see several failures in your code:

  • You try to compare Enviar in your if and yet you do not have that variable defined (which would also have to go with a $ in front). I imagine that what you want to do will be if($_POST["Enviar"] == "Enviar"){

  • In your connection you use a database called bd_conacyt and in your function mysql_db_query you use a call conacyt .

Finally, do not use PHP's mysql functions and use the functions of mysqli failing since with the former it has been shown that there are security flaws.

    
answered by 29.11.2016 в 22:43