Hi, I'm working with php5 and sqlserver 2008 database mounted on a xampp server install the driver to work but I get the following error when I run:
//conBD
<?php
$server='x.x.x.x';
$bd='PruebaO';
$coninfo= array("Database"=>$bd,"UID"=>"admin","PWD"=>"1234567","CharacterSet"=>"UTF-8");
$con = sqlsrv_connect($server, $coninfo);
if($con){
echo "Conectado a: $bd";
echo "<br>";echo "<br>";
}else{
echo "$bd ",(print_r(sqlsrv_errors(),true));
echo "<br>";echo "<br>";
}
?>
//metodos-BD.php
<?php
include ("conBD.php");
$nombre = $_POST['nom'];
$rut = $_POST['rut'];
$fono = $_POST['fon'];
$correo=$_POST['em'];
$direcion=$_POST['dire'];
$cod=$_POST['cod'];
$comprobar= sqlsrv_query($con,"SELECT CodAux, NomAux, RutAux, DirAux, FonAux1, EMail FROM softland.cwtauxi WHERE(CodAux = '$cod')");
$fila=sqlsrv_num_rows($comprobar);
if($fila==0){
$insertarc=sqlsrv_query($con,"Insert Into softland.CWTAUXI ( CodAux,NomAux,NoFAux,RutAux,ActAux,GirAux,PaiAux,Region,CiuAux,Comaux,Provaux,DirAux,DirNum,DirDpto,CodPostal,FonAux1,FonAux2,FonAux3,CodAreaFon, AnexoFon,FaxAux1,FaxAux2, CodAreaFax,ClaCli,ClaPro,ClaEmp,ClaSoc,ClaDis,ClaOtr,Casilla,Email,WebSite,Bloqueado,BloqueadoPro,Notas,EsReceptorDTE,EMailDTE,CtaCliente,CtaCliMonExt,Usuario,Proceso, Sistema) VALUES ('$cod','$nombre', Null, '$rut', 'S', Null, Null, Null , Null, '$direcion', Null,'$fono', Null, Null, Null, NUll, 'Null', 'Null',0,0, 'Null', ' Null', 0, 'S','$correo', 'N', 'N', 'N', 'N', Null, 'N', Null, 'N', 'N', Null , 'N', Null , NULL, NULL, 'softland', 'Ficha Cliente ERP', 'IW')");
if($insertarc){
echo "El vendedor de registro exitosamente en la BD: $bd";
echo "<br>";
echo "<br>";
print_r ($_POST);
}else{
echo"Error en ejecución: \n";
echo "<br>";
die (print_r(sqlsrv_errors(),true));
echo "<br>";
echo "<br>";
echo "<br>";
}
}else{
echo "El Cliente ya exite en: $bd";
while($row=sqlsrv_fetch_array($comprobar)){
echo $row['Codigo']."<br>";
echo $row['Nombre']."<br>";
echo $row['Rut']."<br>";
echo $row['Telefono']."<br>";
echo $row['Email']."<br>";
echo $row['Direccion']."<br>";
}
}
?>
//INDEX
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Clientes nuevos</title>
<link rel="stylesheet" href="css/style.css">
<!--<script src="js/Validaciones.js" type="text/javascript" ></script> onsubmit="return ValidaCamp()"-->
</head>
<body>
<form name="form" method="post" action="lib/metodos-BD.php" >
<div class="logo"> <img src="imagenes/logo-oxford.png" width="90%" height="10%"> </div>
<h2>Ingresar clientes</h2>
<div class="input_style">
<input type="text" name="cod" placeholder="Codigo auxiliar" id="cod" >
<input type="text" name="nom" placeholder="Nombre" id="nom" >
<input type="text" name="rut" placeholder="Rut" id="rut" >
<input type="text" name="fon" placeholder="Telofono" id="fon">
<input type="text" name="em" placeholder="Email" id="em" >
<input type="text" name="dire" placeholder="Direccion" id="dire" >
<input type="submit" value="Guardar" id="btn_ingresar" name="btn_ingresar" class="btn" >
</div>
</form>
</body>
</html>
Conectado a: PruebaO
Error en ejecución:
Array ( [0] => Array ( [0] => 22001 [SQLSTATE] => 22001 [1] => 8152 [code] => 8152 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Los datos de cadena o binarios se truncarían. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Los datos de cadena o binarios se truncarían. ) [1] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 3621 [code] => 3621 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Se terminó la instrucción. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Se terminó la instrucción. ) )
I already checked the length and type of fields in the DB but I can not find the error. I hope you can help me.