Warning: mysqli_close()

Hello,

I had enable the display error in PHP and I am having trouble fixing this error
“Warning: mysqli_close() expects parameter 1 to be mysqli,”

I am not sure what does it says but when I check my command it is correct.
here is my script below

mysqli_close($con);

You need to post the rest of your code. Make sure you didn’t already call MySQLi close somewhere else.

Just a side note, you don’t need to close the connection. It is automatically closed when the script finishes running.

IF that the case then I will just remarks it.

But here is the rest of the code.

[code]

L&K Billing System <?php $errorMessage = ''; $con=''; if (isset($_POST['submit'])) { include 'conn_db.php'; // include 'include/filter.php'; if($errorMessage == '' ) { include 'p1_add_inv.php'; } } //mysqli_close($con); ?>
<body>
	<div id="wrapper">
		<?php include('includes/header.php'); ?>
		<?php include('includes/nav.php'); ?>
		
		<div id="content">
			<h3>Invoice data entry</h3>
			<p>
				Please fill up the form below to add additional customer.
			</p>
			<p>
			<form method="post">
				<fieldset>
					<div>
					<label for="customer">Customer code</label>
					<input name="customer" type="Text" placeholder="Customer Code">
					</div>
					
					<div>
					<label for="description">Description</label>
					<input name="description" type="Text" placeholder="Description">
					</div>
					
					<div>
					<label for="part_number">Part Number</label>
					<input name="part_number" type="Text" placeholder="Part Number">
					</div>
					<div>
					<label for="qty">Quantity Kpcs</label>
					<input name="qty" type="Text" placeholder="Quantity Kpcs">
					</div>
					<div>
					<label for="trading_price">Trading Price</label>
					<input name="trading_price" type="Text" placeholder="Trading Price">
					</div>
					
					<div>
					<label for="amount">Amount</label>
					<input name="amount" type="Text" placeholder="Amount">
					</div>
					
					<?php if ($errorMessage != ''){echo $errorMessage;} ?>
					<input value="Create Invoice" name="submit" type="submit">
				</fieldset>
			</form>

			</p>
			
		</div> <!-- end #content -->

		<?php include('includes/p1_sidebar.php'); ?>
		<?php include('includes/footer.php'); ?>

	</div> <!-- End #wrapper -->
</body>
[/code]

Your problem maybe line 16. I would have to see your conn_db.

I created that one because if I did not issue a $con=""; there will be an error
here is the error below

Notice: Undefined variable: con in /var/www/p1_add_inv_form.php on line 28

If you don’t post all your code no one is going to be able to help you. You did something wrong somewhere else

Hi Kevin,

I am sorry I will be posting all the include files.
conn_db.php
[php]<?PHP

$con=mysqli_connect(‘localhost’, ‘root’, ‘****’, ‘billing’);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

?>[/php]

p1_add_inv.php
[php]<?php

$cust_code=$_POST[‘customer’] ;

$cust_search = mysqli_query($con,“SELECT inv_code FROM customer_info WHERE rec_no=’$cust_code’”);
if(mysqli_num_rows($cust_search) != 0) {

//$cust_code2 = mysqli_fetch_array($cust_search);
$cust_company = mysqli_fetch_array($cust_search);
//$cust_company = $cust_code2['inv_code'];

$petsa_taon = date("Y");
$petsa_buwan = date("m");

	mysqli_query($con,"INSERT INTO invoice_data (
	cust_rec, 
	description, 
	part_number,
	fob_price,
	qty,
	total_fob,
	trading_price,
	amount,
	company_code, 
	taon, 
	buwan, 
	serye
	)

	VALUES (
	'$_POST[customer]',
	'$_POST[description]',
	'$_POST[part_number]',
	'$_POST[fob_price]',
	'$_POST[qty]',
	'$_POST[total_fob]',
	'$_POST[trading_price]',
	'$_POST[amount]',
	'$cust_company['inv_code']', 
	'$petsa_taon', 
	'$petsa_buwan', 
	'$petsa_serye'
	)");

$errorMessage = '<font color="green"><b>One record added! - </b>Record Number: ' . mysqli_insert_id($con) . ' (Please take note of this number)</font><br>';

	}else {
$errorMessage = $errorMessage .  '<font color="red">Customer record does not exist!</font><br>';
}	

?>[/php]

p1_sidebar.php

[code]

Navigation

	<li><a href="p1_add_inv_form.php">Create Invoice</a></li>
	<li><a href="p1_view_record.php">View Invoice Record</a></li>
[/code]

nav.php

[code]

<a href="index.php">Home</a>
<a href="contactus.php">Contact us</a>
<a href="about.php">About</a>
[/code]

footer.php

[code]<?php include('variables/variables.php'); ?>

<?php echo $footer ?>

[/code]

header.php

[code]<?php include('variables/variables.php'); ?>

<h2><?php echo $heading ?></h2>
[/code]

You have a syntax error on line 39
‘$cust_company[‘inv_code’]’,

NEEDS TO BE:

‘{$cust_company[‘inv_code’]}’,

Thanks for the reply. After changing the ‘{$cust_company[‘inv_code’]}’, error still shows.

I am still having error please check below

Warning: mysqli_close() expects parameter 1 to be mysqli, string given in /var/www/p1_add_inv_form.php on line 28

Only remarking will solve the problem? Please advise. Thanks.

[code]

L&K Billing System <?php $errorMessage = ''; $con=''; if (isset($_POST['submit'])) { include 'conn_db.php'; // include 'include/filter.php'; if($errorMessage == '' ) { include 'p1_add_inv.php'; } } mysqli_close($con); ?>
<body>
	<div id="wrapper">
		<?php include('includes/header.php'); ?>
		<?php include('includes/nav.php'); ?>
		
		<div id="content">
			<h3>Invoice data entry</h3>
			<p>
				Please fill up the form below to add additional customer.
			</p>
			<p>
			<form method="post">
				<fieldset>
					<div>
					<label for="customer">Customer code</label>
					<input name="customer" type="Text" placeholder="Customer Code">
					</div>
					
					<div>
					<label for="description">Description</label>
					<input name="description" type="Text" placeholder="Description">
					</div>
					
					<div>
					<label for="part_number">Part Number</label>
					<input name="part_number" type="Text" placeholder="Part Number">
					</div>
					<div>
					<label for="qty">Quantity Kpcs</label>
					<input name="qty" type="Text" placeholder="Quantity Kpcs">
					</div>
					<div>
					<label for="trading_price">Trading Price</label>
					<input name="trading_price" type="Text" placeholder="Trading Price">
					</div>
					
					<div>
					<label for="amount">Amount</label>
					<input name="amount" type="Text" placeholder="Amount">
					</div>
					
					<?php if ($errorMessage != ''){echo $errorMessage;} ?>
					<input value="Create Invoice" name="submit" type="submit">
				</fieldset>
			</form>

			</p>
			
		</div> <!-- end #content -->

		<?php include('includes/p1_sidebar.php'); ?>
		<?php include('includes/footer.php'); ?>

	</div> <!-- End #wrapper -->
</body>
[/code]

Get rid of the empty $con. You shouldn’t need it.

Hello

I have removed both $con=’’; and mysqli_close($con);
This should be ok?

Currently I do no longer see any errors.

Thank you for all your help Kevin. Still this is not the last.

Sponsor our Newsletter | Privacy Policy | Terms of Service