How to use INNER JOIN to display data edited by different users - php

I need to create a record in my database that when a user edits the description field it would save it to the database (this currently works). But when the user wants to add another note to the same note added earlier it just saves over the old note. (am using UPDATE for that).
So I would like to know how to achieve this? In my code below you will see that I have two text areas, 1 to display the record from the database and the other to add a new note to the database. Ideally I would to like to display each new note in a new unedited-able text area (sort of like displaying the history of all notes added to the original note.
<?php
require_once '../config.php';
$description_err = "";
if(isset($_POST["id"]) && !empty($_POST["id"])){
$id = $_POST["id"];
$input_description = trim($_POST["descriptionfield"]);
if(empty($input_description)){
$description_err = "Please enter a description.";
} else{
$description= $input_description;
}
if(empty($description_err)){
$sql = "UPDATE newtask SET new_description=? WHERE id=?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "si", $param_description, $param_id);
$param_description = $description;
$param_id = $id;
if(mysqli_stmt_execute($stmt)){
header("location: user-dashboard.php");
exit();
} else{
echo "Something went wrong. Please try again later.";
}
}
mysqli_stmt_close($stmt);
}
mysqli_close($link);
} else{
if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
$id = trim($_GET["id"]);
$sql = "SELECT * FROM newtask WHERE id = ?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "i", $param_id);
$param_id = $id;
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 1){
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$description = $row["new_description"];
} else{
header("location: ../error.php");
exit();
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
mysqli_stmt_close($stmt);
mysqli_close($link);
} else{
header("location: ../error.php");
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-
scale=1" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Support Admin</title>
<link href="../assets/css/bootstrap.css" rel="stylesheet" />
<link href="../assets/css/font-awesome.min.css" rel="stylesheet" />
<link href="../assets/css/style.css" rel="stylesheet" />
<link href="http://fonts.googleapis.com/css?family=Nova+Flat"
rel="stylesheet" type="text/css" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,700,300"
rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="head">
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4">
<a href="../index.php">
<img src="../assets/img/logo1.png" />
</a>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text-center" >
<img src="../assets/img/top-mouse.png " class="header-mid"
/>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<h4><span>Call:</span> 082 </h4>
<h4><span>E-mail:</span> sales</h4>
</div>
</div>
</div>
</div>
<section>
<div class="container">
<div class="row noti-div">
<div class="col-lg-3 col-md-3 col-sm-3 text-center">
</div>
</div>
</div>
</section>
<section id="main">
<div class="container">
<div class="row">
<div class="col-lg-9 col-md-9 col-sm-9 alert alert-info">
<h3 class=" text-center">Update Task</h3>
<div class="hr-div"> <hr />
</div>
<form action="<?php echo
htmlspecialchars(basename($_SERVER['REQUEST_URI']));
?>" method="post">
<div class="form-group col-lg-12 col-md-12 col-sm-12 <?
php echo (!empty($description_err)) ? 'has-error' : ''; ?>">
<label>New Note<textarea name="descriptionfield"
class="formcontrol</textarea>
</div>
<div class="form-group col-lg-12 col-md-12 col-sm-12">
<label>Note Added By </label>
<textarea class="form-control"><?php echo $description; ?></textarea>
</div>
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div class="form-group col-lg-12 col-md-12 col-sm-12">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<a href="index.php" class=" label label-danger">
<strong>LOGOUT</strong> </a>
<div class="list-group">
<a href="#" class="list-group-item active">Quick Links
</a>
My Dashboard
Open Tasks
Pending Tasks
Completed Tasks
Change Password
</div>
<div class="alert alert-success text-center">
<h3>The Notice Board</h3>
No Notice Found !
</div>
<div class="list-group">
Support Categories
Notes
Manuals
General Information
</div>
</div>
</div>
</div>
</section>
<div id="footer">
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4">
<h3>This</h3>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<h3>Contact Details</h3>
</div>
</div>
</div>
</div>
<script src="assets/js/jquery-1.10.2.js"></script>
<script src="assets/js/bootstrap.js"></script>
</body>
</html>
So as you can see in the above code its updating my "newtask" table which I would assume that it needs to update the new table called "updatedata" (this is not in the code above as I am not sure how to add it as well as the id of the two tables)
It then displays the data from the "newtask" table (Original table).
How would I go about to achieve this as per my question above?
Thanks guys
EDIT
So as from the below image I want to have the text from "updatedata" table to link to id 1 from "newtask" table. And then display that text in different div in my page.
I would like to link all the new texts from update data to newtask without over writing the data already in newtask.
So I would to display like the below

Related

Bootstrap Modal Form doesn't insert data in MYSQL

I have a problem with the bootstrap modal, it doesn't insert data in MySQL even though i have a similar modal in the same page that updates the data.. The data is represented in tables with delete and update buttons for each row... Which both work well in the same page.. I am not using Ajax and i was hoping this would work without using any other technologies.. it's kinda odd as the update query uses the same technique and still works regardless
<?php
require_once "../db.php";
session_start();
if(!isset($_SESSION['admin'])){
header('location:login.php');
}
function redirect($url)
{
if (!headers_sent())
{
header('Location: '.$url);
exit;
}
else
{
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>'; exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../css/all.css">
<link rel="stylesheet" href="../css/bootstrap.min.css">
<script src="../js/jquery-3.5.1.min.js"></script>
<script srC="../js/bootstrap.min.js"></script>
<style>
.nav-link{
font-size:18px;
font-weight:bold;
}
</style>
</head>
<body>
<?php
if(isset($_POST['confirmadd'])){
$code = $_POST['voyage'];
$newrow0 = $_POST['depart'];
$newrow1 = $_POST['villedep'];
$newrow2 = $_POST['arrivee'];
$newrow3 = $_POST['villearr'];
$newrow4 = $_POST['price'];
$addTrip = mysqli_query($sql,"INSERT INTO voyage VALUES('$code','$newrow0','$newrow1',$newrow2','$newrow3','$newrow4');");
if($addTrip){
redirect('dashboard.php');
}else{
echo "error";
}
}
?>
<div class="container-fluid bg-info sticky-top">
<div class="row d-flex align-items-center">
<div class="col-6 offset-1">
<h2 class="display-4 text-white">AnouBus</h2>
</div>
<div class="col-4">
<div class="navbar navbar-expand-lg navbar-light navbar-fixed-top">
<ul class="navbar navbar-nav">
<li class="nav-item"><a class="nav-link" href="logout.php">Logout</a></li>
</ul>
</div>
</div>
</div>
</div>
<h1 class="text-center">Your Trips</h1>
<button class="btn btn-primary mx-2" style="float:right;" data-toggle="modal" data-target="#addmodal">Add Trip</button>
<div class="modal fade" id="addmodal">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header"><h2 class="text-center">Update Trip</h2></div>
<div class="modal-body">
<form method="post">
<div class="form-row">
<div class="form-group col-12">
<input type="text" name="voyage" class="form-control" placeholder="Trip Code">
</div>
<div class="form-group col-12">
<input type="text" name="depart" class="form-control" placeholder="Departure Time" ?>
</div>
<div class="form-group col-12">
<input type="text" name="villedep" class="form-control" placeholder="Departure City">
</div>
<div class="form-group col-12">
<input type="text" name="arrivee" class="form-control" placeholder="Arrival Time">
</div>
<div class="form-group col-12">
<input type="text" name="villearr" class="form-control" placeholder="Arrival City">
</div>
<div class="form-group col-12">
<input type="text" name="price" class="form-control" placeholder="Price">
</div>
<div class="form-group col-12">
<input type="submit" class="form-control btn btn-success" name="confirmadd" value="confirm">
</div>
</div>
</form>
</div>
</div>
</div>
</div>

How to have a mysql query print out in bootstrap cards alongside each other

I am trying to get a mysql query of results to print out alongside each other, say 3 in a row and not one below the other.
I have tried stack overlow answers and I cannot find one that helps
<?php
include('db.php');
$results = mysqli_query($conn, "SELECT * FROM contacts");
if(isset($_GET['edit'])){
$id = $_GET['edit'];
$edit_state = true;
$rec =mysqli_query($db_connection, "SELECT * FROM contacts WHERE id=$id ");
$record = mysqli_fetch_array($rec);
$name = $record['name'];
$contact = $record['contact'];
$email = $record['email'];
$id =
$record['id'];
}?>
<div class="container">
<h1 class="my-4">Welcome to Modern Business</h1>
<!-- Marketing Icons Section -->
<?php while ($row = mysqli_fetch_array($results)){ ?>
<div class="row">
<div class="col-lg-4 mb-4">
<div class="card h-100">
<h4 class="card-header"><?php echo $row['name']; ?></h4>
<img class="img_size" src="images/dog2.jpg" alt="Card image top">
<div class="card-body">
<p class="card-text"><?php echo $row['contact']; ?></p>
</div>
<div class="card-footer">
Learn More
</div>
</div>
</div>
</div>
<?php } ?>
right now, the cards are printing out but not inline, one below the other. I would like them to print horizontally.
any help at all would be appreciated, I am new to php.
This is the wrong outcome, I want them beside each other
PHP code:
<?php
include('dbconn.php'); // include database connection
$output="";
$selQuery = "select * from tbl_name";
$exeQuery = mysqli_query($conn,$selQuery);
$output="<h2>Welcome to Modern Business
<div class='container'>
<div class='row'>";
while($row = mysqli_fetch_array($exeQuery)) {
$name = $row['name'];
$desciption = $row['desciption'];
$ephoto = $row['ephoto'];
$output.="<div class='col-sm-4'>
<h4 class='card-header'>$name</h4>
<img class='img_size' src='$ephoto' alt='Card image top'>
<p>$desciption</p>
<a href='#' class='btn btn-primary'>Learn More</a>
</div>";
}
$output.="</div></div></h2>";
echo $output;
?>
HTML markup including bootstrap links:
<html>
<head>
<title>Bootstrap Example</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.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
</html>
You need to put the while loop before the following div and end it when div ends.
<?php while($row=mysqli_fetch_array($results)){ ?>
<div class="card h-100">
<h4 class="card-header">
<?php echo $row['name']; ?></h4>
<img class="img_size" src="images/dog2.jpg" alt="Card image top">
<div class="card-body">
<p class="card-text"><?php echo $row['contact']; ?></p> </div>
<div class="card-footer">
<a href="#" class="btn btn-primary">
Learn More
</a>
</div>
</div>
<?php } ?>
Also replace col-lg-4 with col-lg-12
Try this and update me.

PHP HTTP Header appears multiple times with the same message

I have a page named as add_administrator.php in this php i am checking if the status value is given using the GET method and if so that display the header with the value in status Now i am getting the value form a page add_administrator_code.php But the problem is that i am getting the header more then once i.e. Three times with the same message What should i do?
here is the add_administrator.php
<?php
session_start();
session_regenerate_id(true);//regenerating session id on every reload or refresh so to avoid the session hijack
if (isset($_GET['status'])) {
$sta = $_GET['status'];
echo "<script type='text/javascript'>alert('$sta');</script>";
}
if($_SESSION['alogin'])
{
}
else
{
header("location:../index.php");
}
?>
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Smart Ambulance</title>
<link rel="stylesheet" href="assets/css/normalize.css">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/themify-icons.css">
<link rel="stylesheet" href="assets/css/flag-icon.min.css">
<link rel="stylesheet" href="assets/css/cs-skin-elastic.css">
<!-- <link rel="stylesheet" href="assets/css/bootstrap-select.less"> -->
<link rel="stylesheet" href="assets/scss/style.css">
<link href="assets/css/lib/vector-map/jqvmap.min.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'>
<!-- Fav and touch icons -->
<?php include 'logo.php';?>
</head>
<body>
<!-- Left Panel -->
<aside id="left-panel" class="left-panel"style="background-color:#004466">
<nav class="navbar navbar-expand-sm navbar-default">
<?php include 'left_menu.php';?>
</nav>
</aside><!-- /#left-panel -->
<!-- Left Panel -->
<!-- Right Panel -->
<div id="right-panel" class="right-panel">
<!-- Header-->
<header id="header" class="header">
<?php include 'header_menu.php';?>
</header><!-- /header -->
<!-- Header-->
<div class="breadcrumbs">
<div class="col-sm-4">
<div class="page-header float-left">
<div class="page-title">
<h1>Dashboard</h1>
</div>
</div>
</div>
<div class="col-sm-8">
<div class="page-header float-right">
<div class="page-title">
<ol class="breadcrumb text-right">
<li class="active">Dashboard / User Details / Adminsitrator / Add</li>
</ol>
</div>
</div>
</div>
</div>
<div class="content mt-3">
<!--********************************************** Content Start **********************************************-->
<div class="col-lg-6">
<div class="card">
<div class="card-header">
<strong>Add Adminsitrator</strong>
</div>
<div class="card-body card-block">
<form action="add_administrator_code.php" method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="row form-group">
<!--<div class="col col-md-3"><label class=" form-control-label">Static</label></div> -->
<div class="col-12 col-md-9">
<!-- <p class="form-control-static">Username</p> -->
</div>
</div>
<div class="row form-group">
<div class="col col-md-3"><label for="text-input" class=" form-control-label">Name</label></div>
<div class="col-12 col-md-9"><input type="text" id="adm_name" name="adm_name" placeholder="Name" class="form-control"><small class="form-text text-muted"></small></div>
</div>
<div class="row form-group">
<div class="col col-md-3"><label for="email-input" class=" form-control-label">Contact Number</label></div>
<div class="col-12 col-md-9"><input type="text" id="adm_mob" name="adm_mob" placeholder="Enter Contact Number" class="form-control"><small class="help-block form-text"></small></div>
</div>
<div class="row form-group">
<div class="col col-md-3"><label for="email-input" class=" form-control-label">Email Id</label></div>
<div class="col-12 col-md-9"><input type="email" id="adm_mail_id" name="adm_mail_id" placeholder="Enter Email" class="form-control"><small class="help-block form-text"></small></div>
</div>
<div class="row form-group">
<div class="col col-md-3"><label for="password-input" class=" form-control-label">Password</label></div>
<div class="col-12 col-md-9"><input type="password" id="adm_pass" name="adm_pass" placeholder="Password" class="form-control"><small class="help-block form-text">Press the Generate Button to generate password</small></div>
</div>
<div class="row form-group">
<div align =center class="col col-md-1"><input type="checkbox" onclick="togglepassword()" ></div>
<label for="text-input" class=" form-control-label">Show Password</label>
</div>
<div>
<button type="submit" class="btn btn-primary btn-sm">
<i class="fa fa-dot-circle-o"></i> Submit
</button>
<button type="reset" class="btn btn-danger btn-sm">
<i class="fa fa-ban"></i> Reset</i>
</button>
<button type="button" onclick="generate()" class="btn btn-success btn-sm">Generate</button>
</div>
</div>
<!--********************************************** Content End **********************************************-->
</div>
</div><!-- /#right-panel -->
<!-- Right Panel -->
<script src="assets/js/vendor/jquery-2.1.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="assets/js/plugins.js"></script>
<script src="assets/js/main.js"></script>
<script src="assets/js/lib/chart-js/Chart.bundle.js"></script>
<script src="assets/js/dashboard.js"></script>
<script src="assets/js/widgets.js"></script>
<script src="assets/js/lib/vector-map/jquery.vmap.js"></script>
<script src="assets/js/lib/vector-map/jquery.vmap.min.js"></script>
<script src="assets/js/lib/vector-map/jquery.vmap.sampledata.js"></script>
<script src="assets/js/lib/vector-map/country/jquery.vmap.world.js"></script>
<script>
( function ( $ ) {
"use strict";
jQuery( '#vmap' ).vectorMap( {
map: 'world_en',
backgroundColor: null,
color: '#ffffff',
hoverOpacity: 0.7,
selectedColor: '#1de9b6',
enableZoom: true,
showTooltip: true,
values: sample_data,
scaleColors: [ '#1de9b6', '#03a9f5' ],
normalizeFunction: 'polynomial'
} );
} )( jQuery );
</script>
<script>
function togglepassword() {
var x = document.getElementById("adm_pass");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
<script>
function generate(){
//set password length/complexity
let complexity = 8;
//possible password values
let values = "ABCDEFGHIJKLMNOPQRSTUVWZYZabcdefghijklmnopqrstuvwxyz1234567890!##$%^&*()_+";
let password = "";
//create for loop to choose password characters
for(var i = 0; i <= complexity; i++){
password = password + values.charAt(Math.floor(Math.random() * Math.floor(values.length - 1)));
}
//add password to textbox/display area
document.getElementById("adm_pass").value = password;
}
</script>
</body>
</html>
here is the add_administrator_code.php
<?php include '../database.php';
// create a variable
$adm_name=$_POST['adm_name'];
$adm_mob=$_POST['adm_mob'];
$adm_mail_id=$_POST['adm_mail_id'];
$adm_pass=$_POST['adm_pass'];
mysqli_query($con,"INSERT INTO admin_details (adm_name,adm_mob,adm_mail_id,adm_pass)
VALUES ('$adm_name','$adm_mob','$adm_mail_id','$adm_pass')");
if(mysqli_affected_rows($con) > 0){
$status = "New Admin added Sucessfully";
header("location: add_administrator.php?status=".$status);
} else {
$status = "Error in adding New Admin";
header("location: add_administrator.php?status=".$status);
}
?>
You need to stop the script after you redirect to make sure nothing else runs:
{
header("location: ...");
exit;
}
Also, your code is vulnerable to both XSS and SQL injection. Read about escaping HTML and prepared statements.
for preventing loop the session start: instead of
session_start();
session_regenerate_id(TRUE);
change to this:
if (session_status() == PHP_SESSION_NONE) {
session_start();
session_regenerate_id(TRUE);
}
update me with the result,
Note: dont forget to normalize the $_GET method for the security
improvement

update database field based on what the user selects via dropdown

so on my site, the admin can assign a job to a user and that job will automatically have the status: waiting to be accepted. I have now created a drop down box on the job page so that the user can either decline or accept the job with that drop down box. however im unsure of the coding needed to update the database field based on what the user selects.
what im aiming for is: the user selects a status, then clicks the change button to update the status of the job.
current code:
<?php
if(!isset($_SESSION))
{
session_start();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Latest compiled and minified CSS -->
<title>Tyre Hire</title>
<link rel="stylesheet" type="text/css" href="css/mystyle.css"/>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<header>
<img class="img-responsive" src ="images/Logo.png" alt ="logo"/>
</header>
</div>
</div>
<?php
require_once ("config.inc.php");
try
{
$conn = new PDO(DB_DATA_SOURCE, DB_USERNAME, DB_PASSWORD);
}
catch(PDOException $exception)
{
echo "Oh no, there was a problem" . $exception->getMessage();
}
if(!isset($_SESSION["username"]))
{
//user tried to access the page without logging in
header( "Location: add.php" );
}
$login = $_SESSION['user_ID'];
$query = "SELECT * FROM login WHERE user_ID = :user_ID";
$term = $conn->prepare($query);
$term->bindValue(':user_ID', $login);
$term->execute();
$login = $term->fetch(PDO::FETCH_OBJ);
$status = "Waiting to be accepted";
$status2 = "Accept Job";
$status3 = "Decline Job";
if(isset($_SESSION["username"]))
{
echo "Welcome, you are now logged in as <b>".$_SESSION['username']."</b> <img class='clientView' src='images/loginIcon.png' alt='client'>"; }
else {
echo "You are currently not logged in";
};
?>
<div class="row">
<div class="col-xs-12">
<br>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="main.php">Tyre Hire</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li> Home <span class="glyphicon glyphicon-print"></span></li>
<li> Search <span class="glyphicon glyphicon-print"></span></li>
<li><?php echo "<a href='all-jobs.php?user_id=" . $login->user_ID . "&occupation=". $login->occupation ."''> Current Jobs <span class='glyphicon glyphicon-print'></span></a>";?> </li>
<li> Register Interest <span class="glyphicon glyphicon-print"></span></li>
<li> Logout <span class="glyphicon glyphicon-print"></span></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="right">
<h2>Current Jobs</h2>
<p>One of the best sites to find the best qualified and skilled drivers in the UK.</p>
<form class="form-horizontal formApply" action="" method="POST">
<h2><u>Job Details </u></h2>
<div class="form-group">
<?php
echo "<h3>Job role :".$worker->jobTitle."</h3>";
echo "<ul>";
echo "<h3> About the role </h3>";
echo "<li><b>Company Name:</b>".$worker->company."</li>";
echo "<li><b>Job Description:</b>".$worker->jobDescription."</li>";
echo "<h3>shift pattern</h3>";
echo "<li><b>Start Time: </b>".$worker-> startTime."</li>";
echo "<li><b>End Time: </b>".$worker-> endTime."</li>";
echo "<br />";
echo "<li><b>start Date:</b>".$worker->startDate."</li>";
echo "<li><b>Job Expiry Date:</b>".$worker->expiry."</li>";
echo "<b><h4>Current Status: </b>".$worker->status."</h4>";
echo "</ul>";
?>
<div class="form-group">
<label class="control-label col-sm-2" for="search"> Status</label>
<div class="col-sm-3">
<select class="form-control" name="status" >
<option value="<? echo $status;?>"><?php echo $status;?></option>
<option value="<? echo $status2;?>"><?php echo $status2;?></option>
<option value="<? echo $status3;?>"><?php echo $status3;?></option>
</select>
<input type="hidden" value="<?php echo $status; ?>" name="status">
</div>
<div class="form-group">
<!--<label class="control-label col-sm-2" for="search"></label> -->
<div class="col-sm-3">
<!-- <select class="form-control" name="status" >
<option value="<? echo $job;?>"><?php echo $job;?></option>
</select> -->
<input type="hidden" value="<?php echo $job; ?>" name="job_id">
</div>
</div>
</div>
<input class = "buttonA" type="submit" name="Apply" value="Change status"/>
</div>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div id="BottomArea">
<h4> Recruitment Agencies </h4>
<div class="row">
<div class="col-xs-3">
<img class="FxPic img-responsive" src="images/fxpic.png" alt="fx-logo">
</div>
<div class="col-xs-3">
<img class="driverhire img-responsive" src="images/driverhire.jpg" alt="driverhire">
</div>
<div class="col-xs-3">
<img class="logi img-responsive" src="images/logi.png" alt="logi-logo">
</div>
<div class="col-xs-3">
<img class="pebble img-responsive" src="images/noel.png" alt="pebbles">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<footer>
<img id="logoFoot" src ="images/Logo.png" alt ="logo"/>
<p><b>Address: 5A twickenham road, london SJ5 7AE</b></p>
</footer>
</div>
</div>
<script src=myjs.js></script>
</div>
</body>
</html>
attempted it after reading the update manual, no errors but upon clicking the button it gives a blank page.:
<?php
include ("db_fncs.php");
try{
$conn = new PDO(DB_DATA_SOURCE, DB_USERNAME, DB_PASSWORD);
}
catch (PDOException $exception)
{
echo "Oh no, there was a problem" . $exception->getMessage();
}
$status = $_POST["status"];
$job = $_POST['job_id'];
print_r($_POST);
$query = "UPDATE jobs SET status = :status WHERE job_id = :job_id AND status = :status";
// Prepare statement
$stmt = $conn->prepare($query);
$stmt->bindValue(':status', $status);
$stmt->bindValue(':job_id', $job);
// execute the query
$stmt->execute();
//$stmt->commit();
echo $stmt->rowCount() . " records UPDATED successfully";
?>
The basic syntax for UPDATE is:
UPDATE <my_table>
SET <update_column_name> = <some_value>
WHERE <identifying_column_name> = <some_value>
In your case, it would probably look something like:
UPDATE jobs
SET status = <new_job_status>
WHERE userid = <user_id>
AND jobid = <job_id>

Webpage only accessible when logged in (PHP)

I'm currently having some issues with creating a webpage that's only accessible once a user has logged in.
I've looked through various threads here, but to no avail. Any help with this would be greatly appreciated.
Here's my code:
login.php
<?php
Include('connect.php');
if (isset($_REQUEST['Submit']))
{
if($_REQUEST['user_id']=="" || $_REQUEST['password']=="")
{
echo " Field must be filled";
}
else
{
$sql1= "select * from student where email= '".$_REQUEST['user_id']."' && password ='".$_REQUEST['password']."'";
$result=mysql_query($sql1)
or exit("Sql Error".mysql_error());
$num_rows=mysql_num_rows($result);
if($num_rows>0)
{
session_start($_SESSION['Login']);
Echo "You have logged in successfully";
header("Location: statistics.html");
}
else
{
echo "Wrong username or password.";
}
}
}
?>
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>PHP Login Form</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<div class="container">
<div class="row" style="margin-top:20px">
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
<form name="form_login" method="post" action="login.php" role="form">
<fieldset>
<h2>Please Sign In</h2>
<hr class="colorgraph">
<div class="form-group">
<input name="user_id" type="text" id="user_id" class="form-control input-lg" placeholder="Email Address">
</div>
<div class="form-group">
<input type="password" name="password" id="password" class="form-control input-lg" placeholder="Password">
</div>
<span class="button-checkbox">
<button type="button" class="btn" data-color="info">Remember Me</button><!-- Additional Option -->
<input type="checkbox" name="remember_me" id="remember_me" checked="checked" class="hidden">
<hr class="colorgraph">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<input type="submit" name="Submit" value="Login" class="btn btn-lg btn-success btn-block">
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</body>
</html>
And statistics.html (Page that should only be accessible when logged in)
<?php
include ("login.php")
session_start();
if(!isset($_SESSION['Login']))
{
header("Location:login.php");
die();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Personal Website</title>
<link rel="stylesheet" href="../../CSS/stylesheetmain.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
</head>
<body>
<!--Navigation Bar-->
<div class="row">
<div class="darkgrey column col-md-8 col-md-offset-2 col-xs-12 col-s-12">
<nav class="navbar navbar-background-color">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"><!--Reference: Bootstrap, 2015. getbootstrap.com. [Online] Available at: http://getbootstrap.com/ [Accessed 01 April 2015]-->
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../index.html"></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li><!--Edits made: Removed active button -->
<li>About Me</li>
<li>Blog</li>
<li>Contact Me</li>
<li>Login</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
</div>
<div class="row">
<div class="navbarbottom column col-md-8 col-md-offset-2 col-xs-12 col-s-12"></div>
</div>
<!--Page Title-->
<div class="row">
<div class="title mediumbluetext col-md-8 col-md-offset-2 col-xs-0 col-s-0">
<center><h1>Statistics</h1></center>
</div>
</div>
<!--Main Body-->
<div class="row">
<!--Left Column Spacer-->
<div class="maintextleftbackground column col-md-2 col-xs-0 col-s-0">
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-52f8f8c0164b330f" async="async"></script>
</div>
<!--Middle Column-->
<div class="maintext80 column col-md-8 col-xs-12 col-s-8 col-s-offset-2"><br>
<div id="main-chart-container"></div>
<div id="breakdown-chart-container"></div>
<div id="embed-api-auth-container"></div>
<div id="view-selector-container"></div>
</div>
<!--Right Column Spacer-->
<div class="maintextrightbackground column col-md-2 col-xs-0 col-s-0">
</div>
</div>
<!--Footer Bar-->
<div class="row">
<div class="darkgrey column col-md-8 col-md-offset-2 col-xs-12 col-s-12">
<nav class="navbar-background-color">
<div class="container-fluid">
<p class="navbar-text navbar-right">SiteMap</p>
</div>
</nav>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script>
(function(w,d,s,g,js,fs){
g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
js.src='https://apis.google.com/js/platform.js';
fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
}(window,document,'script'));
</script>
</body>
</html>
No matter what I try, I can't seem to get the code to work. The files are in the same directory as well.
Any help with this would be greatly appreciated.
A few things wrong here but you're on the right track.
You are VERY susceptible to SQL injection. Please read about it.
Your form uses POST so your PHP should use $_POST and not $_REQUEST
You cannot set a session variable by passing it through to session_start. You need to set the variable like so: $_SESSION['isLoggedIn'] = true.
You are echoing right before you issue a header command. You cannot output anything before redirecting.

Categories