MySQL PHP partial search - php

I have a problem with partial world search.
The code below works, but only with full word search. If I put only part of the word in the search box it does not work. Please can you give me a hint what to change to be able to make partial word search?
<?php include "connection.php";
$sql = "SELECT * FROM Klienci ";
if (isset($_POST['search'])) {
$search_term = mysql_real_escape_string($_POST['search_box']);
$sql .= "WHERE nazwaKlienta = '{$search_term}' ";
$sql .= " OR adresMail = '{$search_term}' ";
$sql .= " OR adresMail2 = '{$search_term}' ";
}
$query = mysql_query($sql) or die(mysql_error());
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BAZA | Dashboard</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/jumbotron-narrow.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="header">
<ul class="nav nav-pills pull-right">
<li class="active">Home</li>
<li>Dodaj Firmę</li>
</ul>
<h3 class="text-muted">ITalents</h3>
</div>
<div class="row marketing">
<div class="col-lg-12">
<h2>KLIENCI</h2>
<table class="table table-striped">
<form name="search_form" method="POST" action="display_data.php">
Search: <input type="text" name="search_box" value ="" />
<input type="submit" name="search" value="Search the table..." >
</form>
<tr>
<th>id</th>
<th>Klient</th>
<th>Email</th>
<th>Email 2</th>
<th>Data dodania do bazy</th>
</tr>
<?php while ($row = mysql_fetch_array($query)) {
//Display customer info
$output ='<tr>';
$output .='<td>'.$row['id'].'</td>';
$output .='<td>'.$row['nazwaKlienta'].'</td>';
$output .='<td>'.$row['adresMail'].'</td>';
$output .='<td>'.$row['adresMail2'].'</td>';
$output .='<td>'.$row['dataDodania'].'</td>';
$output .='<td>Edit</td>';
$output .='<td>Delete</td>';
$output .='</tr>';
//Echo output
echo $output;
?>
<?php } ?>
</table>
</div>
</div>
</div>
<div class="footer">
<p>© Company 2014</p>
</div>
</div> <!-- /container -->
</body>
</html>

The below code should work. You have to use LIKE instead of using equal. For example: WHERE something LIKE '%something2%'
<?php include "connection.php";
$sql = "SELECT * FROM Klienci ";
if (isset($_POST['search'])) {
$search_term = mysql_real_escape_string($_POST['search_box']);
$sql .= "WHERE nazwaKlienta LIKE '%{$search_term}%' ";
$sql .= " OR adresMail LIKE '%{$search_term}%' ";
$sql .= " OR adresMail2 LIKE '%{$search_term}%' ";
}
$query = mysql_query($sql) or die(mysql_error());
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BAZA | Dashboard</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/jumbotron-narrow.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="header">
<ul class="nav nav-pills pull-right">
<li class="active">Home</li>
<li>Dodaj Firmę</li>
</ul>
<h3 class="text-muted">ITalents</h3>
</div>
<div class="row marketing">
<div class="col-lg-12">
<h2>KLIENCI</h2>
<table class="table table-striped">
<form name="search_form" method="POST" action="display_data.php">
Search: <input type="text" name="search_box" value ="" />
<input type="submit" name="search" value="Search the table..." >
</form>
<tr>
<th>id</th>
<th>Klient</th>
<th>Email</th>
<th>Email 2</th>
<th>Data dodania do bazy</th>
</tr>
<?php while ($row = mysql_fetch_array($query)) {
//Display customer info
$output ='<tr>';
$output .='<td>'.$row['id'].'</td>';
$output .='<td>'.$row['nazwaKlienta'].'</td>';
$output .='<td>'.$row['adresMail'].'</td>';
$output .='<td>'.$row['adresMail2'].'</td>';
$output .='<td>'.$row['dataDodania'].'</td>';
$output .='<td>Edit</td>';
$output .='<td>Delete</td>';
$output .='</tr>';
//Echo output
echo $output;
?>
<?php } ?>
</table>
</div>
</div>
</div>
<div class="footer">
<p>© Company 2014</p>
</div>
</div> <!-- /container -->
</body>
</html>

Related

Asking about sorting or ordering results from a search engine by relevancy in php/Mysql

