Reputation: 27
Currently I am trying to execute this code, it doesn't return me any error. It get's in the If that returns the $Query but doesn't actualy insert the values in the database. If i grab the $Query form the echo and paste it on Management Studio it inserts correctly. Can you help me on what am i doing wrong?
<?php
$tmp = $_POST["field2"];
$qual = $_POST['field7'];
$servername = "gghj";
$ligar = array("database"=>"ztt","uid"=>"abwt","pwd"=>"22231");
$ligando = sqlsrv_connect($servername, $ligar);
if($ligando) {
$Query = "INSERT INTO PHCINQUERITOSUPORTE (tempoform,qualform) VALUES($tmp,$qual)";
$do = sqlsrv_query($ligando,$query);
if($do === false)
{
die( print_r( sqlsrv_errors(), true));
}
else{
echo $Query;
echo "<script> ;
$(window).on('load',function(){
$('#myModal').modal('show');
});
}
</script>";
}
}else{
echo "morreu";
die(print_r(sqlsrv_errors(),TRUE));
}
?>
Upvotes: 1
Views: 1271
Reputation: 321
I see the problem. You have used $query
when trying to run the query, but $Query
every other time. Remember PHP is case sensitive when it comes to variables. So if you declare a variable and the variable name contains a capital letter(s), you must ensure when calling the variable you have the capital letter(s) in the right place otherwise it thinks you are trying to call a different variable.
In your case just change $do = sqlsrv_query($ligando,$query);
to $do = sqlsrv_query($ligando,$Query);
and it will work.
Upvotes: 1