0
I tried to make a code in PHP and I’m having difficulties with the query of SQL Server, now I tried to make a query another way and gave error 500 in PHP what can be?
Code of my page:
<?php
$servidor = 'VINIPC\SQLEXPRESS';
$db = 'Db_Tank';
$usuario = 'sa';
$senha = 'vini1234';
$conexao = sqlsrv_connect($servidor, array('Database' => $db, 'UID' => $usuario, 'PWD' => $senha));
$error = null;
$sucses = null;
if(isset($_POST['Promo'])) {
$AwardID = $_POST['AwardID'];
$ActiveID = $_POST['ActiveID'];
$PullDown = $_POST['PullDown'];
if($AwardID == null)
$error.= 'Houve um erro em AwardID!<br />';
if($error == null) {
$sql = ("INSERT INTO [dbo].[Active_Number] ([AwardID], [ActiveID], [PullDown]) VALUES('$AwardID', '50', 'False')");
$stmt = sqlsrv_prepare( $conexao, $sql, array($AwardID, $ActiveID, $PullDown);
if( !$stmt ) {
die( print_r(sqlsrv_errors());
}
$sucses = 'O código: "'.$AwardID.'" foi validado com sucesso.<br />';
}
}
function geraSenha($tamanho = 18, $maiusculas = true, $numeros = false, $simbolos = false)
{
$lmin = 'abcdefghijklmnopqrstuvwxyz';
$lmai = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$num = '1234567890';
$simb = '!@#$%*-';
$retorno = '';
$caracteres = '';
$caracteres .= $lmin;
if ($maiusculas) $caracteres .= $lmai;
if ($numeros) $caracteres .= $num;
if ($simbolos) $caracteres .= $simb;
$len = strlen($caracteres);
for ($n = 1; $n <= $tamanho; $n++) {
$rand = mt_rand(1, $len);
$retorno .= $caracteres[$rand-1];
}
return $retorno;
}
?>
<div id="tbtoolbar">
<center>
<input name='AwardID' id='AwardID' type='text' maxlength='40' value='<?php echo geraSenha(18, true, false, false); ?>' readonly />
<button name='Promo' id="Promo" type="submit" class="btn btn-default">Validar código</button>
<?php echo '<center><div><font color="red">'.$error. '</font></div></center>'; echo '<center><div><font color="green">'.$sucses. '</font></div></center>'; ?></center>
</center>
</div>
<script>
This error is server and is very generic. It has to post the last logs that Apache generated?
– Giancarlo Abel Giulian
Need to enable error display, at the beginning of the file put
ini_set('display_errors', true); error_reporting(E_ALL);
then [Edit] the question and add the error message.– rray