PHP input inside a while loop - php

I have wanted to loop a set of inputs according to the database inside a while loop. But I could not define the input name correctly which ended up in, the submitted POST being empty, when checked with var_dump($_POST).
<body background="images/tl.jpg">
<div id="container">
<?php include "mysql/head.php" ?>
<div id="main">
<p align="left"> Your Staff ID : <?php echo $_SESSION['u_username'] ?></p>
<p align="left"> Your E-Mail : <?php echo $_SESSION['u_acemail']; ?></p>
<form id="sub-form" action="mysql/save_result.php/">
<center>
<table align="center" width=80% border="2" cellpadding="1" cellspacing="1">
<tr>
<th>Student Index No</th>
<th>Result</th>
<?php
include "mysql/dbconnect.php";
$batchno = $_POST['batch'] ;
$year = $_POST['y'];
$semester = $_POST['s'];
$tname = $batchno."_".$year."_".$semester;
$subcode = $_POST['subject'];
$_SESSION['batchno'] = $_POST['batch'];
$_SESSION['year'] = $_POST['y'];
$_SESSION['semester'] = $_POST['s'];
$_SESSION['tname'] = $batchno."_".$year."_".$semester;
$_SESSION['subcode'] = $_POST['subject'];
echo "Results Table Name : ".$tname;
echo "<br><br>";
echo "<b>Subject Code : ".$subcode."   Batch : ".$batchno."   Year : ".$year."   Semester : ".$semester."</b><br>";
$sql = "SELECT stindex,id FROM $tname WHERE stindex NOT LIKE '%stindex%' ORDER BY id;";
$result = mysqli_query($conn, $sql);
$check = mysqli_num_rows($result);
while ($row=mysqli_fetch_assoc($result)) {
$resultid = "result_".$row['id'];
echo "<tr><td align='center'>".$row['stindex']."</td><td align='center'><input type='text' name='$resultid'>".$resultid."</td></tr>";
}
echo "</table><br>";
echo "<b>Number of Rows Fetched : ".$check."</b><br><br>";
?>
Submit Results
`

Related

link not reading underscore and text after it

I have made one site which get the name from the database and display values from the data base.
Some of my database values having underscore (_) like abc_xyz.dll
But on get method it return only abc not the whole value abc_xyz.dll (skips the underscore and values after it)
Here is two links one having vales without underscore which works http://windllfiles.com/dlldata/SDACQ32MP.dll
Here is another link which have underscore which is not working
http://windllfiles.com/dlldata/ETA_USB.dll
Here is the code
('include/config.php'); $character = '';
if(isset($_GET["character"])) {
$character = $_GET["character"];
if($character=='09'){
$query = "SELECT * FROM tbl_student WHERE student_name LIKE '0%'
or student_name LIKE '1%'
or student_name LIKE '2%'
or student_name LIKE '3%'
or student_name LIKE '4%'
or student_name LIKE '5%'
or student_name LIKE '6%'
or student_name LIKE '7%'
or student_name LIKE '8%'
or student_name LIKE '9%'
";
}else{
$character = preg_replace('#[^a-z]#i', '', $character);
$query = "SELECT * FROM tbl_student WHERE student_name LIKE '$character%'";
}
} else {
$query = "SELECT * FROM tbl_student ORDER BY RAND () LIMIT 30"; } $result = mysqli_query($connect, $query); ?> <?php
require 'include/header.php';
?>
Get Your DLL
file
<?php
$character = range('A', 'Z');
echo ' <ul class="pagination alphabet_pagination">';
echo '<li>0-9</li>';
foreach($character as $alphabet)
{
echo '<li>'.$alphabet.'</li>';
}
echo '</ul>';
?>
</div>
<table class="table table-bordered">
<tr>
<th width="auto">All DLL Files</th>
</tr>
<?php
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$name=$row["student_name"]
?>
<tr>
<td><?php echo ''.$name.'';?></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="3" align="center">Data not Found</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<p> <?php include ('include/ads.php'); ?></p> </div></div>
<div class="col-sm-3">
<?php include('include/right.php');?>
Here is the data file where I am using get method
'include/header.php'; $name = $_GET['name']; ?>
class="container-fluid"> Are you missing
File? <div
class="list-group-item list-group-item-action>
Download '.$name.'
File';?>
<?php
$query = "SELECT * FROM tbl_student WHERE student_name='$name'";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$id=$row["student_phone"]
?>
<li class='list-group-item'><p align="justify"><?php echo $id;?></p></li>
<?php
}
}
?>
<br/> <?php $filename = "file/".$name; $filesize = filesize($filename); $filesize =round($filesize/1024, 2);
echo "File Information:"; echo ""; echo "File
Size:  ".$filesize.''; $md5file =
md5_file($filename); echo "MD5 file
sum:  ".strtoupper($md5file).''; $sha1file =
sha1_file($filename); echo "SHA1 file
sum:  ".strtoupper($sha1file).''; ?> Download '.$name.'
File';?> Dll Missing Error Message:

Search doesn't work when there's an apostrophe

I'm trying to make an OPAC website. Everything works fine since it's mostly just selecting from the database and displaying it. I noticed that when the book title i'm trying to search has an apostrophe, it displays nothing. If the book title doesn't contain any apostrophe it all works. I'm using mysql for my database.
<!-- {this is how i connect my datatbase} -->
<?php
include 'includes/dbh.inc.php';
?>
<!DOCTYPE <!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div id= "wrapper">
<img class="cpclogo" src="cpc.png">
<header>
<h1 class="CPC"> Colegio de la Purisima Concepcion </h1>
<h3 class="Saying"> The School of the Archdiocese of Capiz </h3>
</header>
</div>
header.php file
<?php
$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "library";
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
?>
search.php file
<?php
include 'header.php'
?>
<h1 class="searchresults">Search Results:</h1>
<div class="search-container">
<?php
if (isset($_POST['submit']))
{
$search = mysqli_real_escape_string($conn, $_POST['search']);
$sql = "SELECT * FROM book WHERE Book_Title LIKE '%$search%' OR Author LIKE '%$search%' OR Call_Number LIKE '%$search%' OR Book_ID LIKE '%$search%'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
$search = mysqli_real_escape_string($conn, $_POST['search']);
echo "<h3 class='resultcount'>There are ".$queryResult." results!</h3>";
if ($queryResult > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
echo "<a href='article.php?Book_Title=".$row['Book_Title']."&id=".$row['Book_ID']."&call=".$row['Call_Number']."' class= 'search-ref'><div class=search-box>
<tr><td>".$row['Book_Title']." </td>
<td>/ ".$row['Author']."</td>
<p>".$row['Call_Number']."</p>
</div></tr><br>";
}
}
}
?>
<input class="backbtn" type="button" value="Back" onclick="history.back(-1)" />
</div>
article.php file
<?php
include 'header.php';
?>
<div class="article-container">
<?php
//Declairing Variables
$Author = "Authors: ";
$Edition = "Edition: ";
$Subject ="Subject: ";
$Summary = "Summary: ";
$Notes = "Notes: ";
$Publisher ="Publisher: ";
$Phys_Desc ="Physical Description: ";
$Call_Number ="Call Number: ";
$Book_ID = "Book ID: ";
$Title= mysqli_real_escape_string($conn, $_GET['Book_Title']);
$sql ="SELECT * FROM book WHERE Book_Title='$Title'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
if ($queryResult > 0)
while ($row = mysqli_fetch_assoc($result))
{
echo "<div class= 'article-box'>
<h3 class='booktitle'><b>".$row['Book_Title']."</h3></b>
<p><b>$Author</b>".$row['Author']."</p>
<p><b>$Edition</b>".$row['Edition']."</p>
<p><b>$Subject</b>".$row['Subject']."</p>
<p><b>$Summary</b>".$row['Summary']."</p>
<p><b>$Notes</b>".$row['Notes']."</p>
<p><b>$Publisher</b>".$row['Publisher']."</p>
<p><b>$Phys_Desc</b>".$row['Phys_Desc']."</p>
<p><b>$Call_Number</b>".$row['Call_Number']."</p>
</div>";
}
?>
<div class="btns">
<input class="backbtn" type="button" value="Back" onclick="history.back(-1)" />
<button type="submit" id="copybtn" class= "copybtn">Copies</button>
</div>
<!-- POP-UP WINDOW -->
<div class="bg-modal">
<div class="modal-content">
<div class="close"></div>
<table class = "table">
<tr>
<th>Copy</th>
<th>Status</th>
<th>Accession Number</th>
<th>Call Number</th>
<th>Location</th>
<th>Format</th>
<th>Cost</th>
<th>Vendor</th>
<th>Fund</th>
<th>Date Acquired</th>
</tr>
<?php
$id = mysqli_real_escape_string($conn, $_GET['id']);
$call = mysqli_real_escape_string($conn, $_GET['call']);
$sql = "SELECT Copy, Status, Accession_Number, l.Location, f.Format, Cost, Vendor, u.Fund, Date_Acq
FROM copy c
INNER JOIN location l ON l.Location_Acronym = c.Location
INNER JOIN format f ON f.Format_ID = c.Format
INNER JOIN fund u ON u.Fund_ID = c.Fund
WHERE Book_ID='$id'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
if ($queryResult > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
echo "
<tr><td>".$row['Copy']."</td>
<td>".$row['Status']."</td>
<td>".$row['Accession_Number']."</td>
<td>".$call."</td>
<td>".$row['Location']."</td>
<td>".$row['Format']."</td>
<td>₱".$row['Cost']."</td>
<td>".$row['Vendor']."</td>
<td>".$row['Fund']."</td>
<td>".$row['Date_Acq']."</td></tr>
";
}
}
?>
</table>
</div>
</div>
<script src="popup.js"></script>
</body>
</html>
copies.php file
<?php
include 'header.php'
?>
<h1 class="copyresults">Copy Results:</h1>
<div class="article-container">
<table class = "table">
<tr>
<th>Barcode</th>
<th>Copy</th>
<th>Status</th>
<th>Location</th>
<th>Format</th>
<th>Vendor</th>
</tr>
<?php
{
$id = mysqli_real_escape_string($conn, $_GET['id']);
$sql = "SELECT * FROM copy WHERE Book_ID='$id'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
if ($queryResult > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
echo "
<tr><td>".$row['Barcode']."</td>
<td>".$row['Copy']."</td>
<td>".$row['Status']."</td>
<td>".$row['Location']."</td>
<td>".$row['Format']."</td>
<td>".$row['Vendor']."</td></tr>
";
}
}
}
?>
</table>
I reckon there is something fishy about this:
echo "<a href='article.php?Book_Title=".$row['Book_Title']."&id=".$row['Book_ID']."&call=".$row['Call_Number']."' class= 'search-ref'><div class=search-box>...
See that your href value is wrapped in single quotes? When you click on that link, the entire querystring will be truncated at the first single quote and this is the likely culprit.
Use: urlencode() on $row['Book_Title'] if it is the only trouble maker.
echo "<a href='article.php?Book_Title=" . urlencode($row['Book_Title']) . "&id=" . $row['Book_ID'] . "&call=".$row['Call_Number'] . "' class= 'search-ref'><div class=search-box>...
Or this might make your code more attractive (certainly more robust):
$data = [
'Book_Title' => $row['Book_Title'],
'id' => $row['Book_ID'],
'call' => $row['Call_Number']
];
echo "<a href='article.php?" . http_build_query($data) . "' class='search-ref'><div class=search-box>...

applying search or filter to table with pagination

hello kind sirs can you help me with this code. What i try to do is when i type something in the search box, ex. pending it will show the 5 pending reservation per page(5 rows of pending reservation). but when i try it, it shows all the pending reservation which is more than 10.
here is the image
i try something like this.. but it shows nothing
$query = "SELECT * FROM reservations WHERE CONCAT(firstname, lastname, reservationstatus)LIKE '%".$valueToSearch."%' LIMIT " . $this_page_first_result . ',' . $results_per_page";
Here is the whole code
<?php
error_reporting(E_ALL & ~E_NOTICE);
error_reporting(E_ERROR | E_PARSE);
session_start();
?>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "srdatabase";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$results_per_page = 5;
$select= "SELECT * FROM reservations";
$result = mysqli_query($conn, $select);
$number_of_results = mysqli_num_rows($result);
if(!isset($_GET['page']))
{
$page = 1;
}
else
{
$page = $_GET['page'];
}
$this_page_first_result = ($page-1)*$results_per_page;
$sql = "SELECT * FROM reservations LIMIT " . $this_page_first_result . ',' . $results_per_page;
$result = mysqli_query($conn, $sql);
$number_of_pages = ceil($number_of_results/$results_per_page);
?>
<div id="paging-div">
<?php
for($page=1;$page<=$number_of_pages;$page++)
{
echo '<a id="pagingLink" href="adminControl.php?page=' . $page . '">' . $page . '</a>';
}
?>
<?php
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
$query = "SELECT * FROM reservations WHERE CONCAT(firstname, lastname, reservationstatus)LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else
{
$query = "SELECT * FROM reservations";
$search_result = filterTable($query);
}
function filterTable($query)
{
$conn = mysqli_connect("localhost", "root", "", "srdatabase");
$filter_Result = mysqli_query($conn, $query);
return $filter_Result;
}
?>
</div>
<!DOCTYPE html>
<html>
<head>
<title>Admin Control</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="topnav" id="myTopnav">
Home
Speakers
About
Contact
Reservation
Sign Out
<?php echo $_SESSION['firstname']; ?>
Sign Up
Sign In
Admin control
☰
</div>
<br>
<br>
<br>
<br>
<h4 style="padding-left:10px; text-align:center;">Reservation List</h4>
<hr>
<form action="adminControl.php" method="POST">
<input type="text" name="valueToSearch" placeholder="type a value">
<input type="submit" name="search" value="Filter">
</form>
<br>
<br>
<div style="overflow-x:auto;">
<table class="reservations-table">
<tr>
<th class="thFirstName">First Name</th>
<th class="thLastName">Last Name</th>
<th class="thEmailAddress">Email Address</th>
<th class="thContactNumber">Contact Number</th>
<th class="thSpeaker">Speaker</th>
<th class="thTopic">Topic</th>
<th class="thLocation">Location</th>
<th class="thAudience">Audience</th>
<th class="thCount">Count</th>
<th class="thTime">Time</th>
<th class="thDate">Date</th>
<th class="thAction">Reservation Date</th>
<th class="thAction">Status</th>
<th class="thAction">Action</th>
<th class="thAction">Action</th>
</tr>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['firstname'];?></td>
<td><?php echo $row['lastname'];?></td>
<td><?php echo $row['emailaddress'];?></td>
<td><?php echo $row['contactnumber'];?></td>
<td><?php echo $row['speaker'];?></td>
<td><?php echo $row['topic'];?></td>
<td><?php echo $row['location'];?></td>
<td><?php echo $row['audience'];?></td>
<td><?php echo $row['count'];?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['date'];?></td>
<td><?php echo $row['reservationdate'];?></td>
<td><?php echo $row['reservationstatus'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
</div>
<?php
$epr='';
$msg='';
if(isset($_GET['epr']))
$epr=$_GET['epr'];
if($epr=='delete')
{
$id=$_GET['id'];
$delete=mysqli_query($conn, "DELETE FROM reservations WHERE id=$id");
if($delete)
header('location:adminControl.php');
else
$msg='Error :'.mysqli_error();
}
?>
<?php
$epr='';
$msg='';
if(isset($_GET['epr']))
$epr=$_GET['epr'];
if($epr=='approve')
{
$id=$_GET['id'];
$approve=mysqli_query($conn, "UPDATE reservations SET reservationstatus='approved' WHERE id=$id");
header('location:adminControl.php');
}
?>
<script>
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>
<script>
function ifAdmin()
{
document.getElementById("signIn").style.display = "none";
document.getElementById("signUp").style.display = "none";
document.getElementById("signOut").style.display = "block";
document.getElementById("adminControl").style.display = "block";
}
</script>
<script>
function ifNotAdmin()
{
document.getElementById("signIn").style.display = "none";
document.getElementById("signUp").style.display = "none";
document.getElementById("signOut").style.display = "block";
document.getElementById("adminControl").style.display = "none";
}
</script>
<script>
function ifNotLogin()
{
document.getElementById("user").style.display = "none";
document.getElementById("signOut").style.display = "none";
document.getElementById("adminControl").style.display = "none";
}
</script>
<?php
if (isset($_SESSION['signedIn']) && $_SESSION['signedIn'] == true)
//if login
{
if($_SESSION['type'] == 1)
{
echo "<script type='text/javascript'>ifAdmin();</script>";
}
elseif($_SESSION['type'] == 0)
{
echo "<script type='text/javascript'>ifNotAdmin();</script>";
}
}
//if not login
else
{
echo "<script type='text/javascript'>ifNotLogin();</script>";
}
?>
<div id="footer" class="push">Copyright 2017</div>
</body>
</html>
... when i try it, it shows all the pending reservation which is more than 10.
That's because when you hit 2nd, 3rd, ... pages(after navigating from the 1st page), the $_POST array would be empty i.e. $_POST['search'] won't be set, and that's why else{...} part of the code will get executed every time you navigate to 2nd, 3rd, ... pages. Since you're not sending any sensitive data with the form, use GET instead of POST in the method attribute of the form, like this:
<form action="..." method="get">
and get the user inputted data like this:
if (isset($_GET['search'])) {
$valueToSearch = $_GET['valueToSearch'];
...
Subsequently, you need to attach that search query in each of your pagination links, so that the search query would be available when you hop from page to page.
// your code
<?php
for($page=1;$page<=$number_of_pages;$page++)
{
echo "<a id='pagingLink' href='adminControl.php?page=" . $page . "&valueToSearch=". urlencode($_GET['valueToSearch']) ."&search'>" . $page . "</a>";
}
?>
// your code

trouble in using $_SESSION in PHP

I am facing trouble in using $_SESSION when I open viewrcd.php file it opens directly instead of opening admin_login.php page. (b'coz to view this page "viewrcd.php" admin logged in is must...)
admin_login.php
<?php
session_start();
require 'testdbcheking.php';
if(isset($_POST['login']))
{
$a_name = $_POST['admin_name1'];
$a_pword = $_POST['admin_password1'];
$_SESSION['admin_name1'] = 'admin_name1';
if(!empty($_POST['admin_name1']) && !empty($_POST['admin_password1']))
{
$query10="SELECT * FROM admin_login WHERE admin_name = '$a_name' AND admin_password = '$a_pword'";
if($query10_run = mysql_query($query10))
{
$query10_num_rows = mysql_num_rows($query10_run);
if($query10_num_rows == 0)
{
echo 'you are not an admin';
}
if($query10_num_rows == 1)
{
echo "<script>window.open('viewrcd.php?logged= Admin logged in Success','_self')</script>";
}
}
}
else
{
echo 'provide both......';
}
}
?>
<html>
<title>Admin Login Page</title>
<body>
<form action = 'admin_login.php' method = 'POST' >
<table align = 'center' border = '3' bgcolor = 'gray'>
<tr ><td colspan = 8 align ='center'>Admin Login FORM</td></tr>
<tr>
<td>Admin Username:</td>
<td><input type = 'text' name ='admin_name1'></td>
</tr>
<tr>
<td>Admin Password:</td>
<td><input type = 'password' name ='admin_password1'></td>
</tr>
<tr> <td colspan = '4' align ='center'>
<input type = 'submit' name='login' value = 'Login'>
</td>
</tr>
</table>
</form>
</body>
</html>
viewrcd.php
<?php
session_start();
require 'testdbcheking.php';
if($_SESSION['admin_name1'])
{
//echo 'qqq';
header('location :admin_login.php');
//header('location : viewrcd.php');
}
?>
<a href= 'admin_logout.php'>ADMIN_logout </a>
<html>
<head><center><h1>Viewing all the rocords</center></h1><head/>
<body>
<table align = center border = 1>
<tr align = 'center'>
<th>SR.NO.</th>
<th>Username</th>
<th>Firstname</th>
<th>Surname</th>
<th>Delete</th>
<th>Edit</th>
<th>Details</th>
</tr>
<?php
$query4 = 'SELECT * FROM users';
$query4_run = mysql_query($query4);
while (#$data_row = mysql_fetch_array($query4_run))
{
$u_id = $data_row [0];
$u_name = $data_row[1];
$f_name = $data_row [3];
$s_name = $data_row [4];
?>
<tr align = 'center'>
<td> <?php echo #$u_id;?></td>
<td> <?php echo #$u_name;?></td>
<td> <?php echo #$f_name;?></td>
<td> <?php echo #$s_name;?></td>
<td><a href = 'delete.php?del=<?php echo $u_id ;?>'>Delete</a></td>
<td><a href = 'edit.php?edit=<?php echo $u_id ;?>'>Edit</a></td>
<td><a href = 'viewrcd.php?details=<?php echo $u_id ;?>'>Details</a></td>
<?php } ?>
</tr>
</table>
<?php
$record_details = #$_GET['details'];
$query8 = "SELECT * FROM users WHERE id = '$record_details'";
$query_run8 = mysql_query($query8);
while($query_run8_row = mysql_fetch_array($query_run8))
{
$d_name = $query_run8_row[1];
$d_firstname = $query_run8_row[3];
$d_surname = $query_run8_row[4];
?>
<table align = center border = 1>
</tr>
<tr ><td colspan = 10 align = center> your details are here </td></tr>
<tr align = center>
<td><?php echo $d_name ; ?></td>
<td><?php echo $d_firstname ; ?></td>
<td><?php echo $d_surname ; ?></td>
</tr>
<?php } ?>
</table>
<font bgcolor = 'green' align = 'center' size = '6'>
<?php echo #$_GET['deleted'];?>
</font>
<font color = 'green' align = 'center' size = '6'>
<?php echo #$_GET['updated'];?>
<?php echo #$_GET['logged'];?>
</font><br><br><br><br><br>
<form action = "viewrcd.php" method = "get">
Search record: <input type = "text" name = "search" >
<input type = "submit" name = "submit" value ="Find Record">
</form>
<?php
if (isset($_GET['search']))
{
$search_record = $_GET['search'];
$query9 = "SELECT * FROM users WHERE id = '$search_record' OR firstname ='$search_record' ";
$query9_run = mysql_query($query9);
while($query9_run_row = mysql_fetch_assoc($query9_run))
{
//$find_id = $query9_run_row['id'];
$find_username = $query9_run_row['username'];
$find_firstname = $query9_run_row['firstname'];
$find_surname = $query9_run_row['surname'];
?>
<br><br><br>
<table border = '2' bgcolor ='green' align ='center'>
<tr>
<th>Username</th>
<th>Firstname</th>
<th>Surname</th>
<tr>
<td><?php echo $find_username ; ?></td>
<td><?php echo $find_firstname ; ?></td>
<td><?php echo $find_surname ; ?></td>
</tr>
</table>
<?php } } ?>
</body>
</html>
admin_logout.php
<?php
require 'testdbcheking.php';
session_start();
session_destroy();
header('Location: admin_login.php');
?>
replace
if($_SESSION['admin_name1'])
with
if(!$_SESSION['admin_name1'])
in viewrcd.php
replace
if($_SESSION['admin_name1'])
with
if(empty($_SESSION['admin_name1']))
i have updated my answer ..try now
admin_login.php
<?php
session_start();
require 'testdbcheking.php';
global $a_name;
if(isset($_POST['login']))
{
$a_name = $_POST['admin_name1'];
$a_pword = $_POST['admin_password1'];
if(!empty($_POST['admin_name1']) && !empty($_POST['admin_password1']))
{
$query10="SELECT * FROM admin_login WHERE admin_name = '$a_name' AND admin_password = '$a_pword'";
if($query10_run = mysql_query($query10))
{
$query10_num_rows = mysql_num_rows($query10_run);
if($query10_num_rows == 0)
{
echo 'you are not AN admin';
}
if($query10_num_rows == 1)
{
$admin_id = mysql_result($query10_run,0,'admin_name');
$_SESSION['admin_id'] = $admin_id;
echo "<script>window.open('viewrcd.php?logged= Admin logged in Success','_self')</script>";
}
}
}
else
{
echo 'provide both......';
}
}
?>
<br><br><br>
<?php //echo $a_name ; ?>
<html>
<title>Admin Login Page</title>
<body>
<form action = 'admin_login.php' method = 'POST' >
<table align = 'center' border = '3' bgcolor = 'gray'>
<tr ><td colspan = 8 align ='center'>Admin Login FORM</td></tr>
<tr>
<td>Admin Username:</td>
<td><input type = 'text' name ='admin_name1'></td>
</tr>
<tr>
<td>Admin Password:</td>
<td><input type = 'password' name ='admin_password1'></td>
</tr>
<tr> <td colspan = '4' align ='center'>
<input type = 'submit' name='login' value = 'Login'>
</td>
</tr>
</table>
</form>
</body>
</html>
viewrcd.php
<?php
session_start();
require 'testdbcheking.php';
if(!isset($_SESSION['admin_id']))
{
?>
First Login here..
<?php
}
else
{
?>
<a href= 'admin_logout.php'>ADMIN_logout </a>
<html>
<head><center><h1>Viewing all the rocords</center></h1><head/>
<body>
<table align = center border = 1>
<tr align = 'center'>
<th>SR.NO.</th>
<th>Username</th>
<th>Firstname</th>
<th>Surname</th>
<th>Delete</th>
<th>Edit</th>
<th>Details</th>
</tr>
<?php
$query4 = 'SELECT * FROM users';
$query4_run = mysql_query($query4);
while (#$data_row = mysql_fetch_array($query4_run))
{
$u_id = $data_row [0];
$u_name = $data_row[1];
$f_name = $data_row [3];
$s_name = $data_row [4];
?>
<tr align = 'center'>
<td> <?php echo #$u_id;?></td>
<td> <?php echo #$u_name;?></td>
<td> <?php echo #$f_name;?></td>
<td> <?php echo #$s_name;?></td>
<td><a href = 'delete.php?del=<?php echo $u_id ;?>'>Delete</a></td>
<td><a href = 'edit.php?edit=<?php echo $u_id ;?>'>Edit</a></td>
<td><a href = 'viewrcd.php?details=<?php echo $u_id ;?>'>Details</a></td>
<?php } ?>
</tr>
</table>
<?php
$record_details = #$_GET['details'];
$query8 = "SELECT * FROM users WHERE id = '$record_details'";
$query_run8 = mysql_query($query8);
while($query_run8_row = mysql_fetch_array($query_run8))
{
$d_name = $query_run8_row[1];
$d_firstname = $query_run8_row[3];
$d_surname = $query_run8_row[4];
?>
<table align = center border = 1>
</tr>
<tr ><td colspan = 10 align = center> your details are here </td></tr>
<tr align = center>
<td><?php echo $d_name ; ?></td>
<td><?php echo $d_firstname ; ?></td>
<td><?php echo $d_surname ; ?></td>
</tr>
<?php } ?>
</table>
<font bgcolor = 'green' align = 'center' size = '6'>
<?php echo #$_GET['deleted'];?>
</font>
<font color = 'green' align = 'center' size = '6'>
<?php echo #$_GET['updated'];?>
<?php echo #$_GET['logged'];?>
</font><br><br><br><br><br>
<form action = "viewrcd.php" method = "get">
Search record: <input type = "text" name = "search" >
<input type = "submit" name = "submit" value ="Find Record">
</form>
<?php
if (isset($_GET['search']))
{
$search_record = $_GET['search'];
$query9 = "SELECT * FROM users WHERE id = '$search_record' OR firstname ='$search_record' ";
$query9_run = mysql_query($query9);
while($query9_run_row = mysql_fetch_assoc($query9_run))
{
//$find_id = $query9_run_row['id'];
$find_username = $query9_run_row['username'];
$find_firstname = $query9_run_row['firstname'];
$find_surname = $query9_run_row['surname'];
?>
<br><br><br>
<table border = '2' bgcolor ='green' align ='center'>
<tr>
<th>Username</th>
<th>Firstname</th>
<th>Surname</th>
<tr>
<td><?php echo $find_username ; ?></td>
<td><?php echo $find_firstname ; ?></td>
<td><?php echo $find_surname ; ?></td>
</tr>
</table>
<?php } } ?>
</body>
</html>
<?php }?>
admin-logout.php
<?php
session_start();
// session_destroy();
unset($_SESSION['admin_id']);
header('Location: loginform.php');
?>

Showing data from category with php mysql

My tables are:
barangtbl: id, judul_barang, judul_seo, keywords, deskripsi, id_kat, id_sub, id_supersub, kategori_seo, view, gambar
kategori: id_kat, nama_kat
subkategori: id_sub, id_kat, nama_sub
supersubkategori: id_supersub, id_sub, id_kat, nama_supersub
I have a problem with showing data in category from database with PHP, the problem is when i click link: localhost/test/category.php?name=HPI, it doesn't show any data, but if I change HPI with number: 15, it show all.
15 is id_supersub data on supersubkategori table where I join with barangtbl table. So, all i want is if someone click: localhost/test/category.php?name=HPI it will show data with HPI category inside. How solve this problem?
<?php
if (isset($_GET['name']))
{
$kategori = $_GET['name'];
}
include "config.php";
if ((isset($kategori)) =='')
{
$query = "SELECT * FROM barangtbl INNER JOIN supersubkategori on supersubkategori.id_supersub = barangtbl.id_supersub ORDER BY id DESC LIMIT 0,12";
$hasil = mysql_query($query);
$numrows = mysql_num_rows($hasil);
}
else
{
echo "
<table width=\"100%\">
<tr>
<td align=\"center\"><b><font color=\"red\" size=\"2.5\">[ ".$_GET['name']." ]</b></font></td>
</tr>
</table>";
$query = "SELECT * FROM barangtbl WHERE id_supersub = '$kategori' ORDER BY id";
$hasil = mysql_query($query);
$numrows = mysql_num_rows($hasil);
}
?>
<table cellpadding="10" cellspacing="2" align="center">
<tr>
<?php
$kolom=3;
$x = 0;
if($numrows > 0)
{
while($data=mysql_fetch_array($hasil))
{
if ($x >= $kolom)
{
echo "</tr><tr>";
$x = 0;
}
$x++;
?>
<th>
<div id="title">
<a href="product.php?id=<?php echo $data['id']; ?>">
<?php echo $data['judul_barang']; ?>
</a>
<br><br>
</div>
<div id="image">
<a href="product.php?id=<?php echo $data['id']; ?>">
<img width='150' height='150' valign='top' border='1,5' src="product/<?php echo $data['gambar']; ?>" />
</a>
<br><br>
</div>
<div id="action">
<?php
echo '
<a href="product.php?id='.$data['id'].'">
<img src="images/detail.jpg"\ title="Detail Barang" border="0" width=\"50\" height=\"30\">
</a>';
?>
</div>
<hr />
</th>
<?php
}
}
?>
</tr>
</table>
Try removing the quotes
$query = "SELECT * FROM barangtbl WHERE id_supersub = $kategori ORDER BY id";

Categories