Link to home
Start Free TrialLog in
Avatar of Prisilya Jane
Prisilya Jane

asked on

Warning murali_query() error

Why I'm always getting warning: Natalie_query() expects parameter 1 to be mysqli, null given in c:\xampp\htdocs\view\dokumen.php on line 57
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Could you post the code that is generating this error?
Avatar of Prisilya Jane
Prisilya Jane

ASKER

<?php
function load_gred()
{
	include 'configure.php';
	$output= '';
	$sql = "SELECT * FROM `tbl_gred` ORDER BY gred_nama";
	$result = mysqli_query($conn, $sql);
	
	while( $row=mysqli_fetch_array($result))
	{
		$output .= '<option value="'.$row["gred_id"].'">'.$row["gred_nama"].'</option>';
	}
	return $output;	
}

function load_negeri()
{
	include 'configure.php';
	$output= '';
	$sql = "SELECT * FROM `tbl_negeri` ORDER BY negeri";
	$result = mysqli_query($conn, $sql);
	
	while( $row=mysqli_fetch_array($result))
	{
		$output .= '<option value="'.$row["negeri_id"].'">'.$row["negeri"].'</option>';
	}
	return $output;	
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Sistem E-Kuarters</title>
<link href="scripts/view.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="scripts/styles2.css">
   <script src="scripts/min.js" type="text/javascript"></script>
   <script src="script.js"></script>
   <script src="test.js">
</script>
</head>

<body id="bod">
	<div class="content" align="center">
	
		<table width="75%" height="680" border="0" cellpadding="5" cellspacing="5" align="center" bgcolor="#FFFFFF">
	<!--end header section -->
		<!--start content section -->
			<td width="1000" align="center" valign="top" bgcolor="#FFFFFF" ><br><br><br>
			<h2 align="center">PERMOHONAN KUARTERS</h2>
			
				<?php
				$id_penghuni =$_GET['id_penghuni'];
				$sql = "SELECT * FROM kpenghuni WHERE id_penghuni = $id_penghuni";
				$result = mysqli_query($conn, $sql);
				
				$nama= $row['nama'];
				$noKp= $row['noKp'];
				$email= $row['email'];
				$noHp= $row['noHp'];
			?>
			
			<table width="100%" border="1" class="table4">
			<tr>
				<td> Nama:</td>
				<td><?php echo $nama ;?></td>
			</tr>
			<tr>
				<td> IC NUMBER:</td>
				<td><?php echo $noKp ; ?></td>
			</tr>
				<tr>
				<td> Email:</td>
				<td><?php echo $email ; ?></td>
			</tr>
			<tr>
				<td> Phone Number:</td>
				<td><?php echo $noHp; ?></td>
			</tr>
				
				
			</table><br><br><br>
			<p align="center"><input  type="submit" name="submit" value="PRINT" class="table2" onclick="print();"/></p>
			<p align="center"><input  type="submit" name="submit" value="BATAL" class="table2" onClick="history.back(-1);"/></p>
				
		</table>
	</div>
</body>
</html>

Open in new window

Line 57 of the code you posted is blank - it does not tie up with the error you are receiving.

Then you posted
warning: Natalie_query() expects parameter 1 to be mysqli
There is no Natalie_query() in the code you posted

From your opening question
Warning murali_query() error
There is no murali_query() in the code you posted.

So, the code you have posted does not help us to understand what your problem is.
Ops I'm really Sry..Actually it is a typo
Natalie is mysql_query()
Murali is actually mysql_query()
So what line is the error on? Based on the listing above line 57 is blank?

I am going to say this again - consider moving off mysql - it has been deprecated.

It sounds like your connection is failing. I assume the connection is being set in this file
include 'configure.php';

Open in new window


What does that look like?

PLEASE - before you post connection scripts make sure you blank the server, username and password fields.
Your "configure.php" seems to be initializing "$conn".  However, when you call include in the following functions:
function load_gred()
{
	include 'configure.php';
...
}
function load_negeri()
{
	include 'configure.php';
...
}

Open in new window


The $conn variable is valid only within those functions.  Your problem is that on line 56 you are trying to use $conn, but it has  not been initialized.  You can:

A. move the include statement outside of the functions and then inside the functions declare $conn as a global variable:
<?php
include 'configure.php';

function load_gred()
{
global $conn;
	$output= '';
	$sql = "SELECT * FROM `tbl_gred` ORDER BY gred_nama";
	$result = mysqli_query($conn, $sql);
	
	while( $row=mysqli_fetch_array($result))
	{
		$output .= '<option value="'.$row["gred_id"].'">'.$row["gred_nama"].'</option>';
	}
	return $output;	
}

function load_negeri()
{
global $conn;
	$output= '';
	$sql = "SELECT * FROM `tbl_negeri` ORDER BY negeri";
	$result = mysqli_query($conn, $sql);
	
	while( $row=mysqli_fetch_array($result))
	{
		$output .= '<option value="'.$row["negeri_id"].'">'.$row["negeri"].'</option>';
	}
	return $output;	
}

//then when you call the functions, you don't need any parameters
load_negeri();
?>

Open in new window


OR
B. You can augment the functions to accept a mysqli connection handle instead of declaring $conn as a global variable, but when you call the functions, you need to explicitly pass $conn:
<?php
include 'configure.php';

function load_gred(mysqli $conn)
{
	$output= '';
	$sql = "SELECT * FROM `tbl_gred` ORDER BY gred_nama";
	$result = mysqli_query($conn, $sql);
	
	while( $row=mysqli_fetch_array($result))
	{
		$output .= '<option value="'.$row["gred_id"].'">'.$row["gred_nama"].'</option>';
	}
	return $output;	
}

function load_negeri(mysqli $conn)
{
	$output= '';
	$sql = "SELECT * FROM `tbl_negeri` ORDER BY negeri";
	$result = mysqli_query($conn, $sql);
	
	while( $row=mysqli_fetch_array($result))
	{
		$output .= '<option value="'.$row["negeri_id"].'">'.$row["negeri"].'</option>';
	}
	return $output;	
}

//then when you call the functions, you DO need a mysqli object/parameter
load_negeri($conn);#the assumption here is that configure.php has $conn=new mysqli(...);

?>

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.