Multiple tables display php MySQL - php

I am building a web page which has many albums. It will be displaying images when I click one of the albums.
ISSUE 1: The problem I am having now is that all images from different albums will be displayed when I click into only one of the album.
ISSUE 2: In the php file that is for after clicking the album. I want to display only one picture for only one product but my code seems not working correctly
t1.recordid = t2.categoryrecordid
t2.productrecordid = t3.productid
The structure of my MySQL table design:
Category:
Product:
Productimage:
The code for my album:
<div class="row">
<?php
$stmt = $DB_con->prepare('SELECT recordid, catcode,title,imgfile,catdesc FROM category ORDER BY recordid DESC');
$stmt->execute();
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
?>
<div class="col-xs-3">
<p><img src="./images/<?php echo $row['catcode']?>/<?php echo $row['imgfile']; ?>" class="img-rounded" width="190px" height="160px" /></p>
<p><a class="page-header" href="collectionGallery.php?cat= <?php echo $row['catcode']; ?>"><?php echo $row['title']; ?></a></p> <br/>
</div>
<?php
}
} else {
?>
<div class="col-xs-12">
<div class="alert alert-warning">
<span class="glyphicon glyphicon-info-sign"></span> No Data Found ...
</div>
</div>
<?php
}
?>
</div>
</div>
The code for after I clicking to album(display images of that album):
<div class="row">
<?php
$stmt = $DB_con->prepare('SELECT category.*, product.*, productimage.* FROM category JOIN product ON product.categoryrecordid=category.recordid JOIN productimage ON productimage.productid=product.productrecordid');
$stmt->execute();
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
?>
<div class="col-xs-3">
<p><img src="./images/<?php echo $row['catcode'].'/'. $row['imagefilename']; ?>" class="img-rounded" width="190px" height="160px" /></p>
<p><?php echo $row['productcode'].' Price:'.$row['price']; ?></a></p>
</div>
<?php
}
} else {
?>
<div class="col-xs-12">
<div class="alert alert-warning">
<span class="glyphicon glyphicon-info-sign"></span> No Data Found ...
</div>
</div>
<?php
}
?>
</div>

So There is a similar example of the code Which can help you to understand.
but this is in Mysqli Object oriented as i myself learning PDO. But i'm sure this will give to preety good understanding .
Here i'm using PHP Object oriented with Mysqli prepared Statement
1) Create a table in database with name : albums
2) Create a table in database with name : productimg
3) INDEX PAGE: index.php
<?php
include('products.php');
$newprod = new products();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP MYSQL SHOW ALBUMS</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<ul class="breadcrumb" style="width:100px;">
<li>d</li>
<li>d</li>
<li>d</li>
</ul>
<div class="row">
<?php $newprod->showAlbums(); ?>
</div>
</div>
</body>
</html>
4)this file displays album and product image : products.php
<?php
class products{
private $link;
function __construct(){
$this->link = new mysqli('localhost','root','admin','codexworld');
if(mysqli_connect_errno()){
die("connection failed".mysqli_connect_errno());
}
}
function showAlbums(){
$sql = $this->link->stmt_init();
if($sql->prepare("SELECT pname,album_name,product_code FROM albums")){
$sql->bind_result($pname,$albumname,$pcode);
$sql->execute();
while($sql->fetch()){
?>
<div class="col-md-4">
<a href="displproduct.php?pcode=<?php echo $pcode;?>"><img src="albumimages/<?php echo $albumname;?>" alt="<?php echo $pname; ?>" class="" style="width:200px;height:200px;">
<h4>ALBUM :<strong><?php echo $pname;?></strong></h4></a>
</div>
<?php
}
}
}
function showproducts($productcode){
$sql = $this->link->stmt_init();
if($sql->prepare("SELECT productname,productid,image FROM productimg WHERE productid = ?")){
$sql->bind_param('s',$productcode);
$sql->bind_result($pname,$pid,$img);
$sql->execute();
while($sql->fetch()){
?>
<div class="col-md-4">
<img src="productimg/<?php echo $img;?>" alt="<?php echo $pname; ?>" class="" style="width:200px;height:200px;">
<h4>Product Image :<strong><?php echo $pname;?></strong></h4>
</div>
<?php
}
}
}
}
?>
5)This file displays products : displproduct.php
<?php
include('products.php');
$newprod = new products();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP MYSQL SHOW ALBUMS</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<?php if(isset($_GET['pcode'])){
$productcode = $_GET['pcode'];
$newprod->showproducts($productcode);
}
?>
</div>
</div>
</body>
</html>

