-1
Hello I’m trying to search the courses from the database.To see the courses already registered not to register in db again. I’m showing this error:
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /storage/emulated/0/Documents/sistemaescolar/public/cad/curso.php on line 6
the connection code
$host="127.0.0.1"; $db="sistemaescolar"; $pswd=""; $user="root"; $connect = mysqli_connect ($host,$user,$pswd,$db); if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); }
I made this page below to decide what kind will get cadre,:
include_once "class_pessoa.php"; if(isset($_POST["buttonSubmit"])){ $escolha = filter_input(INPUT_POST,'opselect',FILTER_SANITIZE_NUMBER_INT); if(filter_var($escolha,FILTER_VALIDATE_INT)){ include_once "cad/conexao.php"; $sql = "SELECT * from tipoCad where id=$escolha"; $resultado = mysqli_query($connect,$sql); $dado= mysqli_fetch_assoc($resultado); if($dado["nome"] =="Curso"){ $curso = new Curso($dado["nome"]); } mysqli_close($connect); } }
In the part where you have the class Course,
Below is the code that is giving error when searching the bank:
$sql = "select * from cursos"; $resultado=mysqli_query($connect,$sql); while($dados= mysqli_fetch_assoc($resultado)){ echo $dados['nome']; }
https://answall.com/questions/101172
– NoobSaibot
$sql = "SELECT * from tipoCad where id=$escolha";
puts$escolha
in single quotes$sql = "SELECT * from tipoCad where id='$escolha'";
– user60252