Error in sql query with php and mysql? - php

I got this error
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
and here is my code
<?php
$titulo = "Baja de usuario";
require "conexion.php";
$usu_nombre = $_POST["usu_nombre"];
$usu_id = $_POST["usu_id"];
$sql = "DELETE FROM usuarios WHERE usu_id = ".$usu_id;
$resultado = mysqli_query($link, $sql) or die(mysqli_error($link));
$chequeo = mysqli_affected_rows($link);
include "encabezado.php";
?>
Can't really find the syntax error there, any idea?
the $_POST["usu_id"] comes from here:
$titulo = "Formulario de baja- Usuarios - Proyecto integrador";
require "conexion.php";
$usu_id = $_GET["usu_id"];
$sql = "SELECT usu_id, usu_login ,usu_clave, usu_nombre, usu_email FROM usuarios WHERE usu_id = ".$usu_id;
$resultado = mysqli_query($link, $sql) or die(mysqli_error($link));
?>
<?php include "encabezado.php"; ?>
</head>
<body>
<div id="top"><img src="imagenes/top.png" alt="encabezado" width="980" height="80"></div>
<div id="nav">
<?php include "menu.php"; ?>
</div>
<div id="main">
<h1><?php echo $titulo ; ?></h1>
<!-- inicio del desarrollo -->
<form action = "baja-usuario.php" method = "post" onsubmit = "return confirmarBaja()">
<table id="paneles">
<tr>
<th colspan ="5">Se eliminara el siguiente usuario</th>
</tr>
<tr>
<th>Id</th>
<th>Login</th>
<th>Clave</th>
<th>Nombre</th>
<th>Email</th>
</tr>
<?php while($fila = mysqli_fetch_assoc($resultado)){ ?>
<tr>
<td class = "lista"><?php echo $fila["usu_id"] ;?></td>
<td class = "lista"><?php echo $fila["usu_login"]; ?></td>
<td class = "lista"><?php echo $fila["usu_clave"] ;?></td>
<td class = "lista"><?php echo $fila["usu_nombre"] ;?></td>
<td class = "lista"><?php echo $fila["usu_email"] ;?></td>
</tr>
<?php } ?>
<tr>
<td><input type= "hidden" name = "usu_id" value = "<?php echo $fila["usu_id"]; ?>"></td>
<td><input type= "hidden" name = "usu_nombre" value = "<?php echo $fila["usu_nombre"]; ?>"></td> <!-- el input type hidden no renderiza el valor pero si sirve para pasarlo como parametro en el FROM -->
</tr>
<tr>
<td colspan = "2" class ="centrar"><input type = "submit" value = "Eliminar"></td>
</tr>
</table>
</form>
and the usu_id from the : <td class = "lista"><?php echo $fila["usu_id"] ;?></td> displays correctly, showing the ID

