Timer and Navigation in online aptitude test - php

I am a novice in php web app dev.I am designing an online aptitude test. But i met some problem that i couldnt proceed further. This are
The timer restart itself when i click on the navigation for next question
When a question is not answered and the next button is clicked, an eror pops out.
I have poor knowlege of ajax and jquery but belive they can be usedful. Help me in what ever way please to achieve my goal.
below are my codes:
//test.php
<?php
session_start();
// th value of q is given as 1 from the start quiz button of the users home page
if (isset($_GET['q'])) {
$number = (int)$_GET['q'];
}else{
header('Location : index.php');
}
if(!isset($_SESSION['user_session']))
{
header("Location: ../login.html");
}
//connection to the db
include_once '../dbconfig.php';
$stmt = $db_con->prepare("SELECT * FROM tbl_admin WHERE aid=:uid");
$stmt->execute(array(":uid"=>$_SESSION['user_session']));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
$qr = $db_con->prepare("SELECT * FROM questions ");
$qr->execute();
$count = $qr->rowCount();
$qrow=$qr->fetch(PDO::FETCH_ASSOC);
$qst = $db_con->prepare("SELECT * FROM questions where quesNo='$number' ");
$qst->execute();
$qstrow=$qst->fetch(PDO::FETCH_ASSOC);
?>
<body>
<header id="header">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="#"><div id="hms">00:05:00</div></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
</header>
<div class="item active">
<?php
//Code to process score(saved is session variable) and move to the next question
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$ans=$_POST['ans'];
$number=$_POST['number'];
$next = $number+1;
if (!isset($_SESSION['score'])){
$_SESSION['score'] = '0';
}
$qrs = $db_con->prepare("SELECT * FROM questions ");
$qrs->execute();
$counts = $qrs->rowCount();
$sqlans= "SELECT * FROM answers where quesNo='$number' and right_ans='1'";
foreach ($db_con->query($sqlans) as $rowsans) {
if($ans==$rowsans['ans_id']){
$_SESSION['score']++;
}
if($number==$count){
header('location:final.php');
exit();
}else{
header('location:test.php?q='.$next);
}
}
}
?>
<div class="containerx" style="height:530px;">
<div class="image" style="width:100%">
<div class="main">
<hl> Question <?php echo $number ?> of <?php echo $count; ?></hl>
<div class="test">
<form method="post" action="">
<table>
<tr>
<td coLspan=”2”>
<h3>Que <?php echo $qstrow['quesNo']; ?>: <?php echo $qstrow['ques']; ?></h3>
</td>
</tr>
<?php
$sqla= "SELECT * FROM answers where quesNo='$number'";
foreach ($db_con->query($sqla) as $rowsa) {
?>
<tr>
<td>
<input type="radio" name="ans" value=" <?php echo $rowsa['ans_id']; ?>"/> <?php echo $rowsa['ans']; ?>
</td>
</tr>
<?php } ?>
<tr>
<td>
<input type="submit" id="btn_next" name="submit" value="Next Question"/>
<input type="hidden" name="number" value="<?php echo $number ?>"/>
</td>
</tr>
</table>
<!--<div class="caption page-carousel pull-left">-->
</div>
<div class="site-full-width darkbluecolor">
<div class="container">
</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
function count(){
var startTime = document.getElementById('hms').innerHTML;
var pieces= startTime.split(":");
var time = new Date();
time.setHours(pieces[0]);
console.log( time.setMinutes(pieces[1]));
time.setSeconds(pieces[2]);
console.log( time.setMinutes(pieces[1]));
var timedif = new Date(time.valueOf() - 1000);
var newTime=timedif.toTimeString().split(" ")[0];
document.getElementById('hms').innerHTML=newTime;
if(newTime==="00:00:00"){
clearTimeout(time_out);
$('#btn_next').css('display',' none');
alert("Sorry Your time is over");
}
time_out= setTimeout(count,1000);
}
count();
});
</script>

Related

Bootstrap Cards Filter PHP/AJAX Problems

