0
I’m not getting my code working to create a sequential number can someone give me a hand? that’s the mistake:
Warning: mysqli_query() expects at least 2 parameters, 1 given in
C:\Bitnami\wampstack-7.1.13-1\apache2\htdocs\mvpbx\php\caso.php on line 28
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null
given in C:\Bitnami\wampstack-7.1.13-1\apache2\htdocs\mvpbx\php\caso.php on
line 29
string(52) "INSERT INTO caso (numero, perfil_id) VALUES (1, '4')"
button to trigger the creation of the service number in the BD
<form action="php/adiciona-caso.php" method="post" >
<li><button type="submit" value="4"
name="perfil_id" id="perfil_id" class="btn btn-success btn-sm">Novo Atendimento</li></a>
<input type="hidden" value="1" name="numero" id="numero">
adds case;
<?php
$caso = new caso();
$caso->setNumero($_POST["numero"]);
$caso->setPerfil(new Perfil());
$caso->setPerfil($_POST["perfil_id"]);
//var_dump($caso);exit;
$dao = new casoDAO($conexao);
if ($dao->insereCaso($caso)) {
?>
<?php $_SESSION["atendimento_logado"] = $atendimento["numero"];?>
<script type="text/javascript">
window.location="../novo-atendimento.php"
</script>
<?php
DAO
function insereCaso($caso) {
$query = "INSERT INTO caso (numero, perfil_id) VALUES ($caso->getNumero()), '{$caso->getPerfil()}')";
//var_dump($query);exit;
$resultado = mysqli_query($conexao, $query);
$caso = mysqli_fetch_assoc($resultado);
return $caso;
}
case class
class Caso
{
private $conexao;
function __construct($conexao){
$this->conexao = $conexao;
}
public $id;
public $numero;
public $perfil;
public function getNumero()
{
return $this->numero;
}
public function setNumero($numero)
{
$query = mysqli_query($conexao, "SELECT * FROM caso ORDER BY numero DESC LIMIT 1");
$array = mysqli_fetch_array($query);
$ultimo = $array["numero"];
$numero = $ultimo+1; // Peguei o ultimo numero e somei 1
$this->numero = $numero;
}
You are mixing mysqli with mysql?
– Kevin Kouketsu
Possible duplicate of Why should we not use mysql type functions_*?
– Darlei Fernando Zillmer
Thanks Kevin, I had not seen this wrong when copying a solution from the forum. Fixed. Thanks Darlei, already corrected but I still have some errors.
– Sergio Guerjik