0
When trying to send values with zero on the left, when checking in the database I receive the values in zeros. Ex: 000431, appears in the database as 431. This value is being placed in the $prefix variable
Follow the code:
<?php
$bomba1 = $_POST["bomba"];
$bomba = floatval($bomba1);
$prefixo1 = strval($_POST["prefixo"]);
$combustivel = $_POST["combustivel"];
$prefixo2 = str_pad($prefixo1, 6, '0', STR_PAD_LEFT);
$prefixo = substr($prefixo2, -5);
echo $bomba ;
echo $prefixo ;
echo $combustivel ;
$serverName = "GALAXY\BDTL";
$connectionInfo = array( "Database"=>"Abastecimento", "UID"=>"", "PWD"=>"" );
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$sql = "INSERT INTO Abastecimento (prefixo, empresa) VALUES ($prefixo, 'TT' )";
//$params = array(1, "some data");
//$stmt = sqlsrv_query( $conn, $sql, $params);
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}else{
print_r("Gravação concluída");
}
?>
If the data type is numerical then zeros on the left are not significant. If you just want to display with zeros on the left just format properly when displaying.
– anonimo