Sorry for a duplicate question, but its not working for me;
access page only if logged in with php
i have to access display.php page if someone loggedin, if they enter the url directly it need to redirect to login.php page,
i tried sessions but its not working for me, please help me to debug it.
display.php
<?php
session_start();
if(!isset($_SESSION['loggedin']))
{
header("location: login.php");
}
$conn=mysqli_connect("localhost","root","zaq12345","testdb");
if(!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
$disp = "select * from formdata order by user_id desc";
$result = mysqli_query($conn,$disp);
?>
<button onclick="location.href='formnew1.html';">Add</button>
<table border="2" cellpadding="0" cellspacing="0">
<tr>
<th> ID </th>
<th> Name </th>
<th> Email </th>
<th> Age </th>
<th> Gender </th>
<th> Address </th>
<th> City </th>
<th> Skills </th>
<th>Action</th>
</tr>
<?php
//$rows = mysqli_fetch_assoc($result);
while ($row = $result->fetch_assoc())
{
$id = $row['user_id']; ?>
<tr>
<td><?php echo $row['user_id']?> </td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['email']?></td>
<td><?php echo $row['age']?></td>
<td><?php echo $row['gender']?></td>
<td><?php echo $row['address']?></td>
<td><?php echo $row['city']?></td>
<td><?php echo $row['skill']?></td>
<td>
<a id="edit" href="edit1.php?id=<?php echo $row['user_id']; ?>">Edit</a>
Delete
</td>
</tr>
<?php } ?>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
function deleteRow(obj){
conf=confirm('Are you sure to delete the Data');
if(conf){
var tr = $(obj).closest('tr');
$.post("delete1.php", {id: obj.id}, function(result){
tr.fadeOut('slow', function(){
$(obj).remove();
});
});
}
}
</script>
<?php
if (isset($_SESSION['success']))
{
echo '<script> alert("Data Added Successfully");</script>';
}
else if (isset($_SESSION['fail'])){
echo '<script> alert("Failed to Store");</script>';
//header("Location: /training/formnew.html");
}
mysqli_close($conn);
?>
login.php
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<style>
div {
color: rgb(255,0,0);
}
form {
max-width: 425px;
margin: 10px auto;
padding: 10px 20px;
background: #ff994580;
border-radius: 10px;
}
fieldset {
margin-top: 100px ;
margin-bottom: 500px;
border: none;
}
h2 {
margin: 0 0 30px 0;
text-align: center;
font-family: 'Calibri';
font-size: 40px;
font-weight: 300;
}
label {
font-family: 'Calibri';
font-size: 16px;
font-weight: 50;
}
.submit {
background-color: #4CAF50;
border-radius: 10px;
color: white;
padding: 10px 40px 10px;
text-align: center;
font-size: 16px;
cursor: pointer;
}
.reset {
background-color: #ff3333;
border-radius: 10px;
color: white;
padding: 10px 40px 10px;
text-align: center;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<fieldset>
<form id="myform" name="myform" method="POST" action="validate.php">
<H2> LOGIN </H2>
<table width="60%" cellpadding="10">
<tr>
<td>
<label>User ID</label>
</td>
<td>
<input type="text" id="user_id" name="user_id"placeholder="Enter your User ID" required="required"/>
</td>
</tr>
<tr>
<td>
<label>User Name</label>
</td>
<td>
<input type="text" id="user_name" name="user_name" placeholder="Enter your Username" required="required"/>
</td>
</tr>
<tr>
<td>
<label>Password</label>
</td>
<td>
<input type="password" id="password" name="password" placeholder="Enter your Password" required="required"/>
</td>
</tr>
<tr>
<td>
<input type="submit" class="submit" name="submitbtn" value="Login">
</td>
<td>
<input type="reset" class="reset"/>
</td>
</tr>
</table>
</form>
</fieldset>
</script>
</body>
</html>
validate.php
<?php
session_start();
$conn=mysqli_connect("localhost","root","zaq12345","testdb");
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$userid=$_POST['user_id'];
$username=$_POST['user_name'];
$password=$_POST['password'];
$qz = "SELECT * FROM userdata WHERE user_id = '$userid' AND user_name = '$username' AND password = '$password'";
$result=mysqli_query($conn,$qz);
if(mysqli_num_rows($result) == 1 )
{
$_SESSION['loggedin'] = true;
$_SESSION['user_id'] = $userid;
header('location: display1.php');
}
else{
$_SESSION['loggedin'] = false;
echo '<script> alert("ERROR: Please Check Credentials OR SignUp!!!"); window.location.href="login.php"; </script>';
}
}
mysqli_close($conn);
?>
Either remove the line $_SESSION['loggedin'] = false; in your validate.php file.
Or change the if statement in your display.php file to be
if (!isset($_SESSION['loggedin'] || !$_SESSION['loggedin'])
You are setting the loggedin to be false, so when you call isset it returns true, because it is set even though it is set to false.
Related
Sorry for asking this since I am fairly new to PHP, but I am trying to create a login system wherein a user logs in to enter a homepage. The login page sets cookies for the username and password if the user checks the Remember me checkbox regardless if login is successful or not. If login is successful, it starts a session. While there is an active session, the user cannot access the login page unless they log out. If login is not successful, it will redirect back to the login page. My problem here is that the cookies are not set regardless if the login is successful or not. But if I remove the if isset($_SESSION) statement, it successfully sets the cookies. Below is my code:
login.php:
<?php
session_start();
if(isset($_POST["login"]))
{
$remember = $_POST["remember"];
if($remember == 1)
{
setcookie("username", $_POST["uname"], time()+86400);
setcookie("password", $_POST["pwd"], time()+86400);
}
if(isset($_SESSION['uname']))
{
echo"<script>alert('Already logged in.')</script>";
echo"<script>location.href = 'home.php'</script>";
}
}
?>
<html>
<head>
<title>Login</title>
<style>
body
{
background-color: DimGray;
}
table
{
font-family: Calibri;
color:white;
font-size: 14pt;
font-style: normal;
font-weight: bold;
text-align: left;
background-color: DimGray;
border-collapse: collapse;
border: 2px solid white
}
table.inner
{
border: 0px
}
.my_text
{
text-align: center;
font-family: Helvetica;
color:white;
font-size: 40px;
font-weight: bold;
margin: 50px;
}
</style>
</head>
<body>
<div class = my_text> Login Page</div>
<table align="center" cellpadding = "10">
<!----- Userame ---------------------------------------------------------->
<form method="post" action="home.php">
<tr>
<td>Username: </td>
<td><input type="text" name="uname" value = "<?php if(isset($_COOKIE["username"])) echo $_COOKIE["username"]?>"/>
</td>
</tr>
<!----- Password ---------------------------------------------------------->
<tr>
<td>Password: </td>
<td><input type="text" name="pwd" value = "<?php if(isset($_COOKIE["password"])) echo $_COOKIE["password"]?>"/>
</td>
</tr>
<!----- Remember me ------------------------------------------------->
<tr>
<td>Remember Me </td>
<td><input type="checkbox" name="remember" value = "1"/>
</td>
</tr>
<!----- Submit ------------------------------------------------->
<tr>
<td colspan="2" align="center">
<input type="submit" value="Login" name="login">
</td>
</tr>
</table>
</form>
<br>
<br>
</body>
</html>
home.php:
<?php
$uname = "admin";
$pwd = "12345";
session_start();
if(isset($_SESSION['uname']))
{
echo"<table align='center' cellpadding = '10'>";
echo"<tr><td>Welcome " . $_SESSION['uname'] . "</td></tr>";
echo"<tr align = 'center'><td><a href = 'logout.php'><input type = button value = logout name logout></a></td></tr>";
}
else
{
if($_POST["uname"] == $uname && $_POST["pwd"] == $pwd)
{
$_SESSION["uname"] = $uname;
echo"<script>location.href = 'home.php'</script>";
}
else
{
echo"<script>alert('Username or Password is incorrect.')</script>";
echo"<script>location.href = 'login.php'</script>";
}
}
?>
<html>
<head>
<title>Home</title>
<style>
body
{
background-color: DimGray;
}
table
{
font-family: Calibri;
color:white;
font-size: 30pt;
font-style: normal;
font-weight: bold;
text-align: left;
background-color: DimGray;
border-collapse: collapse;
border: 2px solid white
}
table.inner
{
border: 0px
}
.my_text
{
text-align: center;
font-family: Helvetica;
color:white;
font-size: 40px;
font-weight: bold;
margin: 50px;
}
</style>
</head>
<body>
<div class = my_text> Home Page</div>
</body>
</html>
logout.php:
<?php
session_start();
if(isset($_SESSION['uname']))
{
session_destroy();
echo"<script>location.href = 'login.php'</script>";
}
else
{
echo"<script>location.href = 'login.php'</script>";
}
?>
What to add in my query to restrict users from choosing wrong dates ,
E.G. From March 7 To March 2 , the transaction within march 2-7 does not show up ,but when you change it to march 7 to april 7 it shows all transaction , is
there anything that I can add to restrict users from doing that.
Please help me.
Thank you very much.
This is my sales.php file where the user will choose what date to show.
<form action="total_sales.php" method="post">
From: <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required pattern="[0-9]{4}+[0-9]+[0-9]"> To: <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required pattern="[0-9]{4}+[0-9]+[0-9]">
<input type="submit" value="Show Sales" name="salesbtn" ></form></center>
This is my total_sales.php file.
<head>
<script>
$(function() {
$( "#tabs" ).tabs();
$('a[rel*=facebox]').facebox();
$( ".datepicker" ).datepicker();
});
$(document).ready(function(){
// Write on keyup event of keyword input element
$("#searchme").keyup(function(){
// When value of the input is not blank
if( $(this).val() != "")
{
// Show only matching TR, hide rest of them
$("#searchTbl tbody>tr").hide();
$("#searchTbl td:contains-ci('" + $(this).val() + "')").parent("tr").show();
}
else
{
// When there is no input or clean again, show everything back
$("#searchTbl tbody>tr").show();
}
});
});
// jQuery expression for case-insensitive filter
$.extend($.expr[":"],
{
"contains-ci": function(elem, i, match, array)
{
return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
</script>
<script>
function goBack() {
window.history.back();
}
</script>
<?php include('session.php'); ?>
<?php include('header.php'); ?>
<?php include('navbar.php'); ?>
<style>
.footer1 {
position: absolute;
right: 45%;
font-family: ""Lucida Console", Monaco, monospace";
top: 0%;
width: 80%;
background-color:#F8F8FF;
color: black;
text-align: left;
}
h3{
font-size:20px;
font-family: "Arial";
}
table {
width:60%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: center;
}
#media print {
#page { margin: 0; }
body { margin: 1cm; }
#printPageButton {
display: none;
}
#e{
display:none;
}
.footer {
position: fixed;
left: 0;
font-family: ""Lucida Console", Monaco, monospace";
bottom: 0;
width: 100%;
background-color:#F8F8FF;
color: black;
text-align: center;
}
}
</style>
<div style="height:30px;"></div>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-0">
<br><img src="../upload/logo.jpg" align="center" class="footer1" style="height:50px; width:50px;"><br>
<br>
<?php
if(isset($_POST['salesbtn'])) {
$from = date('Y-m-d', strtotime($_POST['dayfrom']))." 00:00:01";
$to = date('Y-m-d', strtotime($_POST['dayto']))." 23:59:59";
?>
<center><h1> Product Sales Report </h1><h3>From (<?php echo $from; ?>) To (<?php echo $to; ?>)</h3>
<button id="printPageButton" onClick="window.print();" class="btn btn-primary" button type="submit">Print</button>
<button id="e" class="btn btn-primary" onclick="goBack()">Back</button>
<br><br>
<table width="100%" cellspacing="0" cellpadding="0" style="font-family:Arial Narrow, Arial,sans-serif; font-size:15px;" border="1">
<tr>
<td width="30%"><div align="center"><strong>Purchase Date</strong></div></td>
<td width="30%"><div align="center"><strong>Customer</strong></div></td>
<td width="40%"><div align="center"><strong> Purchase Name</strong></div></td>
<td width="40%"><div align="center"><strong>Quantity</strong></div></td>
</tr>
<?php
try {
require ("conn.php");
$stmt1 = $conn->prepare("select * from sales_detail left join product on product.productid=sales_detail.productid left join sales on sales.salesid=sales_detail.salesid left join customer on sales.userid=customer.userid where product.supplierid='".$_SESSION['id'] ."' AND sales_date BETWEEN '$from' AND '$to' order by sales.sales_date desc");
$stmt1->execute();
while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
$sales_date = $row['sales_date'];
$customer_name = $row['customer_name'];
$product_name = $row['product_name'];
$sales_qty = $row['sales_qty'];
?>
<tr align="center">
<td><?php echo $sales_date; ?></td>
<td><?php echo $customer_name; ?></td>
<td><?php echo $product_name; ?></td>
<td><?php echo $sales_qty; ?></td>
</tr>
</center>
<?php
}
}
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
}
?>
<tr>
</tr>
</table> </br> </br>
</div>
</div>
</div>
<?php include('script.php'); ?>
<?php include('modal.php'); ?>
<?php include('add_modal.php'); ?>
<script src="custom.js"></script>
So, I tried this and it worked:
the scripts HAVE TO BE in that order (if not it will break)
There is some problem with your pattern, but with Datepicker, you don't need it anyway
After the FROM Date selection I would set the minDate of the TO Date to +1d
Code Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<title>Document</title>
</head>
<body>
<form action="total_sales.php" method="post">
From:
<input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required > To:
<input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required >
<input type="submit" value="Show Sales" name="salesbtn">
</form>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.21/jquery-ui.min.js"></script>
<script>
$(function () {
$(".datepicker").datepicker({
dateFormat: "yy-mm-dd",
minDate: "-1d",
maxDate: "+1w"
});
});
</script>
</body>
</html>
This is my first post here, I feel very welcomed as people told me you guys are nice to help people with problems.
I am making a website for a festival at school, and I somehow got this error today:
mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\projectsite\News.php on line 135
<?php
session_start();
if (isset($_SESSION['test'])){
}else{
$_SESSION["test"]=0;
}?>
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="" href="http://example.com/myicon.png">
<link rel="stylesheet" type="text/css" href="css.css">
</head>
<title>News</title>
</style>
<body bgcolor="#E6E6FA">
<a href="http://localhost/projectsite/index.php" ><img src="images/nl.png"/></a>
<a href="http://localhost/projectsite/homeenglish.php" ><img src="images/uk.png"/></a>
<body background="images/achtergrondje2.jpg" style=>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid #ffffff;
background-color: #494b4a;
}
li {
float: left;
}
li a {
display: block;
color: #dadada;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a {
display: block;
<img src="images/bannertje2.jpg"
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #dadada;
}
li a.active {
color: white;
background-color: #e83d3d;
}
</style>
</head>
</head>
<body><font color="white"
</body>
<ul>
<li>Home</li>
<li>Line-up</li>
<li>Inschrijven</li>
<li><a class="active" href="http://localhost/projectsite/news.php">Nieuws</a></li>
<li style="float:right"><a class="active" href="http://localhost/projectsite/contact.php">Over ons</a></li>
<li style="float:right"><a class="active" href="http://localhost/projectsite/logout.php">Logout</a></li>
<li style="float:right"><a class="active" href="http://localhost/projectsite/Loginmain.php">Login</a></li>
<br>
</ul>
<?php if ($_SESSION["test"] == 1)
{
?><li style="float:right" ><a class="active" href="html.php">uitloggen</a></li><?php
?><li style="float:right" ><a href=''><?php echo "Welkom Back ". $_SESSION["username"] . "( ͡° ͜ʖ ͡°)"?></a></li><?php
}else{
}
?>
</ul>
<div class="flex-container">
<form method="POST">
<table>
<tr><td><h2>Nieuwsitem Toevoegen</h2></td></tr>
<tr>
<th>Title:</th>
<td><input type="text" name="txtTitle" /></td>
</tr>
<tr>
<th>Plaats:</th>
<td><input type="text" name="txtPlaats" /></td>
</tr>
<tr>
<th>Description:</th>
<td><input type="text" name="txtDescription" /></td>
</tr>
<tr>
<th></th>
<td><input type="submit" name="btnnews" value="Invoeren" /></td>
</tr>
<tr>
<th></th>
<td><input type="submit" name="btnnwesplaatsen1" value="plaatsen" /></td>
</tr>
</table>
</form>
<?php
require('connect.php');
// If the values are posted, insert them into the database.
if (isset($_POST['btnnews']))
{
$title = $_POST['txtTitle'];
$Description = $_POST['txtDescription'];
$plaatsID = $_POST['txtPlaats'];
$query = "INSERT INTO `nieuwsitems` (txtPlaats, txtTitle, txtDescription) VALUES ($plaatsID, '$title', '$Description')";
$result = mysqli_query($connection);
if($result)
{
$smsg = "Succes";
}else{
$fmsg ="";
}
}
include("connect.php");
if(isset($_POST['btnnwesplaatsen1']))
{
$query = "SELECT * FROM nieuwsitems WHERE PlaatsID= 1";
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
$titel = $row['Title'];
$item = $row['Description'];
echo "$titel".'<br>';
echo "$item".'<br><hr>';
}
?>
</body>
</html>
Here is connect.php
<?php
$connection = mysqli_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysqli_error($connection));
}
$select_db = mysqli_select_db($connection, 'projectfestival');
if (!$select_db){
die("Database Selection Failed" . mysqli_error($connection));
}
replace in your code that line..
$result = mysqli_query($connection,$query);
when ever i am insert the value it says check data base connection. All the things are correct but it always giving the same error.
I am amking the quiz this page is for adding the question adding. whenever i am inserting the value it says please check DB connection. All the things are correct. User name password database name are also correct.
But same error is occuring
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>!deal Banker</title>
<style type="text/css">
body{
margin:0;
padding:0;
line-height: 1.5em;
}
b{font-size: 110%;}
em{color: red;}
#topsection{
background: #EAEAEA;
height: 90px; /*Height of top section*/
}
#topsection h1{
margin: 0;
padding-top: 15px;
}
#contentwrapper{
float: left;
width: 100%;
}
#contentcolumn{
margin: 0 200px 0 230px; /*Margins for content column. Should be "0 RightColumnWidth 0 LeftColumnWidth*/
}
#leftcolumn{
float: left;
width: 230px; /*Width of left column*/
margin-left: -100%;
background: #C8FC98;
}
#rightcolumn{
float: left;
width: 200px; /*Width of right column*/
margin-left: -200px; /*Set left marginto -(RightColumnWidth)*/
background: #FDE95E;
}
#footer{
clear: left;
width: 100%;
background: black;
color: #FFF;
text-align: center;
padding: 4px 0;
}
#footer a{
color: #FFFF80;
}
.innertube{
margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/
margin-top: 0;
}
/* ####### responsive layout CSS ####### */
#media (max-width: 840px){ /* 1st level responsive layout break point- drop right column down*/
#leftcolumn{
margin-left: -100%;
}
#rightcolumn{
float: none;
width: 100%;
margin-left: 0;
clear: both;
}
#contentcolumn{
margin-right: 0; /*Set margin to LeftColumnWidth*/
}
}
#media (max-width: 600px){ /* 2nd level responsive layout break point- drop left column down */
#leftcolumn{
float: none;
width: 100%;
clear: both;
margin-left: 0;
}
#contentcolumn{
margin-left: 0;
}
}
</style>
</head>
<body>
<div id="maincontainer">
<div id="topsection"><div class="innertube">
<?php
include'menu.php';
?></div></div>
<div id="contentwrapper">
<div id="contentcolumn">
<?php
$conn = mysql_connect("localhost","banker","gaurav#441");
$db = "idealbanker";
$table = "pp";
mysql_select_db($db,$conn);
if(isset($_REQUEST['submit']))
{
if($_POST['question'] == '')
{
echo 'cannot submit field empty';
}
elseif($_POST['answer1'] == '')
{
echo 'cannot submit field empty';
}
elseif($_POST['answer2'] == '')
{
echo 'cannot submit field empty';
}
elseif($_POST['answer3'] == '')
{
echo 'cannot submit field empty';
}
elseif($_POST['answer4'] == '')
{
echo 'cannot submit field empty';
}
elseif($_POST['answer5'] == '')
{
echo 'cannot submit field empty';
}
else
{
function clean($str) {
$str = #trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$question = clean($_POST['question']);
$answer1 = clean($_POST['answer1']);
$answer2 = clean($_POST['answer2']);
$answer3 = clean($_POST['answer3']);
$answer4 = clean($_POST['answer4']);
$correctanswer = clean($_POST['answer5']);
$qry = "INSERT INTO $table( question, answer1, answer2, answer3, answer4, correctanswer )VALUES('$question','$answer1','$answer2','$answer3','$answer4','$correctanswer')";
$result = #mysql_query($qry);
if(!$result)
{
echo 'Question Cannot Submit Check DB Connection';
echo "<br>Add Again";
}
else
{
echo 'Question Submitted Successfully';
}
echo "<br>Add More";
}
}
else
{
echo '<form name="form1" method="post" action="'.$_SERVER['PHP_SELF'].'">
<table width="500" border="0">
<tr>
<td width="100">Question</td>
<td width="242">
<input name="question" type="text" size="60">
</td>
</tr>
<tr>
<td>Answer 1 </td>
<td><input name="answer1" type="text" size="30"></td>
</tr>
<tr>
<td>Answer 2 </td>
<td><input name="answer2" type="text" size="30"></td>
</tr>
<tr>
<td>Answer 3 </td>
<td><input name="answer3" type="text" size="30"></td>
</tr>
<tr>
<td>Answer 4 </td>
<td><input name="answer4" type="text" size="30"></td>
</tr>
<tr>
<td>Correct Answer </td>
<td><input name="answer5" type="text" size="30"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="submit" value="Submit">
</label></td>
</tr>
</table>
</form>
';
}
?>
</div>
</div>
<div id="leftcolumn">
<?php
include 'left.php';
?>
</div>
<div id="rightcolumn">
<?php
include 'right.php';
?>
</div>
<div id="footer"><?php
include'footer.php';
?></div>
</div>
</body>
</html>
Your "check db connection" error message is UTTERLY useless. Never output a fixed unchanging message. Have the DB TELL you why the query failed:
if (!$result) {
die(mysql_error());
}
And note that you're simply ASSUMING the connection is working. You never bother checking the return values of your connection and select_db calls.
The main aim is to display the row when the master row is clicked, there will be multiple records for one single incident id. how to apply jquery function for this type of output. Helps appreciated.
I tried using jexpand function but its not working.
The main aim is to get output like, when one particular row is clicked the remaining set of row with same id should be expanded and vice-versa.
The table results are fetched from mysql database.
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
body { font-family:Arial, Helvetica, Sans-Serif; font-size:0.8em;}
#report { border-collapse:collapse;}
#report h4 { margin:0px; padding:0px;}
#report img { float:right;}
#report ul { margin:10px 0 10px 40px; padding:0px;}
#report th { background:#7CB8E2 url(header_bkg.png) repeat-x scroll center left; color:#fff; padding:7px 15px; text-align:left;}
#childALL { background:#C7DDEE none repeat-x scroll center left; color:#000; padding:7px 15px; }
#report tr.td { background:#fff url(row_bkg.png) repeat-x scroll center left; cursor:pointer; }
#report div.arrow { background:transparent url(arrows.png) no-repeat scroll 0px -16px; width:16px; height:16px; display:block;}
#report div.up { background-position:0px 0px;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#report tr:siblings").show();
$("#report tr:siblings").hide();
$("#report div.arrow").click(function(){
$(this).next("#childALL").toggle();
$(this).find(".arrow").toggleClass("up");
});
//$("#report").jExpand();
});
</script>
</head>
<body>
<center>
<img src="abc.jpg" width="400px" height="100px" />
</center>
<?php
$con= mysqli_connect("172.28.212.145", "root", "root", "xxx");
if(!$con)
{
die('not connected');
}
$con= mysqli_query($con, "Select Incident_id,name,qualification from masterdata;");
?>
<div>
<center>
<table id="report">
<tr>
<th>Incident Id</th>
<th>name</th>
<th>Qualification</th>
<th></th>
</tr>
<?php
$incident = null;
while($row = mysqli_fetch_array($con))
{
if( $row['Incident_id'] != $incident )
{
$incident = $row['Incident_id'];
?>
<tr>
<td>
<?php echo $row['Incident_id']; ?>
</td>
<td>
<?php echo $row['name']; ?>
</td>
<td>
<?php echo $row['JournalUdpdateChanges']; ?>
</td>
<td><div class="arrow"></div></td>
</tr>
<?php } else { ?>
<tr id="childALL">
<td >
<?php echo $row['Incident_id']; ?>
</td>
<td >
<?php echo $row['name']; ?>
</td>
<td >
<?php echo $row['qualification']; ?>
</td>
<td >
<?php echo $row['Priority_im']; ?>
</td>
</tr>
<?php
}
}
?>
</table>
</center>
</div>
</body>
</html>
Bootstrap makes really easy work out of this.
Bootstrap Accordion