Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an errors it says
Parse error: syntax error, unexpected 'mysqli_query' (T_STRING)



What I have tried:

dbconnect.php
<?php



$host = "localhost";

$username = "root";

$password = "";

$db_name = "dbmargs"; 



$mysqli = new mysqli($host, $username, $password, $db_name);



if(mysqli_connect_errno()) {

echo "Error: Could not connect to database.";

exit;

}

?>


delete.php
<?php
include 'dbconnect.php'



mysqli_query("DELETE FROM tblregister WHERE id = '$id'")
or die(mysqli_error());      

?>
Posted
Updated 7-Mar-17 23:47pm
Comments
Richard MacCutchan 8-Mar-17 5:39am    
The message implies that there is something not quite right with the included file. I think you need a semi-colon after the include filename.
Jim Clinton 8-Mar-17 5:43am    
oh i forgot the semi-colon but it still not works it says

Warning: mysqli_query() expects at least 2 parameters,


Notice: Undefined variable: id in C:\xampp\htdocs\cwang\admin\delete.php on line 6

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\cwang\admin\delete.php on line 6

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\cwang\admin\delete.php on line 7

Just read the function documentation PHP: mysqli::query - Manual[^]:
PHP
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ])

The functions requires two or three parameters:
Quote:
link

Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init()

query

The query string.

So you have to use [EDIT: Added corrected error calls which is also missing the parameter]
PHP
mysqli_query($mysqli, "DELETE FROM tblregister WHERE id = '$id'") or die(mysqli_error($mysqli));
OR
PHP
$mysqli->query("DELETE FROM tblregister WHERE id = '$id'") or die($mysqli->error);


Once again:
I suggest to not mix procedural and object styles. Choose one and use only that. It will help to avoid such errors.
See also PHP: Dual procedural and object-oriented interface - Manual[^]:
Quote:
It is possible to switch between styles at any time. Mixing both styles is not recommended for code clarity and coding style reasons.
 
Share this answer
 
v2
Comments
Jim Clinton 8-Mar-17 5:53am    
Notice: Undefined variable: id
Jochen Arndt 8-Mar-17 6:09am    
Yes. Another error. There is no $id variable defined.

I focussed on the specified error (the other errors has been added by you while I was writing my solution):
"Parse error: syntax error, unexpected 'mysqli_query' (T_STRING)"

That means:
The parser found a string but expects something else (a mysqli object here).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900