I have a search engine based on multiple select options that the user can enter a lot of option and the search engine fetch the database to get the the results of arrays that entered in the the select options but I need to make this code to fetch and get ordered the results by the most relevant
so this is the code :
<?php
//doctors.php
$connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");
$query = "SELECT DISTINCT Symptome4 FROM tbl_customer ORDER BY Symptome4 ASC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
?>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Home Page</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" />
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />
<link rel="stylesheet" href="./css/style.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href=".\css\bootstrap.css" rel="stylesheet" />
<link href="css/bootstrap-select.min.css" rel="stylesheet" />
<script src="js/bootstrap-select.min.js"></script>
</head>
<body>
<main class="find-bar">
<header id="header">
<div class="overlay overlay-lg">
</div>
<nav>
<div class="container">
<div class="logo">
<h1>Oxygenta</h1>
</div>
<div class="links">
<ul>
<li>
Home
</li>
<li>
Diagnosis
</li>
<li>
Doctors
</li>
<li>
Home Doctors
</li>
<li>
Nurses
</li>
<li>
Help
</li>
<li>
Sign Out
</li>
</ul>
</div>
</nav>
<div class="header-content">
<div class="container content">
<div class="column-1">
<h1 class="header-title">Find Your <br /> Favorite Doctor</h1>
<div class="wrapper">
<div class="search_box">
<div class="search_btn"><i class="fas fa-search"></i></div>
<input type="text" class="input_search" placeholder="What are you looking for?">
</div>
</div>
</div>
<img src="./img/doctor_PNG16022.png" class="img-bar" alt="" />
</div>
</div>
</header>
<section class="services section">
<div class="container left">
<div class="section-header">
<h2 data-title="">Symptoms</h2>
</div>
</div>
</section>
<div class="container">
<select name="multi_search_filter" id="multi_search_filter" multiple class="form-control selectpicker" style="width: 50%;">
<option value="Runny Nose">Runny Nose</option>
<option value="Sore Throat">Sore Throat</option>
<option value="Headaches">Headaches</option>
<option value="Sneezing">Sneezing</option>
<option value="High Temperature">High Temperature</option>
<option value="Hoarse Voice">Hoarse Voice</option>
<option value="Difficulty Swallowing">Difficulty Swallowing</option>
<option value="Drooling">Drooling</option>
<option value="Weak Voice">Weak Voice</option>
<option value="Coughs">Coughs</option>
<option value="Dry Throat">Dry Throat</option>
<option value="Difficulty Speaking">Difficulty Speaking</option>
<option value="Throat Pain">Throat Pain</option>
<option value="Fever">Fever</option>
<option value="Difficulty Breathing">Difficulty Breathing</option>
<option value="Loss Of Smell">Loss Of Smell</option>
<option value="Loss Of Taste">Loss Of Taste</option>
</select>
<input type="hidden" name="hidden_country" id="hidden_country" />
<br />
<table class="table table-striped ">
<tbody>
</tbody>
</table>
</section>
<script>
$(document).ready(function(){
load_data();
function load_data(query='')
{
$.ajax({
url:"fetch.php",
method:"POST",
data:{query:query},
success:function(data)
{
$('tbody').html(data);
}
})
}
$('#multi_search_filter').change(function(){
$('#hidden_country').val($('#multi_search_filter').val());
var query = $('#hidden_country').val();
load_data(query);
});
});
</script>
and this for fetch.php
<?php
//fetch.php
$connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");
if($_POST["query"] != '')
{
$search_array = explode(",", $_POST["query"]);
$search_text = "'" . implode("', '", $search_array) . "'";
$query = "
SELECT * FROM tbl_customer
WHERE Symptome4 IN (".$search_text.") OR Symptome2 IN (".$search_text.") OR Symptome1 IN (".$search_text.") OR Symptome3 IN (".$search_text.") OR Symptome5 IN (".$search_text.")
ORDER BY DiseaseID DESC ";
}
else
{
$query = "SELECT * FROM tbl_customer ORDER BY DiseaseID DESC";
}
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$total_row = $statement->rowCount();
$output = '';
if($total_row > 0)
{
foreach($result as $row)
{
$output .= '
<table><tr><td>
<div class="cards"></td>
<td><div class="card-wrap">
<div class="card ">
<div class="card-content z-index">
<img src="./img/nurse.png" class="icon" alt="" />
<h3 class="title-sm">'.$row["DiseaseName"].'</h3>
<h5 style="text-align: left;">
'.$row["Symptome1"].'
</p>
<p>
'.$row["Symptome2"].'
</p>
<p>
'.$row["Symptome3"].'
</p>
<p >
'.$row["Symptome4"].'
</p>
<p >
'.$row["Symptome5"].'
</p>
More Info
</td>
<td>
</div>
</div>
</div>
</div>
</div>
';
}
}
else
{
$output .= '
<tr>
<td colspan="5" align="center">No Data Found</td>
</tr>
';
}
echo $output;
?>
and this is the result:
enter image description here