The error was that i was using <?php while($fila = mysqli_fetch_assoc($resultado)){ ?> and so the usu_id the form send to the POST, was empty beacuse of the msqli_fetch_assoc

Related

File view to the another tab (PHP)

I have inserted a file with an UPDATE command because I want my files (pdf, jpg) to be in one table together with name, course, etc. and and I just want to know if it it is possible that instead of showing the name of the filename in the table, its filename would be an href on when the person have click it, it would go in the another tab to show is content (pdf, or jpeg).
Here is my code of my addrequirements.php
<?php
include_once 'connection.php';
$result = mysqli_query($conn,"SELECT * FROM collegestud");
$result1 = mysqli_query($conn,"SELECT * FROM shsstud");
session_start();
if(!$_SESSION['login']){
header("location:index.php");
die;
}
?>
<div id="ccc">
<?php
if (mysqli_num_rows($result) > 0) {
?>
<table id="example" class="display" style="width:100%;">
<thead>
<tr>
<th>Student Id</th>
<th>Course</th>
<th>Last Name</th>
<th>First Name</th>
<th>Psa</th>
<th>Form137</th>
<th>2x2 Picture</th>
<th>Actions</th>
</tr>
</thead>
<tbody id='cccc'>
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $row["Stud_ID"]; ?></td>
<td><?php echo $row["Course"]; ?></td>
<td><?php echo $row["Lastname"]; ?></td>
<td><?php echo $row["Firstname"]; ?></td>
<td><?php echo $row["PSA"]; ?></td>
<td><?php echo $row["Form137"]; ?></td>
<td><?php echo $row["Picture"]; ?></td>
<td><a style="color:green;" href="updatecollege1.php?id=<?php echo $row["ID"]; ?>"><i class="fas fa-folder-plus fa-2x "></i></a> 
<span><a style="color:red" href="deletecollege.php?ID=<?php echo $row["ID"]; ?>"onclick="return confirm('Do you really want to delete this student?')"><i class="fas fa-user-minus fa-2x"></i></a></span>
</td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
<?php
}
else
{
echo "<p><center><strong>0 RESULTS IN THE TABLE</center></p></strong>";
}
?>
Code of my updatecollege1.php
<?php
include_once 'connection.php';
session_start();
if(!$_SESSION['login']){
header("location:index.php");
die;
}
$result = mysqli_query($conn,"SELECT * FROM collegestud WHERE id='" . $_GET['id'] . "'");
$row= mysqli_fetch_array($result);
?>
<div class = "container3">
<strong><left>PSA   </left></strong>
<span>   <input id="ra" type="text" value="" readonly>ADD or UPDATE</span><br>
Code of my psaadd.php
<?php
include_once 'connection.php';
session_start();
if(!$_SESSION['login']){
header("location:index.php");
die;
}
if(count($_POST)>0) {
mysqli_query($conn,"UPDATE collegestud
set PSA = '" . $_POST['PSA'] . "'
WHERE ID='" . $_POST['ID'] . "'");
$id = $_POST['ID'];
header('Location: updatecollege1.php?id='.$id);
}
$result = mysqli_query($conn,"SELECT * FROM collegestud WHERE id='" . $_GET['id'] . "'");
$row= mysqli_fetch_array($result);
?>
<form action="" method="POST" onsubmit="return confirm('Are you sure you want to save changes?');">
<div class= "container2">
<p style="font-weight: bold; font-size: 35px; text-align: center;">PSA</p>
<input type="hidden" name="ID" class="txtField" value="<?php echo $row['ID']; ?>">
<div class = "container3">
<center>
<input name="PSA" type = "file" accept = '.pdf'>
</center>
PROBLEM:
I just want to have a solution that instead it displays the filename of that file (text), it will show its filename in the table that is clickable to open its file in the another tab.
Yes, of course it possible. You should save also relative path to that PDF in database and then show link in UI part:
<!-- Start of table -->
<td>
Click to view
</td>
And your database table will have 1 additional field named path VARCHAR(256) NOT NULL with value e.g. students/some_name_of_file.pdf
Never store file content to database, it's not build to hold file contents

Navigate to the specific link is not working according to the database status value in php and sqlite

when i clicked the link it does not redirect to the page that specified.i have the sqlite database and there is a database column for status(added,updated like wise).i want to redirect to the page when i clicked the status link in my link.php.Now Object not found error is getting.
this is my link.php code below.
Please can you help me guys.
<?php
// Includs database connection
include "db_connect.php";
// Makes query with rowid
$query = "SELECT rowid, * FROM registration";
// Run the query and set query result in $result
// Here $db comes from "db_connection.php"
$result = $db->query($query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Data List</title>
<script>
function pop_up(url){
window.open(url,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=1076,height=768,directories=no,location=no')
}
</script>
</head>
<body>
<br>
<br>
<!-- Add New-->
<table>
<tbody>
<tr>
<th style="">status</th>
<th style="">submitted</th>
<th style="">department</th>
<th style="">head</th>
<th style="">title</th>
<th style="">applicant</th>
<th style="">date</th>
</tr>
<?php while($row = $result->fetchArray()) {?>
<!--<tr class="table-row" data-href="update.php?id=<?php echo $row['rowid'];?>" data-target="_blank">-->
<tr>
<td>
</td>
<td>view
<?php
if ($row['rowid'] == "added"){
echo "<a href='updated.php" . $row['submitted'] . "updated'> </a>";
} else {
echo "<a href='next.php" . $row['submitted'] . "next'> </a>";
}
?>
</td>
<td><?php echo $row['status'];?></td>
<td><?php echo $row['submitted'];?></td>
<td><?php echo $row['department'];?></td>
<td><?php echo $row['head'];?></td>
<td><?php echo $row['title'];?></td>
<td><?php echo $row['applicant'];?></td>
<td><?php echo $row['date'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
<script>
var tableRows = document.getElementsByClassName('table-row');
for (var i = 0, ln = tableRows.length; i < ln; i++) {
tableRows[i].addEventListener('click', function() {
window.open(this.getAttribute('data-href'), this.getAttribute('data-target'));
});
}
</script>
<br>
<br>
</body>
</html>

Method pot-php, mysqli and fpdf

I have tried to make a report using FPDF.
While sending the form data to the Query in FPDF, does not show me the data
Form
include_once('PDF.php');
require 'conexion.php';
$where = "";
if (isset($_POST['buscar'])) {
$desde = date('Y-m-d',strtotime ($_POST['desde']));
//$hasta = date('Y-m-d', strtotime($_POST['hasta']));
$valor = $_POST['campo'];
if (empty($_POST['dese'])) {
$where = "WHERE proveedores LIKE '%".$valor."%' ORDER BY cxl ASC";
} elseif (empty($POST['campo'])) {
$where = "WHERE f_elaboracion = '".$desde."' ORDER BY cxl ASC";
}else{
$where = "WHERE proveedores LIKE '".$valor."' AND f_elaboracion = '".$desde."' ORDER BY cxl ASC";
}
}
$sql = "SELECT * FROM retensiones $where";
$resultado = $mysqli->query($sql);?>
<html lang="es">
<body>
<div class="container">
<div class="row">
<h2 style="text-align:center">FORMULARIO</h2>
</div>
<div class="row">
<form method="POST" >
<select name="campo">
<option value="2">Proveedor</option>
<?php
$query = $mysqli -> query ("SELECT proveedores FROM proveedores ORDER BY proveedores ASC");
while ($valores = mysqli_fetch_array($query)) {
echo '<option value="'.$valores[proveedores].'">'.$valores[proveedores].'</option>';
}?>
</select>
<td>Desde : </td>
<td><input type="date" id="desde" name="desde"/></td>
<button name="buscar" type="submit" class="btn btn-info" >Buscar</button>
<td width="200"><a target="_blank" href="indexpdf.php" class="btn btn-danger">Exportar Busqueda a PDF</a></td>
</form>
</div>
<div class="row table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>CXL</th>
<th>FECHA</th>
<th>Concepto</th>
<th>Periodo</th>
<th>Importe</th>
<th>I.V.A.</th>
<th>I.S.R.</th>
</tr>
</thead>
<tbody>
<?php while($row = $resultado->fetch_array(MYSQLI_ASSOC))
{?>
<tr>
<td><?php echo $row['cxl']; ?></td>
<td><?php echo date('d/m/Y',strtotime($row['f_elaboracion'])); ?></td>
<td><?php echo $row['concepto']; ?></td>
<td><?php echo $row['periodo']; ?></td>
<td><?php echo number_format (($row['importe']),'2','.',','); ?></td>
<td><?php echo number_format (($row['iva']),'2','.',','); ?></td>
<td><?php echo number_format (($row['isr']),'2','.',','); ?></td>
</tr>
<?php
}?>
</tbody>
</table>
</div>
</div>
</body>
</html>
FPDF TEMPLATE
$mysqli = new mysqli('localhost', 'root', 'pasword.123', 'tesoreria');
if($mysqli->connect_error){
die('Error en la conexion' . $mysqli->connect_error);
}
$where = "";
if(isset($_POST['buscar'])) {
$desde = date('Y-m-d',strtotime ($_POST['desde']));
//$hasta = date('Y-m-d', strtotime($_POST['hasta']));
$valor = $_POST['campo'];
if (empty($_POST['dese'])) {
$where = "WHERE proveedores LIKE '%".$valor."%' ORDER BY cxl ASC";
} else if (empty($POST['campo'])){
$where = "WHERE f_elaboracion = '".$desde."' ORDER BY cxl ASC";
} else {
$where = "WHERE proveedores LIKE '".$valor."' AND f_elaboracion = '".$desde."' ORDER BY cxl ASC";
}
}
$sql = "SELECT * FROM retensiones $where";
$result = $mysqli->query($sql);
include_once('PDF.php');
$pdf = new PDF();
$pdf->AliasNbPages();//Genera el numero de paginas finales
$pdf->AddPage();//Agrega una nueva pagina
$rows=0; // inicia el contador de fila
$totalimporte=0;
$totaliva=0;
$totalisr=0;
$pdf->SetXY(10,80);
$pdf->SetFont('Arial','',10);
$pdf->SetTextColor(3,3,3);//Coor del Texto Negro
while ($fila = $result->fetch_assoc())
{
$pdf->Cell(20,7, utf8_decode($fila['cxl']),0,0,'L');
$pdf->Cell(25,7, date('d/m/Y',strtotime($fila['f_elaboracion'])),0,0,'L'); //date strtotime , da el formato dia mes año
$pdf->Cell(45,7, utf8_decode($fila['concepto']),0,0,'L');
$pdf->Cell(25,7, utf8_decode($fila['periodo']),0,0,'L');
$pdf->Cell(25,7, number_format (($fila['importe']),'2','.',',') ,0,0,'L'); // numer format , le da el formato en centenas miles y millones
$pdf->Cell(25,7, number_format (($fila['iva']),'2','.',','),0,0,'L');
$pdf->Cell(25,7, number_format (($fila['isr']),'2','.',','),0,0,'L');
$pdf->Ln();
$rows++; //suma 1 al contador
$totalimporte= $totalimporte + ($fila['importe']);
$totaliva = $totaliva + ($fila['iva']);
$totalisr = $totalisr + ($fila['isr']);
if($rows==22) { // si el numero de fila es igual a 20
$rows = 0; //vuelve el contador cero y
$pdf->AddPage(); // agrega una nueva pagina
}
}
$pdf->Ln();
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','B',10);
$pdf->Cell(20,7 ,"TOTALES",1,0,'L');
$pdf->SetX(115);
$pdf->SetFont('Arial','',12);
$pdf->Cell(30,10, number_format (($totalimporte),'2','.',',') ,1,0,'L');
$pdf->Cell(30,10, number_format (($totaliva),'2','.',',') ,1,0,'L');
$pdf->Cell(30,10, number_format (($totalisr),'2','.',',') ,1,0,'L');
$pdf->Output();//Salida del navegador
mysql_close($conexion);
Your <a target="_blank" href="indexpdf.php" class="btn btn-danger">Exportar Busqueda a PDF</a> does not send the form data. You can use Jquery to send the data you want to the PDF template.
include_once('PDF.php');
require 'conexion.php';
$where = "";
if (isset($_POST['buscar'])) {
$desde = date('Y-m-d',strtotime ($_POST['desde']));
//$hasta = date('Y-m-d', strtotime($_POST['hasta']));
$valor = $_POST['campo'];
if (empty($_POST['dese'])) {
$where = "WHERE proveedores LIKE '%".$valor."%' ORDER BY cxl ASC";
} elseif (empty($POST['campo'])) {
$where = "WHERE f_elaboracion = '".$desde."' ORDER BY cxl ASC";
}else{
$where = "WHERE proveedores LIKE '".$valor."' AND f_elaboracion = '".$desde."' ORDER BY cxl ASC";
}
}
$sql = "SELECT * FROM retensiones $where";
$resultado = $mysqli->query($sql);?>
<html lang="es">
<head>
<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 type="text/javascript">
$(document).ready(function () {
$("#indexPDF").click(function(){
submit('indexpdf.php', 'POST', [
{ name: 'desde', value: $('#desde').val() },
{ name: 'campo', value: $('#campo').val() }
], '_blank');
});
});
function submit(action, method, values, target) {
var form = $('<form/>', {
action: action,
method: method,
target: target
});
$.each(values, function() {
form.append($('<input/>', {
type: 'hidden',
name: this.name,
value: this.value
}));
});
form.appendTo('body').submit();
}
</SCRIPT>
</head>
<body>
<div class="container">
<div class="row">
<h2 style="text-align:center">FORMULARIO</h2>
</div>
<div class="row">
<form method="POST" >
<select name="campo">
<option value="2">Proveedor</option>
<?php
$query = $mysqli -> query ("SELECT proveedores FROM proveedores ORDER BY proveedores ASC");
while ($valores = mysqli_fetch_array($query)) {
echo '<option value="'.$valores[proveedores].'">'.$valores[proveedores].'</option>';
}?>
</select>
<td>Desde : </td>
<td><input type="date" id="desde" name="desde"/></td>
<button name="buscar" type="submit" class="btn btn-info" >Buscar</button>
<td width="200"><div id="indexPDF" class="btn btn-danger">Exportar Busqueda a PDF</div></td>
</form>
</div>
<div class="row table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>CXL</th>
<th>FECHA</th>
<th>Concepto</th>
<th>Periodo</th>
<th>Importe</th>
<th>I.V.A.</th>
<th>I.S.R.</th>
</tr>
</thead>
<tbody>
<?php while($row = $resultado->fetch_array(MYSQLI_ASSOC))
{?>
<tr>
<td><?php echo $row['cxl']; ?></td>
<td><?php echo date('d/m/Y',strtotime($row['f_elaboracion'])); ?></td>
<td><?php echo $row['concepto']; ?></td>
<td><?php echo $row['periodo']; ?></td>
<td><?php echo number_format (($row['importe']),'2','.',','); ?></td>
<td><?php echo number_format (($row['iva']),'2','.',','); ?></td>
<td><?php echo number_format (($row['isr']),'2','.',','); ?></td>
</tr>
<?php
}?>
</tbody>
</table>
</div>
</div>
</body>
</html>
I changed your code
<a target="_blank" href="indexpdf.php" class="btn btn-danger">Exportar Busqueda a PDF</a>
to
<div id="indexPDF" class="btn btn-danger">Exportar Busqueda a PDF</div>
Missing is the Style sheet. I edited the above code to include the style sheet.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

How to delete row of table with a button inside

I have a table generated with The foreach construct, on each <tr> there is a delete button inside. I want to delete the row containing the button (by the ID) but all I've done is delete the last row (the last ID) that was saved and not the desired.
This is a part of my HTML code:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<table class="Pizarra" id="pizarra" cellspacing="0px";>
<tr class="trThDos">
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tbody>
<!-- Comienza PHP -->
<?php
$i = 0;
foreach ($resultados as $fila)
{
?>
<tr>
<input type="hidden" name="id" value="<?php echo $fila['ID']; ?>" />
<td class="tdTurno"><?php echo '#' . ++$i ?></td>
<td class="tdImg">
<?php echo $fila ['value'];
switch ($fila['value'])
{
case "0":
echo "<img src='./img/consulta-56-2.png'";
break;
case "1":
echo "<img src='./img/shot-56-2.png'";
break;
case "2":
echo "<img src='./img/ta-56-2.png'";
break;
case "3":
echo "<img src='./img/cert-56-2.png'";
break;
default:
echo "Hubo un error en la selección";
break;
} ?>
</td>
<td>
<?php echo $fila ['nombre']; ?>
</td>
<td class="tdHr">
<?php echo $fila ['hora']; ?>
</td>
<td>
<input type="submit" class="btnBorrar" name="btnBorrar" value="X">
</td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
PHP code:
<?php
// ----------- CONEXIÓN ------------------
try {
$conexion = new PDO('mysql:host=localhost;dbname=farmacia', 'Emm', ' ');
$conexion->exec("set names utf8");
//echo "Conexión OK <br />";
}catch(PDOException $e){
echo "Error: " . $e->getMessage();
die();
}
// ----------- TERMINA CONEXIÓN -----------------
if(isset($_POST['btnBorrar'])){
$id = $_POST['id'];
$statement = $conexion->prepare("DELETE FROM eventos WHERE ID = $id");
$statement->execute();
//fetchAll' es clave para que invoque (llame) TODOS los elementos
$resultados = $statement->fetchAll();
header("Location:index.php");
$conexion = null;
}
?>
Use GET method instead of POST
In your HTML instead of using submit button use link as shown in below
X
In the delete.php do like following
<?php
if(isset($_GET['id'])){
//get the id into php variable like below
$id = $_GET['id'];
//sql query to delete with id variable in where clause
}
?>
Hope this work!!!
Try with below code..
HTML
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<table class="Pizarra" id="pizarra" cellspacing="0px";>
<tr class="trThDos">
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tbody>
<!-- Comienza PHP -->
<?php
$i = 0;
foreach ($resultados as $fila) {
?>
<tr id="row_id_<?php echo $fila['ID']; ?>">
<td class="tdTurno"><?php echo '#' . ++$i ?></td>
<td class="tdImg"><?php echo $fila ['value'];
switch ($fila['value']){
case "0":
echo "<img src='./img/consulta-56-2.png'";
break;
case "1":
echo "<img src='./img/shot-56-2.png'";
break;
case "2":
echo "<img src='./img/ta-56-2.png'";
break;
case "3":
echo "<img src='./img/cert-56-2.png'";
break;
default:
echo "Hubo un error en la selección";
break;
} ?></td>
<td><?php echo $fila ['nombre']; ?></td>
<td class="tdHr"><?php echo $fila ['hora']; ?></td>
<td><input type="button" class="btnBorrar" name="btnBorrar" value="X" onClick="delete_row(<?php echo $fila['ID']; ?>)"></td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
JavaScript
function delete_row(delete_id) {
$.ajax({
type: "POST",
url: 'delete_row.php',
data: 'delete_id='+delete_id,
success: function(data_respones){
$("#row_id_"+delete_id).remove();
}
});
}
delete_row.php
<?php
// ----------- CONEXIÓN ------------------
try {
$conexion = new PDO('mysql:host=localhost;dbname=farmacia', 'Emm', ' ');
$conexion->exec("set names utf8");
//echo "Conexión OK <br />";
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
die();
}
if(isset($_POST["delete_id"])){
//do delete stuff
$statement = $conexion->prepare("DELETE FROM eventos WHERE ID = $id");
$statement->execute();
}
?>
Instead of using POST method, use GET and give your delete button a link like
yourscript.php?delete={ID}
and handle your id like
$deleteId = (int)$_GET["delete"];
and
if(isset($deleteId)){
//do delete stuff
$statement = $conexion->prepare("DELETE FROM eventos WHERE ID = $deleteId");
$statement->execute();
//fetchAll' es clave para que invoque (llame) TODOS los elementos
$resultados = $statement->fetchAll();
}
Replace your hidden input field with this;
<a href="yourscript.php?delete=<?php echo $fila['ID']; ?>">Delete me</>

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');
?>

Categories