Error calling DB table

Asked

Viewed 101 times

0

I’m a beginner in Mysql and PHP, and I want to basically list the information I have on db on a page html. I made the code and is returning these errors:

Warning: mysqli_select_db() expects Parameter 1 to be mysqli, string Given in C: xampp htdocs testeman vendo.php on line 10

Notice: Undefined variable: con in C: xampp htdocs testeman vendo.php on line 13

Warning: mysqli_query() expects Parameter 1 to be mysqli, string Given in C: xampp htdocs testeman vendo.php on line 13

Warning: mysqli_error() expects Exactly 1 Parameter, 0 Given in C: xampp htdocs testeman vendo.php online 13

Github of the code: https://github.com/howdruss/AjudaStack/blob/master/Duvida

NOTE: I’m new to the site and I’m confused about putting the code here.

1 answer

0


Check if this is so:

<? php

$servidor = "localhost";
$usuario = "root";
$senha = "";
$dbname = "teste123";

// coneão ao banco de dados
$conn = mysqli_connect ($servidor, $usuario, $senha, $dbname);

$query = "SELECT nome, email, assunto FROM suatabela";
$dados = mysqli_query ($conn,$query);
$linha = mysqli_fetch_assoc ($dados);

 ?>

The connection of mysqli_query was reversed, I also noticed a lot of incorrect variables..

  • Oops, excuse me but could you be clearer? kkk I’m beginner yet, and I got a little lost in your resolution :/

  • looking at the code I notice a comparison if (total of $> 0) { Wrong at first instance: would be : if ($total > 0){ .

  • i updated the code there on github: and continue with these errors: Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs testeman vendo.php on line 14 Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs testeman vendo.php on line 15 Warning: mysqli_free_result() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs testeman vendo.php on line 42

  • Now that I’ve seen Voce you don’t need it because it’s calling db above: $db_select = mysqli_select_db ($Conn ,$dbname); , and so on : $query = "SELECT name, email, subject FROM your table"; $data = mysqli_query ($Conn,$query); $line = mysqli_fetch_assoc ($data); $total = mysqli_num_rows($data)

  • meeeeeeee, It was, it helped me a lot of dude <3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.