php while loop not printing contents of an array horizontally in bootstrap

I am using a while loop in PHP to extract data for some items and print each query like a separate card in the same row as in a shopping cart. Bootstrap seems to print them vertically in separate rows. Expected layout
code
<!DOCTYPE html> <html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Shopping Cart</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="cart.css"> </head> <body>
<div class="container">
<?php
$connect = mysqli_connect('localhost','root','','cart');
$query = 'SELECT * FROM products ORDER BY id ASC';
$result = mysqli_query($connect, $query);
if (mysqli_num_rows($result)>0) {
while($product = mysqli_fetch_assoc($result)){
?>
<div class="col-sm-4 col-md-3">
<form method="post" class="" action="index.html">
<div class="products ">
<img src="<?php echo $product['image']; ?>" class="img-fluid" />
<h4 class="text-info"><?php echo $product['name']; ?></h4>
<h4>INR <?php echo $product['price']; ?></h4>
<input type="text" name="quantity" class="form-control" value="1" />
<input type="submit" name="add_to_cart" class="btn btn-info" value="Add" />
</div>
</form>
</div>
<?php
}
}
?>
</div>
</body>
</html>
I have tried using class="row-fluid" before the start of the loop or even the .product but it doesn't help.
Actual output in normal screen or developer tool
To allow for the products to be shown in 'rows' (horizontally), you need to add a <div class="row"> to your HTML code. I've banged together a small demo, that shows the basic idea (and the use of HEREDOC which allows for (IMHO) cleaner separation of HTML and PHP code).
Function renderProduct() is invoked through a foreach() loop on a dummy product range stored in array $products to imitate your database while loop.
The gist:
<?php
function renderProduct($product = 'n/a') {
$htmlProduct = <<<HEREDOC
<div class="col-sm-4 col-md-3">
<form method="post" class="" action="index.html">
<div class="products ">
<img src="$product" class="img-fluid" />
<h4 class="text-info">$product</h4>
<h4>INR $product</h4>
<input type="text" name="quantity" class="form-control" value="1" />
<input type="submit" name="add_to_cart" class="btn btn-info" value="Add" />
</div>
</form>
</div>
HEREDOC;
return $htmlProduct;
}
$htmlStart = <<<HEREDOC
<!DOCTYPE html> <html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Shopping Cart</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="cart.css">
</head>
<body>
<div class="container">
<div class="row"> <!-- ADDED -->
HEREDOC;
$htmlEnd = <<<HEREDOC
</div> <!-- close row -->
</div> <!-- close container -->
</body>
</html>
HEREDOC;
// render page
echo $htmlStart;
$products = ['product1', 'product2', 'product3', 'product4', 'product5', 'product6', 'product7'];
foreach($products as $prod) {
echo renderProduct($prod);
}
echo $htmlEnd;

How to change pages without changing url?

