简体   繁体   中英

Im trying to Insert a result field from a previous Select using SQL SERVER with PHP and is not working

$idcliente=$_POST['clientes'];

$query = "SELECT Nombre FROM [RMSG].[dbo].[Clientes_Corte]
    where IDCliente =$idcliente AND Status = 0"; 

$result = sqlsrv_query($estadocon, $query);

if($row = sqlsrv_fetch_array($result)){ 
  $insertar="INSERT into Registro_Corte
             (IDCliente,NombreCliente,Descripcion,Lote,Yarda,Fecha)
  values($idcliente,".$row['Nombre'].",'$descrip','$lote','$yarda','$fecha')";

  $recurso=sqlsrv_prepare($estadocon, $insertar)or die('Error');
    if(sqlsrv_execute($recurso)){
      print '<script language="JavaScript">'; 
      print 'alert("Registro Creado Exitosamente!!")'; 
      print '</script>';
    else{
      print '<script language="JavaScript">'; 
      print 'alert("Error al Guardar Registro!!")'; 
      print '</script>';
     }
} else { 
    echo "No se encontro el Nombre del Cliente"; 
}   

Because it is a string, your field 'Nombre' should be in inside single quotes, like this:

$insertar="INSERT into Registro_Corte
    (IDCliente,NombreCliente,Descripcion,Lote,Yarda,Fecha)
    values($idcliente,'".$row['Nombre']."','$descrip','$lote','$yarda','$fecha')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM