5
I have a site that is being done with PHP + SQL SERVER, and to log in needs client code, and it puts there only that always says that is incorrect, and that is correct.
Apparently the sqlsrv_num_rows
not working, because I put the correct login and does not enter the site I made.
Login validation code:
<?php
session_start();
$serverName = "10.0.0.0.0";
$connectionInfo = array( "Database"=>"banco", "UID"=>"usuario", "PWD"=>"senha" );
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$var1 = $_POST['codMont'];
$sql = "SELECT *
FROM AB7030 AB7,ABB030 ABB,AB6030 AB6, AA1030 AA, SA1030 SA
WHERE ABB.D_E_L_E_T_ = ''
AND AB7.D_E_L_E_T_ =''
AND AB6.D_E_L_E_T_ = ''
AND SA.D_E_L_E_T_ = ''
AND ABB.ABB_FILIAL = AB6.AB6_FILIAL
AND ABB.ABB_NUMOS = AB6.AB6_NUMOS
AND ABB.ABB_FILIAL = AB7.AB7_FILIAL
AND ABB.ABB_NUMOS = AB7.AB7_NUMOS
AND AB6.AB6_CODCLI = SA.A1_COD
AND AA.AA1_CODTEC = ABB_CODTEC
AND ABB.ABB_CODTEC = '".$var1."'
AND AB7.AB7_TIPO IN ('1','3')
AND AB7_FILIAL = '99'";
$stmt = sqlsrv_query($conn, $sql);
$row_count = sqlsrv_num_rows($stmt);
if ($row_count > 0 ){
$_SESSION['codMont'] = $var1;
header('location:homee.php');
}else{
unset ($_SESSION['codMont']);
$mensagem = "<div class='alert alert-danger'>Código do Montador ou senha incorretos. Tente novamente!</div>";
printf ($mensagem);
printf ($var1);
}
Even if I put the correct or incorrect code does not work, always says that has no registration with this code, and yes. Does anyone know what the problem would be?
Have you tried printing the first line to see if SQL actually returns a result?
– Wilson Faustino
I put to print the
$stmt
and the answer wasResource id #6
– Maria
Do so to display the results: $stmt = sqlsrv_prepare($Conn, $sql); $result = sqlsrv_execute($stmt); $Row = sqlsrv_fetch_array($result); print_r($Row);
– Wilson Faustino
Made that mistake:
Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\web\teste.php on line 37
Código do Montador ou senha incorretos. Tente novamente!
– Maria
And using your $stmt? by adding below the $row_count line the following: $Row = sqlsrv_fetch_array($stmt); print_r($Row);
– Wilson Faustino
Now printed out what I ordered on
SELECT
and changed theif ($row_count > 0 ){...
forif ($row > 0 )
and it worked!!! Thank you very much!!!– Maria
I think you should not use $Row>0, at least you should use a Count($Row)>0. But I don’t think we have reached a correct result yet.
– Wilson Faustino
I put the
count($row)>0
and works well. Pq says that we have not reached a correct result?– Maria