I am currently working on a project, but I'm just stuck on something. I know there are a lot of questions related to this, but I couldn't find any useful information.
I'm new to PHP and I need to write php code which changes pages and doesn't change the URL (i.e if I am going to login.php, the URL should still be home.php) and I need to use the GET method.
I'm sorry if there are some mistakes in my code, but thanks for any help.
Here is my home.php file:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="Layout.css" />
<link rel="stylesheet" type="text/css" href="Menu.css" />
<meta http-equiv="Content-Type" content="text/html"; charset=utf-8" />
<title> Title </title>
</head>
<body>
<div id="Holder"></div>
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li> Home </li>
<li>Login </li>
<li>Register </li>
</ul>
</nav>
</div>
<div id="Content">
<div id="PageHeading">
<h1> Welcome to HOME page </h1>
</div>
</div>
<div id="Footer"></div>
</body>
</html>
Here is my login.php file:
<?php
session_start();
$db = mysqli_connect ("localhost", "root", "","information1");
if (isset($_POST['Register'])){
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);
$sql = "SELECT username, password FROM user WHERE username='$username' AND
password='$password'";
$base =mysqli_query ($db, $sql);
if (mysqli_num_rows($base) == 1) {
header ("location: nav_menu.php");
}
else
{
echo "Passwords does not match";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Layout.css" />
<link rel="stylesheet" type="text/css" href="Menu.css" />
<meta http-equiv="Content-Type" content="text/html"; charset=utf-8" />
<title> Title </title>
</head>
<body>
<div id="Holder"></div>
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li> Home </li>
<li>Login </li>
<li>Register </li>
</ul>
</nav>
</div>
<div id="Content">
<div id="PageHeading">
<h1> Welcome to HOME page </h1>
</div>
<div id="ContentRight">
<h2> Text2 </h2> </br>
<h6> Text3 </h6 </br>
</div>
<div id="ContentLeft">
<form name ="form2" method="POST" action="login.php">
<div class = "ContentTable">
<table width="400" border="0" align ="left">
<tbody>
<h4> Username: </h4>
<input type="text" name= "username" id="username" required></td>
</tr>
<tr>
<td> </td>
</tr>
<h4> Password: </h4>
<input type="text" name= "password" id="password" required></td>
</tr>
<td><input type="submit" name="Register" id="RegisterButton" value="Register"></td>
</div>
</div>
</form>
<div id="Footer"></div>
</body>
</html>

PHP MySQL Updating in a Form Is not Updating [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
So this is for a school project. We are making a website and I am using PHP with MySQL and phpMyAdmin.
My problem is that when I am updating a product instead of changing the field, it erases all the data for the row besides the ProductID, which is the primary key.
***EDIT: I will address this here: This is a school project and thus security is not an issue for me.
I just need the products to update, now. The erasing problem has been solved.
** End Edit **
Code:
update-page.php - has the actual form in it
<'?'php
session_start();
require_once 'db_connect.php';
$query = "SELECT * FROM Products";
$result = mysql_query($query);
if (!$result) {
die("Database query failed: " . mysql_error());
}
$num = mysql_num_rows($result);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>AppleRetail - Update Product</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/update-custom.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">AppleRetail.com</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
Products
</li>
<li>
Add Product
</li>
<li>
Delete Product
</li>
<li>
Update Price
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<!-- Jumbotron Header -->
<header class="jumbotron hero-spacer">
<h1>Update Product</h1>
<p>Change the information below and select "Update" to update the product information.</p>
</header>
<hr>
<form action="update.php" method="POST">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Product ID</th>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Image URL</th>
</tr>
</thead>
<tbody>
<?php while($row = mysql_fetch_array($result)) { ?>
<tr>
<input type="hidden" name="id" value="<?php echo $row['ProductID']; ?>"/>
<td><?php echo $row['ProductID']; ?></td>
<td><input type="text" name="name" value="<?php echo $row['Name']; ?>"/></td>
<td><input type="text" name="description" value="<?php echo $row['Description']; ?>"/></td>
<td><input type="text" name="price" value="<?php echo $row['Price']; ?>"/></td>
<td><input type="text" name="image" value="<?php echo $row['Image']; ?>"/></td>
<td>
<input type="submit" name="update" value="Update">
</td>
</tr>
<?php }?>
</tbody>
</table>
</form>
<!-- Footer -->
<footer>
<div class="row">
<div class="col-lg-12">
<p>Copyright © AppleRetail.com</p>
</div>
</div>
</footer>
</div>
<!-- /.container -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
And then the update.php has the query in it.
<?php
session_start();
require_once 'db_connect.php';
// Grab the posted data and send to variable
$ProductID = $_POST['ProductID'];
$Name = $_POST['Name'];
$Description = $_POST['Description'];
$Price = $_POST['Price'];
$Image = $_POST['Image'];
$_SESSION['ProductId1'] =$ProductId;
$_SESSION['Name1'] = $Name;
$_SESSION['Description1'] = $Description;
$_SESSION['Price1'] = $Price;
$_SESSION['Image1'] = $Image;
$query = "UPDATE Products SET Name='$Name', Description='$Description', Price='$Price', Image='$Image' WHERE ProductID='$ProductID'";
$result = mysql_query($query);
if (!$result) {
die("Database query failed: " . mysql_error());
}
if($result =='true'){echo "<p>Post is add</p>";}
else{ echo "<p>Post is not add</p>"; }
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>AppleRetail Update Page</title>
</head>
<body>
<?php header("Location: updateFinal.php"); ?>
</body>
</html>
Any Help is appreciated! Thank you!
Please ask if more information is needed!
input type="text" name="name"
input type="text" name="description"
Compare that with
$_POST['Name'];
^
$_POST['Description'];
^
And spot the error ;)

Convert a PHP "Object" to a SESSION?

I have a {$obj->product_stock} which contains a numeric value - the stock of the product.
How can I convert that {$obj->product_stock} to a SESSION? Here is what I tried...
$_SESSION['product_stock'] = {$obj->product_stock};
Why does it error and how can I get round this?
<?php
session_start();
include_once("config.php");
// Current URL of the Page. cart_update.php redirects back to this URL
$current_url = urlencode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="keywords" content="">
<title>Product Page</title>
<?php include("includes/header-includes.php"); ?>
</head>
<body>
<?php include("includes/navigation.php"); ?>
<?php include("includes/basket-warning.php"); ?>
<!-- Products List Start -->
<?php
$ProductID = intval($_REQUEST['ProductID']);
$results = $mysqli->query("SELECT * FROM products where ProductID = '$ProductID';");
if($results) {
$_SESSION['product_stock'] = $obj->product_stock;
echo "STOCK: ". $_SESSION['product_stock'] ."";
$products_item = '<ul class="products">';
// Fetch results, set as object and output HTML
while($obj = $results->fetch_object()) {
$products_item .= <<< EOT
<li class="product">
<form method="post" action="cart_update.php">
<div class="product-content">
<h3>{$obj->ProductName} <strong>(STOCK: {$obj->product_stock}</strong>)</h3>
<div class="product-image" style="background: url({$obj->TypeImage}) no-repeat; background-size: 100%; min-height: 551.328px;">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="item active"><img src={$obj->TypeImage} class="img-responsive"></div>
<div class="item"><img src={$obj->AlternativeImagesOne} class="img-responsive"></div>
<div class="item"><img src={$obj->AlternativeImagesTwo} class="img-responsive"></div>
<div class="item"><img src={$obj->AlternativeImagesThree} class="img-responsive"></div>
</div>
</div>
</div>
<div class="product-content-cont">
<h4>{$obj->ProductName} - Overview</h4>
<p>{$obj->ProductDescription}</p>
</div>
</div>
<div class="like-what-you-see">
<fieldset>
<label>
<span>Price</span>
{$currency}{$obj->Price}
</label>
<label>
<input type="" size="1" maxlength="2" name="product_qty" value="1" class="form-control" />
</label>
</fieldset>
<input type="hidden" name="ProductCode" value="{$obj->ProductCode}" />
<input type="hidden" name="type" value="add" />
<input type="hidden" name="return_url" value="{$current_url}" />
<button type="submit" class="btn btn-warning">Add</button>
</div>
</form>
</li>
EOT;
}
$products_item .= '</ul>';
echo $products_item;
}
?>
<!-- Products List End -->
<?php include("includes/footer.php"); ?>
</body>
</html>
Your code:
$_SESSION['product_stock'] = $obj->product_stock;
echo "STOCK: ". $_SESSION['product_stock'] ."";
is outside the while loop. Therefore $obj is not yet defined.
Move the code above into the while loop like this
$products_item = '<ul class="products">';
// Fetch results, set as object and output HTML
while($obj = $results->fetch_object()) {
$_SESSION['product_stock'] = $obj->product_stock;
echo "STOCK: ". $_SESSION['product_stock'] ."";
....

Categories