I have a page of a website which has bootstrap cards on. The cards are generated dynamically, but I wanted to add a filter section. I am trying to use AJAX to acheive this, I have got to a point where when you select a checkbox it triggers the loader gif but then that loader gif doesn't disapear. Through my hours of debugging I can see that its the page that the AJAX call is calling that is the problem, but I just can't see what the issue is and I am not getting errors or anything in the console.
If anyone has any ideas I would really appreciate it, I have pasted my code below, also I am aware my sql queries are currently open to injection, just want to get it to work first.
<body>
<?php include("PHP/header.php"); ?>
<div class="container-fluid">
<div class="container" style="margin-top: 2%; text-align: center;">
<h1>Title goes here</h1>
Some tetx
<br/>
<br/>
<br/>
Filter Reviews:
<ul class="list-group">
<?php
$search = $conn->prepare("SELECT DISTINCT reviewcat FROM review_db ORDER BY reviewcat");
$search->execute();
while ($row = $search->fetch(PDO::FETCH_ASSOC)) {
?>
<li class="list-group-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input product_check" value="<?=$row['reviewcat'];?>" id="reviewcat"> <?=$row['reviewcat']; ?>
</label>
</div>
</li>
<?php } ?>
</ul>
</div>
<br/><br/>
<div class="row-fluid ">
<h5 class="text-center" id="textChange"> All Products </h5>
<hr>
<div class="text-center">
<img src="Images/loader.gif" id="loader" width="100" style="display: none">
</div>
<div id="result" class="card-deck card_group_style pt-4" >
<?php
$res_data = $conn->prepare("SELECT * FROM review_db");
$res_data->execute();
?>
<?php while ($row = $res_data->fetch(PDO::FETCH_ASSOC)) {// Important line !!! Check summary get row on array .. ?>
<div class="col-sm-6 col-lg-3 py-2">
<div class="card mb-4">
<img class="card-img-top card-images " src="Images/Reviews/<?php echo $row['reviewimage1'];?>" alt="<?php echo $row['reviewtitle'];?>" >
<div class="card-body">
<h5 class="card-title"><?php echo $row['reviewtitle'];?></h5>
<p class="card-text"><?php echo $row['reviewsynop'];?></p>
<a href="Reviews/review-content.php?id=<?php echo $row['id'];?>&reviewtitle=<?php echo $row['reviewtitle'];?>" class="btn btn-primary my-4" >Read More</a>
<div class="card-footer" style="padding: 1%;">
<small class="text-muted">Submitted: <?php
$my_date = $row['reviewsub'];
$date = DATE("d/m/Y",strtotime($my_date));
echo $date;?></small>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php include("PHP/footer.php"); ?>
</div>
</body>
<?php include("PHP/js.php"); ?>
<script>
$(document).ready(function(){
$('#link-review,#link-footer-review').addClass('active');
});
</script>
<script type="text/javascript">
$(document).ready(function(){
function get_filter_text(text_id){
var filterData = [];
$('#'+text_id+':checked').each(function(){
filterData.push($(this).val());
});
return filterData;
}
$(".product_check").click(function(){
$("#loader").show();
var action = 'data';
var reviewcat = get_filter_text('reviewcat');
$.ajax({
method:'POST',
url:'reviewaction.php',
data:{action:action,reviewcat:reviewcat},
success:function(response){
$("#result").html(response);
$("#loader").hide();
$("#textChange").text("Filtered Reviews");
}
});
});
});
</script>
</html>
reviewaction.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include_once $_SERVER['DOCUMENT_ROOT'] . '/Private/db.php';
// $stmt = $conn->prepare("SELECT * FROM blogdata ORDER BY blogsub DESC");
// $stmt->execute();
?>
<?php
if(isset($_POST['action'])){
$sql = "SELECT * FROM review_db WHERE reviewcat !=''";
$revsearch = $conn->prepare($sql);
$revsearch->execute();
$output='';
if($revsearch->num_rows>0){
while ($row = $revsearch->fetch(PDO::FETCH_ASSOC)) {
$output .= '
<div class="col-sm-6 col-lg-3 py-2">
<div class="card mb-4">
<img class="card-img-top card-images " src="Images/Reviews/'. echo $row['reviewimage1'];.'" alt="'. echo $row['reviewtitle'];.'" >
<div class="card-body">
<h5 class="card-title">'. echo $row['reviewtitle'];.'</h5>
<p class="card-text">'. echo $row['reviewsynop'];.'</p>
<a href="Reviews/review-content.php?id='. echo $row['id'];.'&reviewtitle='. echo $row['reviewtitle'];.'" class="btn btn-primary my-4" >Read More</a>
<div class="card-footer" style="padding: 1%;">
<small class="text-muted">Submitted: '.
$my_date = $row['reviewsub'];
$date = DATE("d/m/Y",strtotime($my_date));
echo $date;.'</small>
</div>
</div>
</div>
</div>
';
}
else{
$output = "<h3>No Reviews Found!</h3>";
}
echo $output;
}
?>
I have actually found something in the server error log, I was stupidly only use dev tools on firefox, but have found that in the reviewaction.php script I had left semicolons in and had also missed a closing bracket. There are still some other problems, which I can fix, just couldn't work out why it wasn't firing.

Storing order details in MYSQL database using php

I'm trying to learn php and MYSQL through developing an eCommerce website. So far the experience with these new languages are really good, but I'm stuck on one of my ideas. I have managed to add the order details to my database, however it adds only a product at a time. Originally what I wanted to do is to add more than a product and store it in a database.
For an example let's say an user wants to buy 5 items. How can I store this into my database. With my current code this just add as a single product with the total of 5 products.(Even the quantity is not adding up).
I'm not sure whether my code is correct. Any suggestions on this is really appreciated. (Please feel free to modify code, it will be really helpful)
Following is the code I'm using to add orders to database.
<div class="col-md-12">
<h4 class="text-center">Paypal Intergration Goes Here.</h4>
<img src="./images/paywith_paypal.png" class="img-responsive center-block" alt="Pay With Paypal">
<?php
// Getting product details
$total = 0;
global $con;
$ip = getIp();
$sel_price = "SELECT * FROM zeus_limited.cart WHERE ip_address='$ip'";
$run_price = mysqli_query($con, $sel_price);
while($p_price=mysqli_fetch_array($run_price)){
$product_id = $p_price['cart_product_id'];
$product_price = "SELECT * FROM zeus_limited.product WHERE product_id='$product_id'";
$run_product_price = mysqli_query($con,$product_price);
while ($prod_price = mysqli_fetch_array($run_product_price)){
$product_price = array($prod_price['product_price']);
$product_id = $prod_price['product_id'];
$pro_name = $prod_price['product_title'];
$values = array_sum($product_price);
$total +=$values;
}
}
// Getting Quantity from cart
$get_quantity = "SELECT * FROM zeus_limited.cart WHERE cart_product_id='$product_id'";
$show_quantity = mysqli_query($con, $get_quantity);
$row_qty = mysqli_fetch_array($show_quantity);
$quantity = $row_qty['quantity'];
if($quantity == 0){
$quantity = 1;
}
else {
$quantity = $quantity;
$total = $total * $quantity;
}
// Getting Customer details
$user = $_SESSION['customer_email'];
$get_customer = "SELECT * FROM zeus_limited.customer WHERE customer_email='$user'";
$show_customer = mysqli_query($con, $get_customer);
$row_c = mysqli_fetch_array($show_customer);
$customer_id = $row_c['customer_id'];
$customer_email = $row_c['customer_email'];
$customer_name = $row_c['customer_fname'];
$trx_id = mt_rand();
$currency = 'USD';
$invoice = mt_rand();
// Insert data to ORDER table
$add_order = "INSERT INTO zeus_limited.orders (order_product_id, order_customer_id, order_quantity, invoice_no, status, order_date) VALUES ('$product_id','$customer_id','$quantity','$invoice','in Progress',NOW())";
$run_order = mysqli_query($con, $add_order);
// Insert data to PAYMENT table
$add_payment = "INSERT INTO zeus_limited.payment (amount, payment_customer_id, payment_product_id, trx_id, payment_currency, payment_date) VALUES ('$total','$customer_id','$product_id','$trx_id','$currency',NOW())";
$run_payment = mysqli_query($con, $add_payment);
// Removing products from CART
$empty_cart = "DELETE FROM zeus_limited.cart";
$show_customerart = mysqli_query($con, $empty_cart);
if($total == $total){
echo "<div class='text-center'>";
echo "<h3>Welcome:" . $_SESSION['customer_email']. "<br>" . "Hooray! Your Payment was successful!</h3>";
echo "<a href='./customer/my_account.php'>Go to your Account</a><br>";
echo "</div>";
}
else {
echo "<div class='text-center'>";
echo "<h4>Welcome Guest, Payment process failed... Please try again</h4><br>";
echo "<a href='/shop_products.php'>Go to Back to shop</a>";
echo "</div>";
}
?>
</div>
I'm attaching the cart code as well.(if it's needed)
<?php
session_start();
require_once './includes/init.php';
require_once './functions/functions.php';
echo getCart();
?>
<!DOCTYPE html>
<html>
<head>
<title>Zeus Pvt. Ltd</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/font-awesome.min.css" />
<link rel="stylesheet" href="css/style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
<script src="js/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="header">
<div class="container container-bg">
<div class="row">
<div class="col-md-4"><img src="images/logo.png" class="img-responsive" alt="Responsive image"></div>
<div class="col-md-5"></div>
<div class="col-md-3">
<div class="zeus_cart">
<div class="cart_bg">
<ul class="cart">
<i class="cart_icon"></i><p class="cart_desc"><?php getTotalCartPrice() ?><br><span class="yellow"><?php getTotalItems() ?></span></p>
<div class='clearfix'></div>
</ul>
<ul class="product_control_buttons">
<li><img src="images/close.png" alt=""/></li>
<li>Edit</li>
</ul>
<div class='clearfix'></div>
</div>
<ul class="quick_access">
<li class="view_cart">View Cart</li>
<li class="check">Checkout</li>
<div class='clearfix'></div>
</ul>
</div>
</div>
</div>
</div>
<div class="container container-bg">
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="active">Shop Products</li>
<li>My Account</li>
<li>Contact Us</li>
<li>
<?php
if(!isset($_SESSION['customer_email'])){
echo 'Login';
}
else {
echo 'Logout';
}
?>
</li>
<li class="welcome"><a>Welcome <?php echo getUsername(); ?></a></li>
</ul>
<form method="get" action="results.php" enctype="multipart/form-data" class="navbar-form navbar-right">
<div class="form-group search">
<input type="text" name="user_query" class="form-control" placeholder="Search Products">
</div>
<button type="submit" class="btn btn-default btn-search"></button>
</form>
</div>
</div>
</div>
</nav>
</div>
<div class="main">
<div class="container container-bg">
<div class="row">
<div class="col-md-12">
<div class="shoppingcart-title">
<h4 class="text-center sidebar-main-menu">Shopping Cart</h4>
<div class="table-responsive">
<form action="" method="POST" enctype="multipart/form-data">
<table class="table">
<thead>
<tr>
<th>Product No.</th>
<th>Product(s)</th>
<th>Name</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Sub Total</th>
<th>Remove</th>
</tr>
</thead>
</tbody>
<?php
global $con;
$total = 0;
$ip = getIp();
$select_price = "SELECT * FROM zeus_limited.cart WHERE zeus_limited.cart.ip_address='$ip'";
$run_price = mysqli_query($con, $select_price);
while ($product_price = mysqli_fetch_array($run_price)) {
$product_id = $product_price['cart_product_id'];
$product_quantity = $product_price['quantity'];
$product_price = "SELECT * FROM zeus_limited.product WHERE zeus_limited.product.product_id ='$product_id'";
$run_product_price = mysqli_query($con, $product_price);
while ($product_new_price = mysqli_fetch_array($run_product_price)) {
$product_price = array($product_new_price['product_price']);
$product_id = $product_new_price['product_id'];
$product_image = $product_new_price['product_image_carousel'];
$product_title = $product_new_price['product_title'];
$unit_product_price = $product_new_price['product_price'];
$values = array_sum($product_price);
$total += $values * $product_quantity;
?>
<tr>
<td><?php echo $product_id; ?></td>
<td><img src="images/products/<?php echo $product_image; ?>" </td>
<td><?php echo $product_title; ?></td>
<td><input id="" type="text" name="quantity[<?php echo $product_id; ?>]" size="5" value="<?php echo $product_quantity; ?>" style="text-align:center;"/>
<input type="hidden" name="product_id[<?php echo $product_id; ?>]" value="<?php echo $product_id; ?>"
</td>
<!--Updating the quantity-->
<?php
$ip = getIp();
if (isset($_POST['update_cart'])){
foreach ($_POST['product_id'] as $pid => $id) {
$product_id = $id;
$product_quantity = $_POST['quantity'][$pid];
$update_products = "UPDATE zeus_limited.cart SET quantity = '$product_quantity' WHERE cart_product_id = '$product_id' AND ip_address = '$ip';";
$run_update = mysqli_query($con, $update_products);
}
if($update_products){
echo "<script>window.open('cart.php','_self')</script>";
}
}
?>
<td><?php echo 'Rs '. $unit_product_price; ?></td>
<td><?php echo 'Rs '.$unit_product_price * $product_quantity ?></td>
<td><input type="checkbox" name="remove[]" value="<?php echo $product_id; ?>"/></td>
</tr>
</tbody>
<?php } } ?>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th>Grand Total: </th>
<th><?php echo 'Rs '. $total ?></th>
<th></th>
</tr>
</thead>
</table>
<div class="cart_buttons">
<input type="submit" name="update_cart" value="Update Cart"/>
<input type="submit" name="continue_shopping" value="Continue Shopping"/>
<input type="submit" name="checkout" value="Checkout"/>
<?php if (isset($_POST['checkout'])){echo "<script>window.open('checkout.php','_self')</script>"; } ?>
</div>
</form>
<?php
global $con;
$ip = getIp();
if (isset($_POST['update_cart'])){
foreach ($_POST['remove'] as $remove_id) {
$delete_product = "DELETE FROM zeus_limited.cart WHERE cart_product_id='$remove_id' AND ip_address='$ip'";
$run_delete = mysqli_query($con, $delete_product);
if($run_delete){
echo "<script>window.open('cart.php','_self')</script>";
}
}
}
if (isset($_POST['continue_shopping'])){
echo "<script>window.open('shop_products.php','_self')</script>";
}
?>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="container">
<div class="row">
<div class="col-md-4 footer-grid">
<h3>Menu</h3>
<ul class="list1">
<li>Home</li>
<li>Shop Products</li>
<li>My Account</li>
<li>Contact Us</li>
<li>Login</li>
</ul>
</div>
<div class="col-md-4 footer-grid">
<h3>Your Account</h3>
<ul class="list1">
<li>My Orders</li>
<li>Edit Account</li>
<li>Change Password</li>
<li>Delete Account</li>
<li>My Cart</li>
</ul>
</div>
<div class="col-md-4 footer-grid">
<h3>About Us</h3>
<p class="footer_desc">Zeus is a pharmacy focused on providing patients with what they need and deserve - exceptional pharmacy care. It is our responsibility and passion to care for your medication needs.</p>
<p class="f_text"><span class="fa fa-phone" aria-hidden="true"></span> Phone: +081 123 45 67</p>
<p class="email"><span class="fa fa-envelope" aria-hidden="true"></span> Email: <span>info#zeuspharmacy.com</span></p>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
</div>
<div class="footer-bottom">
<div class="container">
<div class="row">
<div class="col-md-12 footer-grid-bottom">
<div class="copyrights">
<p>© 2017 Zeus Pharmacy. Made with <span class="fa fa-heart" aria-hidden="true"></span> by Dilum Tharaka</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
order table structure image
payment table structure image
Above are the table structures I'm using. Thanks in advance

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>

How to display hidden data of one div to another div?

I am working on a project where I came across where when I click plus sign the data will hide and the appear in the div next to it.
here is the code:
<fieldset class="col-md-4" >
<legend>Services</legend>
<div class="col-md-12" >
<?php
$id = 0;
foreach ($servicesname as $val) {
$id++;
?>
<div class="col-md-12" style="font-size: 16px;" id="itemservices<?php echo $id ?>">
<span style="float:left;" ><?php echo $val[0]['servicename']; ?></span>
<a style="float:right;" href onclick="return addSrvToCart('itemservices<?php echo $id ?>')" >
<strong>&#8377 <?php echo $val[0]['amount']; ?></strong>
<span class="glyphicon glyphicon-plus-sign" id="id_<?php echo $id; ?>"></span>
</a>
</div>
<?php } ?>
</div>
</fieldset>
and the code for next div:
<fieldset class="col-md-4" >
<legend>Cart</legend>
<div style="list-style:none;" class="no-left-padding" id="cart">
<div class="col-md-12" >
</div>
</div>
<div class="col-sm-12 no-right-padding" style="background-color:#f3f0f0; padding-top:6px; border:1px solid#ccc">
<label class="pull-right">/*what should i write here to show the sum */: ₨ </label>
</div>
<button style="margin-top:10px;" class="btn btn-primary btn-sm pull-right" onclick="bookNowAfterFilter()">Book Now</button>
</fieldset>
And This the Jquery code:
<script>
function addSrvToCart(elem){
alert($('#' + elem).html());
$('#' + elem).hide();
//return false;
//what should i write here the show that hidden div
document.getElementById('summery);
return false;
}
</script>
This is the picture and I want to display the data in the Cart div and show the amount
You need to change in both HTML and Script to achieve the result
Try like this
HTML
<fieldset class="col-md-4" >
<legend>Services</legend>
<div class="col-md-12" >
<?php
$id = 0;
foreach ($servicesname as $val) {
$id++;
?>
<div class="col-md-12" style="font-size: 16px;" id="itemservices<?php echo $id ?>">
<span style="float:left;" ><?php echo $val[0]['servicename']; ?></span>
<a style="float:right;" onclick=" addSrvToCart('itemservices<?php echo $id ?>')" >
&#8377<strong> <?php echo $val[0]['amount']; ?></strong>
<span class="glyphicon glyphicon-plus-sign" id="id_<?php echo $id; ?>"></span>
</a>
</div>
<?php } ?>
</div>
</fieldset>
and the code for next div:
<fieldset class="col-md-4" >
<legend>Cart</legend>
<div style="list-style:none;" class="no-left-padding">
<div class="col-md-12" id="cart" >
</div>
</div>
<div class="col-sm-12 no-right-padding pull-right" style="background-color:#f3f0f0; padding-top:6px; border:1px solid#ccc">
Total: ₨ <label class="" id="sumAmount">0</label>
</div>
<button style="margin-top:10px;" class="btn btn-primary btn-sm pull-right" onclick="bookNowAfterFilter()">Book Now</button>
</fieldset>
Script:
function addSrvToCart(elem){
var div=$('#' + elem);
div.hide();
$('#cart').append(div.html());
var total = parseInt(div.find('strong').html()) + parseInt($('#sumAmount').html());
$('#sumAmount').html(total);
}
It will produce output as
I think it will help you.

Inserting into database failed while expected to be inserted

I'm trying to insert the user and cursus id in the database on submit the current user is defined in the second part(see comment) and connection with the database is made in the require once on top of the file.
When i press the button now its echoing success but in the database noting is showing up. Console is not showing up anything and when i echo $a or &b its giving me the correct id's. What is it that im doing wrong?
<?php
session_start();
require_once('includes/mysql_config.php');
//getting user data/id
$id = isset($_SESSION['id']) ? $_SESSION['id'] : header('location: login.php');
$result = mysqli_query($con, "SELECT * FROM users WHERE id =".$_SESSION['id']);
$user = mysqli_fetch_array($result);
require_once('header.php');
$id = $_GET['id'];
$result = mysqli_query($con, "SELECT * FROM cursus c LEFT OUTER JOIN cursussoort cr ON (c.cursussoort_ID = cr.id) WHERE c.ID = $id ORDER BY c.begindatum ASC");
$amount = mysqli_affected_rows($con);
for ($i = 0; $i < $amount; $i++) {
$cursus = mysqli_fetch_array($result);
$a = $cursus['id'];
$b = $user['id'];
//$a = mysqli_real_escape_string($a);
//$b = mysqli_real_escape_string($b);
if(isset($_POST['submit'])){
if($user['id']) {
$sql = "INSERT INTO aanmeldingen (users_id, cursus_id) VALUES ('$b', '$a')";
$result = mysqli_query($sql);
echo "success";
} else {
echo "failed";
}
}
?>
<div class="main-nav">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<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">
<h1><img class="img-responsive" src="images/logo.png" alt="logo"></h1>
</a> -->
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="scroll active">Home</li>
<li class="scroll">Over ons</li>
<li class="scroll">Cursussen</li>
<li class="scroll">Contact</li>
<?php if(isset($_SESSION['id'])) {
echo '<li><span>Mijn account</span></li>';
echo '<li><span>Log Out</span></li>';
} else {
echo '<li><span>Log In</span></li>';
} ?>
</ul>
</div>
</div>
</div><!--/#main-nav-->
<br><br>
<!-- Post Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-preview">
<h1> <?php echo $cursus['naam_cursus'] . "<br />";?></h1>
van: <?php echo $cursus['begindatum'] . "<br />";?>
tot: <?php echo $cursus['begindatum'] . "<br />";?>
<?php echo $cursus['beschrijving'] . "<br />";?>
</div>
</div>
</div>
<form method="post">
<input type="submit" name="submit">
</form>
</div>
</div>
<?php } ?>
<hr>
If you guys need more information tell me.
With your code here:
$result = mysqli_query($sql);
mysqli_query() requires two arguments; The connection, and the query. Try replacing that with this and tell me if it fixing your issue:
$result = mysqli_query($con, $sql);
Matt

Categories