mysqli_num_rows funktioniert nicht?

Hallo ich wollte etwas auf Strato hosten. Jedoch funktioniert mysqli_num_rows nicht.

Weiß jemand wie ich den Fehler beheben kann.

Hier die Fehler meldung:

Connected successfully Fatal error: Uncaught TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool given in /mnt/web016/e0/16/511052116/htdocs/cgi-bin/Inventar/index.php:28 Stack trace: #0 /mnt/web016/e0/16/511052116/htdocs/cgi-bin/Inventar/index.php(28): mysqli_num_rows() #1 {main} thrown in /mnt/web016/e0/16/511052116/htdocs/cgi-bin/Inventar/index.php on line 28

Und mein Code:

<?php session_start:
require_once('dbconnection.php');
$servername = "...";
$username = "...";
$password = "...";


// Create connection
$con = new mysqli($servername, $username, $password);


// Check connection
if ($con->connect_error) {
  die("Connection failed: " . $con->connect_error);
}
echo "Connected successfully";
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('mysql.trace_mode', true);








//Code for Registration 
if(isset($_POST['signup']))
{
	$fname=$_POST['fname'];
	$lname=$_POST['lname'];
$sql=mysqli_query($con,"select id from users where fname='$fname'");
$row=mysqli_num_rows($sql);
if($row>3)
{
	echo "<script>alert('Artikel befindet sich schon 3 mal in der Truhe');</script>";
} else{


	$msg=mysqli_query($con,"insert into users(fname,lname) values('$fname','$lname')");
}
if($msg)
{
	echo "<script>alert('Erfolgreich Eingetragen');</script>";
}
}


?>


PHP, Strato
Javascript geht nicht in einem von XMLHttpRequest geladenen Div?

Hallo ich versuche gerade mit XMLHttpRequest einen Div auf meiner Webseite zu aktuallisieren soweit geht das auch nur wenn ich versuche in der datei die geladen werden soll etwas mit Javascript auszuführen wird dies nicht getan. Ich habe aber überprüft das die datei geladen wird. Das was ich in JS geschrieben habe wird auch in den Div geladen nur nicht ausgeführt..
Hier meine Datei die den Div läd:

  <script language="javascript" type="text/javascript">
    function getData() {
      var xhr = new XMLHttpRequest();                 // Create XMLHttpRequest object
    
      xhr.onload = function() {                       // When response has loaded
        // The following conditional check will not work locally - only on a server
        if(xhr.status === 200) {                       // If server status was ok
          document.getElementById('load').innerHTML = xhr.responseText; // Update
        }
      };
      
      xhr.open('GET', 'sql/load.php', true);        // Prepare the request
      xhr.send();                                 // Send the request
    }
    
    setInterval(getData, 1000);
</script>

<div id='load'></div> 

Hier meine Load.php

<?php
session_start();
require_once "config.php";
require_once "link_user.php";
        //Check new messages
        $test = "false";
        $sql = "SELECT * FROM msg WHERE touser='$user_name' AND readmsg='$test' LIMIT 1";
        $query = mysqli_query($db_link, $sql) or die (mysqli_error());
        $num = mysqli_num_rows($query);
        while ($row = mysqli_fetch_array($query)) {
            $chat_id = $row["chat_id"];

        }
        if($num == 1){
            
echo "<script>
var notification = new Notification('Notification title', {
    icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
    body: 'Hey there! You\'ve been notified!',
   });</script>
";
        }
?>
Computer, HTML, programmieren, JavaScript, PHP

Meistgelesene Beiträge zum Thema PHP