Im having problems while trying to fetch an id of a specific string in mySQL
My table:
ID | URL |
1 | http://google.com |
When I put this V
SELECT ID FROM urls
WHERE url LIKE ('http://google.com')
code into mySQL it does show the ID 1, but Im trying to let it display on a page on my website.
The code below is the code of the page where Im trying to display this code.
<?php
// Create connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to create table
$url = 'http://google.com';
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "
SELECT ID FROM urls
WHERE url LIKE ('http://google.com')
";
$result = $conn->query($sql);
echo $result;
$conn->close();
Yes I have defined DB_HOST, DB_USER, DB_PASS and DB_NAME and they work fine.
Whenever I execute the code, this error message appears.
Catchable fatal error: Object of class mysqli_result could not be converted to string in /home/u926065153/public_html/db_t.php on line 16
Please note I dont have a lot of experience with SQL and this is my way of learning.