Issue
I am new to PHP and SQL and trying run a code, which has run into a problem. Connected the SQL, included the PHP files and was working fine.
However, the moment I added the SQL query, I am getting an error
syntax error, unexpected token". Unexpected 'Name'. Expected ';'.intelephense(1001)
How can I fix this?
<?php
include 'partials/_header.php';
include 'partials/_dbconnect.php';
SELECT * FROM `categories` WHERE category_id=1;
?>
Solution
This is the correct way to run a query in PHP
partials/_dbconnect.php
:
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
the code
<?php
include 'partials/_header.php';
include 'partials/_dbconnect.php';
$result = $mysqli->query("SELECT Name FROM City LIMIT 10");
printf("Select returned %d rows.\n", $result->num_rows);
Answered By - Digen Prime Apps Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.