Do not insert form in the Database

1

Good afternoon.

I am doing an inventory system with PHP AND SQL SERVER 2008, when making the connection it is successful but when inserting data and consulting them in the database I verify and it does not insert anything.

 $serverName = ("10.21.22.235"); //serverName\instanceName, portNumber (por defecto es 1433
    $connectionInfo = array("Database"=>"new", "UID"=>"sa", "PWD"=>"");
    $conexion = sqlsrv_connect($serverName, $connectionInfo);
    //include('conexion.php');




    if($conexion===false)
    {
        die(print_r (sqlsrv_errors(),true));

    }

    if ($_POST)

   {
      $id_area_mant=$_POST['id_area_mant'];
      $nombre=$_POST['nombre'];
      $ap=$_POST['ap'];
      $am=$_POST['am'];
      $contra=$_POST['contra'];


      $tsql= "INSERT into 'Area'(id_area_mant,nombre,ap,am,contra) 
      values ('$id_area_mant','$nombre','$ap','$am','$contra')";

   $recurso=sqlsrv_query($conexion,$tsql);

   if($recurso)
   {
   echo"Agregado correctamente";
   }
   else
   {
   echo"No Agregado";
   }

   }

?>
    
asked by Carlos 07.03.2017 в 19:14
source

4 answers

0

You have errors in the values:

('$id_area_mant','$nombre,'$ap',$am,$contra)

Try changing them to:

('$id_area_mant','$nombre','$ap','$am','$contra')
    
answered by 07.03.2017 в 19:19
0

I think the query you use to insert the data has errors in the syntax, you tried running the query that generates your script directly in sql, for example you flip a quote that closes when you pass the value contained in $ name

$tsql= "INSERT into 'Area'(id_area_mant,nombre,ap,am,contra) 
  values ('$id_area_mant','$nombre','$ap',$am,$contra)";
    
answered by 07.03.2017 в 19:19
0

Remove the quotes from the name of the table. Instead of:

$tsql= "INSERT into 'Area' (...

You must write:

$tsql= "INSERT into Area (...
    
answered by 07.03.2017 в 19:43
0

You should get the errors to know what is wrong. It is difficult to find it blindly.

if( $recurso === false ) {
if( ($errors = sqlsrv_errors() ) != null) {
    foreach( $errors as $error ) {
        echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
        echo "codigo: ".$error[ 'code']."<br />";
        echo "mensaje: ".$error[ 'message']."<br />";
    }
  }
}
    
answered by 07.03.2017 в 20:42