I have similar code that works with no errors but when I try and query my database I'm getting the several errors. Can anyone help ?
errors:
Notice: Undefined variable: link in C:\wamp64\www\twitter clone\functions.php on line 22
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp64\www\twitter clone\functions.php on line 22
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\wamp64\www\twitter clone\functions.php on line 24
Code;
<?php
session_start();
$link = mysqli_connect("localhost", "root", "pass", "twitter");
if (mysqli_connect_errno()) {
print_r(mysqli_connect_error());
exit();
}
if (isset($_GET['function']) == "logout"){
session_unset();
}
function displayTweets($type) {
if ($type == 'public'){
$whereClause = "";
}
$query = "SELECT * FROM tweets ".$whereClause." ORDER BY 'datetime' DESC LIMIT 10";
$result = mysqli_query($link, $query);
if (mysqli_num_rows($result) == 0) {
echo "No Tweets";
}
}
?>