Hi, I'm trying to recreate PHPMyAdmin through a website however, I can update data inside newer databases however, for existing databases I have this error going on
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\improject-master\table-browse-edit.php on line 48
I tried echo-ing $mysqli->error and this shows up
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
I've tried looking through google for the solutions however to no avail they don't seem to work on this.
Here's my php
<?php
session_start();
error_reporting(E_ERROR | E_PARSE);
$tname = $_SESSION['tname'];
$row_id = $_SESSION['row_id'];
$dbname = $_SESSION['dbname'];
$conn = mysqli_connect("localhost", "root", "", $dbname);
$result = mysqli_query($conn, "SHOW COLUMNS FROM $tname");
$fields = array();
$new_fields = array();
$counter = 0;
if(isset($_POST['save'])){
$id = $_POST['id'];
$new_fields = $_SESSION['fields'];
$counter = $_SESSION['counter'];
$sql .= "UPDATE $tname SET ";
for($i = 0 ; $i < $counter ; $i++){
$sql .= $new_fields[$i];
$sql .= " = '" . $_POST[$new_fields[$i]] . "' ";
if($i < $counter - 1){
$sql .= " , ";
}
}
$sql .= " WHERE $row_id = $id";
$result = mysqli_query($conn, $sql);
if (!$result) {
$err = "Error updating data. Please try again.";
} else {
header("Location: table-browse.php");
}
}
and the line that the error was referring to is
<?php if(mysqli_num_rows($result) > 0): ?>
How do I make it so that I can edit data inside old databases as well?
What I have tried:
It seems that this error happens when i try to pass a query to a database/table that was created within PHPMyAdmin itself. How do I remedy that?