tags:

views:

26

answers:

3

Okay I have a piece of code that for some reason gives me the following errors.

Warning: mysqli_query() expects at least 2 parameters, 1 given in
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in

here is the code below.

$dbc = mysqli_query("SELECT * FROM sitename WHERE id='$user_id'"); 
while($row = mysqli_fetch_array($dbc)){ 
$state = $row["state"];
$city = $row["city"];
$zip = $row["zip"]; 
$bio_body = $row["bio_body"];

If you can please help me by giving me the correct code.

+3  A: 

You need to include the database link parameter as well as the query you want to run. Like this:

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$dbc = mysqli_query($mysqli,"SELECT * FROM sitename WHERE id='$user_id'");

I don't see why it wouldn't work after that's fixed.

inkedmn
A: 

mysqli_query expects a link identifier from the database as the first argument, which is returned by mysqli_connect.

this causing the query to get a null result, which is causing the second error.

http://us3.php.net/manual/en/mysqli.query.php

http://us3.php.net/manual/en/mysqli.connect.php

GSto
A: 

From PHP builder:

Description

Procedural style: mixed mysqli_query ( mysqli link, string query [, int resultmode] )

This basically means you are missing one parameter, the link you create when you open the database connection. Take a look at the following example:

$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$dbc = mysqli_query($link, "SELECT * FROM sitename WHERE id='$user_id'");

mysqli_fetch_array doesn't work because the previous command failed.

Anax