Related

PHP array isn't displaying in page

The list of notes should be displayed within the ul li spans, any reason as to why they aren't showing and instead the array is showing at the top of the page?
The database connection appears to be working perfectly fine, however the notes aren't showing within the spans. It also removes the 'you haven't added any notes text'
code
<?php
require_once 'app/init.php';
$notesQuery = $db->prepare("
SELECT ID, note
FROM notes
");
$notesQuery->execute();
$notes = $notesQuery->rowCount() ? $notesQuery : [];
foreach($notes as $note) {
print_r($note);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notes</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>myNotes</h1>
<nav>
Home
About
Contact
</nav>
</header>
<div class="container">
<form action="add.php" method="post">
<textarea name="note" placeholder="Insert a note..." autocomplete="off" required></textarea>
<input type="submit" value="Add" />
</form>
<div class="notes">
<h2>Notes</h2>
<?php if(!empty($notes)): ?>
<ul>
<?php foreach($notes as $note): ?>
<li>
<span><?php echo $note['note']; ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>you haven't added any notes yet.</p>
<?php endif; ?>
</div>
Working Code
<?php
require_once 'app/init.php';
$notesQuery = $db->prepare("
SELECT ID, note
FROM notes
");
$notesQuery->execute();
$notes = $notesQuery->rowCount() ? $notesQuery : [];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notes</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>myNotes</h1>
<nav>
Home
About
Contact
</nav>
</header>
<div class="container">
<form action="add.php" method="post">
<textarea name="note" placeholder="Insert a note..." autocomplete="off" required></textarea>
<input type="submit" value="Add" />
</form>
<div class="notes">
<h2>Notes</h2>
<?php if(!empty($notes)): ?>
<ul>
<?php foreach($notes as $note): ?>
<li>
<span><?php echo $note['note']; ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>you haven't added any notes yet.</p>
<?php endif; ?>
</div>
</div>
</body>
</html>
Feel free to use below as an example for your query.
// Your sql query
$sql = "SELECT ID, note FROM notes";
// Prepare your statement
$stmt = $db -> prepare($sql);
// Execute your prepared statement
$stmt -> execute();
// Retreive all rows
$notes = $stmt -> fetchAll();
// Check if array is not empty
if (!empty($notes)) {
//Spit out the array
print_r($notes);
}

I am very new to using PHP. I would like to create a comment box

I am very new to using PHP.I would like to create a comment box for the user.
1. How do you save the comment in the database
2. How do you see if there are any posts
3. How do you display all posts to current page.
I am using Wampsever/MySQL Workbench. May I have help? Thank you!
<?php
require_once("db_connection.php");
require_once("needed_functions.php");
if (isset($_POST['submit']))
{
//Take Comment
$comment_id = $_POST["comment"];
if ($message == "" )
{
$query = "INSERT INTO comment (";
$query .= "comment";
$query .= ") VALUES (";
$query .= " '{$comment}'";
$query .= ")";
//connect &select
$mysqli = new mysqli("localhost", "user_id");
//query
$result = $mysqli->query("INSERT INTO Comment () VALUES();")
//close
$result->close();
}
}
?>
<!DOCTYPE html>
<html>
<title>JAE Movies</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins">
<style>
body,h1,h2,h3,h4,h5 {font-family: "Poppins", sans-serif}
body {font-size:16px;}
.w3-half img{margin-bottom:-6px;margin-top:16px;opacity:0.8;cursor:pointer}
.w3-half img:hover{opacity:1}
</style>
<body style= "background-image:url(Roll.jpg)">
<!-- Sidebar/menu -->
<nav class="w3-sidebar w3-black w3-collapse w3-top w3-large w3-padding" style="z-index:3;width:300px;font-weight:bold;" id="mySidebar"><br>
Close Menu
<div class="w3-container">
<h3 class="w3-padding-64"><b>JAE<br>Movies</b></h3>
</div>
<div class="w3-bar-block">
Home
Sign In
Sign Up
Information
Customer Service
Administrator
</div>
</nav>
<!-- Top menu on small screens -->
<header class="w3-container w3-top w3-hide-large w3-light-blue w3-xlarge w3-padding">
?
<span>JAE Movies</span>
</header>
<!-- Overlay effect when opening sidebar on small screens -->
<div class="w3-overlay w3-hide-large" onclick="w3_close()" style="cursor:pointer" title="close side menu" id="myOverlay"></div>
<!--Start Inserting Page Content-->
<div class="w3-main" style="margin-left:340px;margin-right:40px">
<!-- Header -->
<div class="w3-container" style="margin-top:80px" id="userhome">
<h1 class="w3-jumbo w3-text-white"><b>Lion King</b></h1>
</div>
<!--Image-->
<div class="w3-half">
<img src="Images/LionKing.jpg" alt="LionKing" style="width:100%">
</div>
<!--Description-->
<div class="w3-half">
<p style="color:white";>Lion cub and future king Simba searches for his identity. His eagerness to please others and penchant for testing his boundaries sometimes gets him into trouble.</p></br>
</div>
<!--Buttons-->
<div>
<button type="submit">WATCH TRAILER!</button>
<button type="submit">WATCH MOVIE</button>
</div>
<!--Comments-->
<div>
<br>
<textarea rows="4" cols="50" name="comment" form="usrform">
Enter comment here...</textarea>
<form action=" " method="post" id="com">
<input type ="submit" name="submit" value="submit" class="texty" >
</form>
</div>
When using database connections in PHP make sure you do the following
//connect &select
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
//query
$result = $mysqli->query("INSERT INTO tbl_name () VALUES();") // Add the update comment here
//close
$result->close();
Always remember to :
connect
select
query
close
you'll then need to get all of the comments for the page using the same process but with the select process rather than insert.
<?php
require_once("db_connection.php");
require_once("needed_functions.php");
if(isset($_POST['submit'])){
$comment = mysql_escape_string($_POST['comment']);
$sql = "INSERT INTO comments (comment) VALUES ('$comment')";
if($res = $link->query($sql)){
}
else
{
echo "Error".$sql."<br>".$link->error;
}
}
?>
<!DOCTYPE html>
<html>
<title>Movies</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins">
<style>
body,h1,h2,h3,h4,h5 {font-family: "Poppins", sans-serif}
body {font-size:16px;}
.w3-half img{margin-bottom:-6px;margin-top:16px;opacity:0.8;cursor:pointer}
.w3-half img:hover{opacity:1}
</style>
<body>
<div class="container">
<img src="images/1.jpg" alt="loinKing" style="width:100%;height:300px;">
<br>
<br>
<form action="" method="post">
<div class="form-group">
<textarea type="text" name="comment" placeholder="Type Comment.." class="form-control"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" value="POST" class="btn btn-primary">
</div>
</form>
<!-- Left-aligned -->
<?php
//HERE SHOW OR DISPLAY THE COMMENTS
$q = "SELECT * FROM comments ORDER BY id DESC";
if($r->num_rows > 0){
while($row = $r->fetch_assoc()){
?>
<div class="media">
<div class="media-left">
<img src="images/img_avatar1.png" class="media-object" style="width:60px">
</div>
<div class="media-body">
<p>Date Posted : <?php echo $row['date'];?></p>
<p>Comments :<?php echo $row['comment'];?></p>
</div>
</div>
<?php
}
}
else
{
?>
<h4>No Comments Available</h4>
<?php
}
}
else
{
echo "Error".$sql."<br>".$link->error;
}
?>
</div>
</body>
So their is a code which save comment in database , displays in database and if comment is not posted or not available than it show NO COMMENT AVAILABE message.
I'M USING PHP AND MYSQLI HERE. Recommend not to use mysql as it is deprecated.
THE DATABASE TABLE IMAGE
CODE OUTPUT IMAGE
php file:
<?php
$link = new mysqli ('localhost','root','admin','demo1');
if($link->connect_error){
die ("Connection failed".$link->error);
}
if(isset($_POST['submit'])){
$comment = mysql_escape_string($_POST['comment']);
$sql = "INSERT INTO comments (comment) VALUES ('$comment')";
if($res = $link->query($sql)){
}
else
{
echo "Error".$sql."<br>".$link->error;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<img src="images/1.jpg" alt="loinKing" style="width:100%;height:300px;">
<br>
<br>
<form action="" method="post">
<div class="form-group">
<textarea type="text" name="comment" placeholder="Type Comment.." class="form-control"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" value="POST" class="btn btn-primary">
</div>
</form>
<!-- Left-aligned -->
<?php
//HERE SHOW OR DISPLAY THE COMMENTS
$q = "SELECT * FROM comments ORDER BY id DESC";
if($r = $link->query($q)){
if($r->num_rows > 0){
while($row = $r->fetch_assoc()){
?>
<div class="media">
<div class="media-left">
<img src="images/img_avatar1.png" class="media-object" style="width:60px">
</div>
<div class="media-body">
<p>Date Posted : <?php echo $row['date'];?></p>
<p>Comments :<?php echo $row['comment'];?></p>
</div>
</div>
<?php
}
}
else
{
?>
<h4>No Comments Available</h4>
<?php
}
}
else
{
echo "Error".$sql."<br>".$link->error;
}
?>
</div>
</body>
</html>
I hope all of your questions are answered. If not then reply to me....
Error For some reason I'm not finding:
Your screenshot is exactly what I am looking

I need simple code to make the entire webpage responsive (PHP code)

I have coded a working page but did not incorporate webpage responsiveness which I now need desperately! Is there a single line of code that will make the entire webpage responsive or do I need to make each element responsive?
I have tried to include the following code but to no success:
<meta name="viewport" content="width=device-width, initial-scale=1">
Here is the full code:
<?php
session_start();
$customer = $_SESSION['id_login'];
$order = $_SESSION['id_login'];
if (!isset($_SESSION['mysesi']) && !isset($_SESSION['mytype'])=='customer')
{
echo "<script>window.location.assign('LoginAndReg.php')</script>";
}
?>
<?php
include("admin/php/myFunctions.php");
#mysql_connect("localhost","root","") or die("Could not connect to database");
#mysql_select_db("bookstore") or die("Could not select database");
$displayImages = "";
if((isset($_GET['cat']) ? $_GET['cat'] : '') == "children")
$sqlSelProd = #mysql_query("select * from tblproduct where prod_cat = '$_GET[cat]'") or die(mysql_error());
else if((isset($_GET['cat']) ? $_GET['cat'] : '') == "Horror")
$sqlSelProd = #mysql_query("select * from tblproduct where prod_cat = '$_GET[cat]'") or die(mysql_error());
else if((isset($_GET['cat']) ? $_GET['cat'] : '') == "Thriller")
$sqlSelProd = #mysql_query("select * from tblproduct where prod_cat = '$_GET[cat]'") or die(mysql_error());
else
$sqlSelProd = #mysql_query("select * from tblproduct") or die(mysql_error());
if(mysql_num_rows($sqlSelProd) >= 1){
while($getProdInfo = mysql_fetch_array($sqlSelProd)){
$prodNo = $getProdInfo["prod_no"];
$prodID = $getProdInfo["prod_id"];
$prodName = $getProdInfo["prod_name"];
$prodPrice = $getProdInfo["prod_price"];
$displayImages .= '<div class="col col_14 product_gallery">
<img src="images/product/'.$prodNo.'.jpg" alt="Product '.$prodNo.'" width="170" height="150" />
<h3>'.$prodName.'</h3>
<p class="product_price">R '.$prodPrice.'</p>
Add to Cart</div>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- Responsive code -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Great selling Book Store</title>
<link href="css/slider.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<script language="javascript" type="text/javascript">
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
</head>
<body id="home">
<div id="main_wrapper">
<div id="main_header">
<div id="site_title"><h1>Book Store</h1></div>
<div id="header_right">
<div id="main_search">
<form action="products.php" method="get" name="search_form">
<input type="text" value="Search" name="keyword" onfocus="clearText(this)" onblur="clearText(this)" class="txt_field" />
<input type="submit" name="Search" value="" alt="Search" id="searchbutton" title="Search" class="sub_btn" />
<p>Welcome, <?php echo $_SESSION['mysesi'] ?></p> Log Out
<?php echo $customer ?>
<?php echo $order ?>
</form>
</div>
</div> <!-- END -->
</div> <!-- END of header -->
<div id="main_menu" class="ddsmoothmenu">
<ul>
<li>Home</li>
<li>Books</li>
<li>Cart</li>
<li>Checkout</li>
<li>About</li>
</ul>
<br style="clear: left" />
</div> <!-- end of menu -->
<div id="main_middle">
<img src="images/image_book.png" alt="Image 01" width="500" height="170" />
<h1>Great Selling book Store</h1>
<p>Great Selling book Store is a country wide book store.</p>
Browse All books
</div> <!-- END of middle -->
<div id="main_top"></div>
<div id="main">
<div id="sidebar">
<h3>Categories</h3>
<ul class="sidebar_menu">
<li>Children</li>
<li>Horror</li>
<li>Thriller</li>
</ul>
</div> <!-- END of sidebar -->
<div id="content">
<h2>Products</h2>
<?php echo $displayImages; ?>
</div> <!-- END of content -->
<div class="cleaner"></div>
</div> <!-- END of main -->
<div id="main_footer">
<div class="cleaner h40"></div>
<center>
Copyright © 2048 DigitalNinja
</center>
</div> <!-- END of footer -->
</div>
<script type='text/javascript' src='js/logging.js'></script>
</body>
</html>
I would recommend using bootstrap it's easy to use and it can make your page responsive by just adding some classes to your file.
I think this is what you've been looking for:
How to get just the responsive grid from Bootstrap 3?

PHP MySQL: boolean Value works on local server but returns empty on live server?

I have a boolean ( bit ) value stored in my database. The problem is when I run the PHP script on local server I get the value either 0 or 1 depending upon the value stored in Database against the id using mySQL query. However the same script on live server returns absolutely nothing neither 0 nor 1. My variable remains empty. Any possible explanation. The value of $status remains empty on live server but works on local
<?php
session_start();
require_once __DIR__ . '/connect.php';
if (!$_SESSION['loginadmin'])
{
header("location:error.php");
}
else
{
?>
<!DOCTYPE html>
<!---->
<html lang="en">
<head>
<title></title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,600,700' rel='stylesheet' type='text/css'>
<link href="bootstrapTheme.css" rel="stylesheet">
<!-- Owl Carousel Assets -->
<link href="owl.carousel.css" rel="stylesheet">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script src="js/Forum_400.font.js"></script>
<script src="js/script.js"></script>
<!--Login Button scripts-->
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<script src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/megamenu.js"></script>
<script src="js/menu_jquery.js"></script>
<!--**********-->
</head>
<body id="page1">
<div class="body6">
<div class="body1">
<div class="body5">
<div class="main">
<!-- header -->
<header>
<h1><img src="images/logo.png" / ></div></h1>
<nav>
<ul id="top_nav">
<li><img src="images/icon_1.gif" alt="">HOME</li>
<li class="login" >
<div id="loginContainer"><img src="images/icon_2.png" alt=""><span>SIGN OUT</span>
</div>
</li>
<li class="end"><img src="images/icon_3.gif" alt="">CONTACT US</li>
</ul>
</nav>
</header>
<!---->
<div class="contact-bg">
<div class="container">
<div class="contact-us">
<div class="contact_right">
<div class="contact-form">
<h3 class="style">ADMINISTRATOR PANEL</h3>
<form method="post" action="status.php">
<div>
<span><label>Membership ID</label></span>
<span><input name="membership" type="text" class="textbox"></span>
</div>
<div>
<input name="submit" type="submit" value="Check">
</div>
<?php
if(isset($_POST['submit']))
{
$_SESSION['id']=$_POST['membership'];
$membership=$_POST['membership'];
$first_id=0;
if(($membership=="" && $membership==NULL))
{
echo "<script type='text/javascript'>alert('We are sorry ! But you have missed the field');</script>";
}
else
{
$query0 = "LOCK TABLES card WRITE";
$result0 = mysql_query($query0);
$query1 = "LOCK TABLES card as card1 READ";
$result1 = mysql_query($query0);
if( $result0 && $result1 )
{
$query = "SELECT status FROM card WHERE id='$membership'";
$result = mysql_query($query);
$numberofrows = mysql_num_rows ($result);
$query_ = "UNLOCK TABLES";
mysql_query($query_);
if($numberofrows)
{
$row=mysql_fetch_row($result,MYSQL_ASSOC);
$status = $row['status'];
$sql = "SELECT name FROM customers WHERE mem_id='$membership'";
$res = mysql_query($sql);
$numberofrows = mysql_num_rows($res);
if (!$status)
{
?>
<div>
<?php
if ($numberofrows)
{
$row=mysql_fetch_row($res,MYSQL_ASSOC);
$memname = $row['name'];
echo "<span><label>Name: $memname $status</label></span>";
}
else
echo "<span><label>No User Against this Membership ID</label></span>";
?>
<span><label>Current Status: Not Activated</label></span>
</div>
<div>
<input type="submit" name="activate" value="Activate">
</div>
<?php
}
else
{
?>
<div>
<?php if ($numberofrows)
{
$row=mysql_fetch_row($res,MYSQL_ASSOC);
$memname = $row['name'];
echo "<span><label>Name: $memname $status</label></span>";
}
else
echo "<span><label>No User Against this Membership ID</label></span>";
?>
</div>
<div>
<span><label>Current Status: Activated </label></span>
<input type="submit" name="deactivate" value="Deactivate">
</div>
<?php
}
}
else
echo "<script type='text/javascript'>alert('No such membership id');</script>";
$query_ = "UNLOCK TABLES";
mysql_query($query_);
}
else
die ("Database access failed: " . mysql_error());
}
// }
}
if(isset($_POST['activate']))
{
$query="UPDATE card SET status=TRUE WHERE id='$_SESSION[id]'";
$result = mysql_query($query);
if($result)
echo "<script type='text/javascript'>alert('membership id: $_SESSION[id] Status Changed to ACTIVATED');</script>";
}
if(isset($_POST['deactivate']))
{
$query="UPDATE card SET status=FALSE WHERE id='$_SESSION[id]'";
$result = mysql_query($query);
if($result)
echo "<script type='text/javascript'>alert('membership id: $_SESSION[id] Status Changed to Deactivated');</script>";
}
}
?>
</form>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<!---->
<footer>
<div id="wrapper">
<section class="col1 pad_left1">
<div id="end">
<div id="end_menu">
Home . About . Contact . Terms of Use . Sponsors
</div>
<div id="social">
<ul id="icons">
<li><img src="images/icon1.gif" alt=""></li>
<li><img src="images/icon2.gif" alt=""></li>
<li><img src="images/icon3.gif" alt=""></li>
<li><img src="images/icon4.gif" alt=""></li>
<li><img src="images/icon5.gif" alt=""></li>
</ul>
</div>
<div id="sponsors">
<img src="images/g1.png" width="150px" height="100px"/>
<img src="images/g2.png" width="150px" height="100px"/>
</div>
<div id="subscribe">
<span class="toto">NEWSLETTER</span><br>
<input type="text" id="inputs" placeholder="e-mail" />
<br>
<div id="sub_but">
SUBSCRIBE
</div>
</div>
</div>
</section>
</div>
</footer>
</body>
</html>
I had the status value as BIT on my local server which was working fine on the local server however it was returning empty on live server.
FIX ON LIVE SERVER: Changed the status column type from BIT to TINYINT on live server.

trouble getting content from my database to a form in php

I have been follwing a series of tutorials over at [thedigitalcraft.com][1] building my first ever dynamic website. I recently followed his 15th, and thought I followed along greatly, but for some reason the content that should be showing up isn't when I run the page. No errors, its almost like one of my sql statements is wrong, or it can't connect to my phpMyAdmin database.I'm building a user interface for editing each of the pages, a control panel. I'm running on XAMPP localhost btw, working in dreamweaver. Why is my content not showing up in the form? I know that I am connected to the database.. I've pasted my code from my pages.php and index.php
1. pages.php:
<?php ## Page Manager ?>
<h2>Page Manager</h2>
<div class="col sidebar">
<ul>
<?php
$q = "SELECT * FROM pages ORDER BY name ASC";
$r = mysqli_query($dbc, $q);
if ($r)
{
while($link = mysqli_fetch_assoc($r))
{
echo '<li>'.$link['name'].'</li>';
}
}
?>
</ul>
</div>
<div class="col editor">
<?php if (isset($_GET['id'])) {
$q = "SELECT * FROM pages WHERE id = '$_GET(id)' LIMIT 1";
// the database connection, our query
$r = mysqli_query($dbc, $q);
$opened = mysqli_fetch_assoc($r);
?>
<form action="#" method="post">
<p><label>Page title: </label><input type="text" size="30" name="title" value="<?php echo $opened['title']?>"></p>
<p><label>Page name:</label> <input type="text" size="30" name="name" value="<?php echo $opened['name']?>"></p>
<label>Page body:</label><br>
<textarea name="body" cols="30" rows="8"><?php echo $opened['body'] ?></textarea>
</form>
<?php } ?>
</div>
index.php:
<?php
error_reporting(0);
// Setup document:
include('config/setup.php');
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title><?php //echo $page_title; ?>JakeForDesign - Admin Panel</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>
<div class="wrap_overall">
<div class="header"> <?php head(); ?> </div>
<div class="nav_main"> <?php nav_main(); ?> </div>
<div class="content"> <?php include('content/'.$pg.'.php'); ?> </div>
<div class="footer"> <?php footer(); ?> </div>
</div>
</body>
</html>
2. index.php:
<?php
error_reporting(0);
// Setup document:
include('config/setup.php');
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title><?php //echo $page_title; ?>JakeForDesign - Admin Panel</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>
<div class="wrap_overall">
<div class="header"> <?php head(); ?> </div>
<div class="nav_main"> <?php nav_main(); ?> </div>
<div class="content"> <?php include('content/'.$pg.'.php'); ?> </div>
<div class="footer"> <?php footer(); ?> </div>
</div>
</body>
</html>
3. setup.php(for connection to database)
<?php
## Setup Document
// host(or location of the database), username, //password, database name
$dbc = #mysqli_connect('localhost', 'root', 'password', 'database') OR die ('Could not connect to the database because: '. mysqli_connect_error() );
include('Functions/sandbox.php');
include('Functions/template.php');
if ($_GET['page'] == '')
{
$pg = 'home';
}
else
{
$pg = $_GET['page'];
}
$page_title = get_page_title($dbc, $pg);
?>
$q = "SELECT * FROM pages WHERE id = '$_GET(id)' LIMIT 1";
This is wrong
$q = "SELECT * FROM pages WHERE id = '" . $_GET['id'] . "' LIMIT 1";
This is good
Don't forget to secure it with intval() if it's a numeric value!

Categories