0
Hello, how can I create a php query that click the button insert the codes in the table?
My code:
<?php
$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) {
$q = q("INSERT INTO [dbo].[Active_Number] ([AwardID], [ActiveID], [PullDown]) VALUES('$AwardID', '50', 'False')");
$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>
I want to know how you query, there just explains the connection
– user39571
"I didn’t quite understand the connection part, "I got it wrong then.
– Augusto
How you connect PHP to SQL, I want to know how you run the PHP query pro SQL
– user39571
Which database are you using? Mysql? Postgres? First you have to create a connection to the database. Then use the functions related to your data or PDO, passing your connection variable as parameter. By the way, the database and its tables must have been created before.
– Antonio Alexandre
SQL Server 2014, could you explain me in code?
– user39571
Here is an example using lib sqlsrv.
– rray
I tried to do but I could not put the code I tried to do?
– user39571
Unfortunately it seems that connecting PHP with SQL Server is not as trivial as doing it with Mysql or Postgres. I recommend you to read the documentation from the Installation of SQL Server Express Edition in your development environment. You may need to install dlls to run PHP. http://php.net/manual/en/book.mssql.php
– Antonio Alexandre