Error in bringing BD information to the date and putting it into an input

1

My question is directed to the following: I need to bring the date that I have in the records and modify it and save the new date, but when I want to bring the date it says it is false, try with a statement in sql but it marks me error in the statement sqlsrv_fecth_array, I put the code I hope and you can help me.

<?php
$serverName = 'localhost';  
$connectionInfo = array( "Database"=>"cccc", "UID"=>"gggg", "PWD"=>"vos");
/* Connect using Windows Authentication. */  
try  
{  
$conn = sqlsrv_connect($serverName, $connectionInfo);  
    //echo 'Conectado';
}  
catch(Exception $e)  
{   
die( print_r( $e->getMessage() ) );   
}  

    $fecha = ""; 
    $nombreQuejoso = ""; 
    $apellidoQuejoso = ""; 
    $servidorPublico = "";
    $tipoAutoridad = "";
    $nacionalidad= "";
    $ocupacion="";
    $domicilio="";
    $localidad="";
    $municipio="";
    $telefono="";
    $celular="";
    $observaciones="";
    $fechaNacimiento="";

$sql = "SELECT TOP 1 * FROM tExpedientes WHERE IdExpediente='" .$_GET['id']."' ORDER BY fecha DESC";
    $version = sqlsrv_query($conn, $sql);
    while ($row = sqlsrv_fetch_array($version)) {
        $nombreQuejoso = $row["QuejosoNombre"]; //
        $apellidoQuejoso = $row["QuejosoApellidos"]; //
        $servidorPublico = $row["ServidorPublico"]; //
        $tipoAutoridad = $row["TipoAutoridad"]; //
        $sql1 = "SELECT date_Format(Fecha,'%d.%m.%Y HH:ii:ss') as NewFecha FROM tExpedientes WHERE IdExpedientes=Fecha ORDER BY Fecha DESC"; //
        $fecha1 = sqlsrv_query($conn, $sql1);
        **$row = sqlsrv_fetch_array($fecha1);**
        $fecha = $row('NewFecha');
        var_dump($fecha);
    }

This is where I want to put it, maybe I'm wrong but I still do not know how to do it.

    <legend>Cambio de Fecha</legend>

    <input type="text" name="datepicker" id="datepicker" readonly="readonly" size="18" value="<?php echo ($fecha); ?>"><br>
    
asked by Cesar Ortega 31.03.2017 в 17:29
source

3 answers

0

Verify that the format in which you are trying to assign is as follows YYYY-MM-DD

Example:

<input type="date" name="fecha" value="2017-03-30">
    
answered by 31.03.2017 в 17:45
0

Greetings, you have a syntax error when using:

while ($row = sqlsrv_fetch_array($version)) {
}

since the one that is used by sqlsrv is different from the one of mysql for example, and it would be applied in this way:

while( $row = sqlsrv_fetch_array( $version, SQLSRV_FETCH_ASSOC) ) {
}

I leave the link to the php manual referring to sqlsrv: link

    
answered by 01.04.2017 в 14:47
0

I was able to find the answer, maybe it's not the best but it works for me I'll leave it as I resolved it.

$version = sqlsrv_query($conn, $sql);
while ($row = sqlsrv_fetch_array($version)) { 
    $nombreQuejoso = $row["QuejosoNombre"]; //
    $apellidoQuejoso = $row["QuejosoApellidos"]; //
    $servidorPublico = $row["ServidorPublico"]; //
    $tipoAutoridad = $row["TipoAutoridad"]; //

    **$fecha = date_format($row["Fecha"],'d/m/Y h:i');** 

I just had to format it because when I brought it I marked it as an object, I hope and it works for someone else, I thank you very much for your help.

    
answered by 10.04.2017 в 16:52