i'm working with MySQL for the first time in this way.
Initial position: I have a small webpage with a basic login through PHP and MySQL - this works fine. Now i've created another table inside the database with different sorts of meat products.
First i would need to read all products in the data-table to edit/delete or add new products.
The meat product table is like this:
- meat 1
- meat 2
- meat 3 n. xxx n
I have a "home.php" with the product sortiment and HTML elements I have a config.php to connect to the database I have a load-fleisch.php to connect to the meat product table I have a process.js to get the JSON Data and create HTML elements
Problem: The Data from load-fleisch.php doesn't load. load-fleisch.php
<?php
// include config file
require_once 'config.php';
// Check user login or not
if(!isset($_SESSION['uname'])){
header('Location: index.php');
}
//a PHP Super Global variable which used to collect data after submitting it from the form
$request = $_REQUEST;
// Set the INSERT SQL data
$sql = "SELECT fleischsorte FROM fleischprodukte";
// Process the query
$results = $db->query($sql);
// Fetch Associative array
$row = $results->fetch_assoc();
// Free result set
$results->free_result();
// Close the connection after using it
$db->close();
// Encode array into json format
echo json_encode($row);
?>
Thats my home.php WITHOUT the HTML Elements
<?php
include "config.php";
// Check user login or not
if(!isset($_SESSION['uname'])){
header('Location: index.php');
}
// logout
if(isset($_POST['but-logout'])){
session_destroy();
header('Location: index.php');
}
?>
This is my process.js
$( document ).ready(function() {
console.log("test1X");
// Ajax config
$.ajax({
type: "GET",
url: 'load-fleisch.php',
dataType: 'json',
beforeSend: function () {
},
success: function (response) {
console.log(response);
}
});
console.log("test3X");
});
Could someone give me some tips on how to solve the problem or other methods on how to approach the problem? Thank you very much in advance!