update database field based on what the user selects via dropdown - php

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>

Related

Why it says something goes wrong and can't update to database in mysql?

I am new to PHP. When I create the below code following tutorial, I am puzzle why I can't update my data to database. As it shows below error
"Something went wrong, please try again"
Can anyone help to see through my scripts on where did I go wrong? Or is there anyway that I can do step by step debug to find out which line goes wrong?
<?php require_once("Includes/DB.php"); ?>
<?php require_once("Includes/Functions.php"); ?>
<?php require_once("Includes/Sessions.php"); ?>
<?php
if (isset($_POST["Submit"]))
{
$PostTitle = $_POST["PostTitle"];
$Category = $_POST["Category"];
$Image = $_FILES["Image"]["name"];
$Target = "Upload/".basename($_FILES["Image"]["name"]);
$PostText = $_POST["PostDescription"];
$Admin = "Sharon";
date_default_timezone_set("Asia/Singapore");
$CurrentTime=time();
$DateTime=strftime("%B-%d-%Y %H:%M:%S",$CurrentTime);
if(empty($PostTitle))
{
$_SESSION["ErrorMessage"] = "Title Can't be empty";
Redirect_to("AddNewPost.php");
} elseif (strlen($PostTitle)<5) {
$_SESSION["ErrorMessage"] = "Post Title should be greater
than 5 characters";
Redirect_to("AddNewPost.php");
} elseif (strlen($PostText)>999) {
$_SESSION["ErrorMessage"] = "Post Description should be less than 1000
characters";
Redirect_to("AddNewPost.php");
} else {
// Query to insert Post in DB when everything is fine
global $ConnectingDB;
$sql="INSERT INTO posts(datetime,title,category,author,image,post)";
$sql.="VALUES
:dateTime,:postTitle,:categoryName,:adminName,:imageName,:postDescription
)";
$stmt=$ConnectingDB->prepare($sql); // - > means PDO object rotation
$stmt->bindValue(':dateTime',$DateTime);
$stmt->bindValue(':postTitle',$PostTitle);
$stmt->bindValue(':categoryName',$Category);
$stmt->bindValue(':adminName',$Admin);
$stmt->bindValue(':imageName',$Image);
$stmt->bindValue(':postDescription',$PostText);
$Execute=$stmt->execute();
move_uploaded_file($_FILES["Image"]["tmp_name"],$Target);
if($Execute)
{
$_SESSION["SuccessMessage"]="Post Added Successfully";
Redirect_to("AddNewPost.php");
} else {
$_SESSION["ErrorMessage"]="Something went wrong, please
try again";
Redirect_to("AddNewPost.php");
}
}
} //Ending of Submit Button If- Condition
?>
<!DOCTYPE>
<html lang="en">
<head>
<link rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.7.2/css/all.css"
integrity="sha384-
fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr"
crossorigin="anonymous">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/
bootstrap.min.css" integrity="sha384-
ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
<link rel="stylesheet" href="css/Styles.css">
<title>Categories</title>
</head>
<body>
<div style="height:10px; Background:#27aae1;"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container" ">
<a href="#" class="navbar-brand"> Application
Department </a>
<button class="navbar-toggler" data-
toggle="collapse" data-target="#navbarcollapseCMS">
<span class="navbar-toggler-
icon"></span>
</button>
<div class="collapse navbar-collapse"
id="navbarcollapseCMS">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a href="Main.php" class="nav-
link"><i class="fas fa-home text-success"></i> Main page </a>
</li>
<li class="nav-item">
<a href="Post.php" class="nav-
link"> Posts </a>
</li>
<li class="nav-item">
<a href="Categories.php"
class="nav-link"> Categories</a>
</li>
<li class="nav-item">
Admin
</li>
<li class="nav-item">
<a href="Comment.php"
class="nav-link"> Comments</a>
</li>
</ul>
<ui class="navbar-nav ml-auto">
<li class="nav-item"><a
href="Logout.php" class="nav-link text-warning"><i class="fas fa-user-
times"></i> Logout</a></li>
</ul>
</div>
</div>
</nav>
<div style="height:10px; Background:#27aae1;"></div>
<!--NAVBAR END-->
<!--header-->
<header class="bg-dark text-white py-3">
<div class="container">
<div class="row">
<div class="col-md-12">
<p style="font-size:30px;"> <i class="fas fa-edit"
style="color:#27aae1;"></i> Add New Post </p>
</div>
</div>
</div>
</header>
<!--header end-->
<!--Main Area -->
<section class="container py-2 mb-4">
<div class="row">
<div class="offset-lg-1 col-lg-10" style="min-height:420px;">
<?php
echo ErrorMessage();
echo SuccessMessage();
?>
<form class="" action="AddNewPost.php" method="post"
enctype="multipart/form-data">
<div class="card bg-secondary text-
light mb-2">
<div class="card-body bg-dark">
<div class="form-group">
<label for="title"> <span class="FieldInfo"> Post Title: </span></label>
<input class="form-control" type="text" name="PostTitle" id="title"
placeholder="Type title here" value="">
</div>
<div
class="form-group">
<label
for="CategoryTitle"> <span class="FieldInfo"> Choose Category:
</span></label>
<select
class="form-control" id="CategoryTitle" name="Category">
<?php
//Fetching all the categories from category mysql_list_tables
global $ConnectingDB;
$sql = "SELECT id,title FROM category";
$stmt = $ConnectingDB->query($sql);
while ($DateRows = $stmt->fetch()) {
$Id = $DateRows["id"];
$CategoryName = $DateRows["title"];
?>
<option> <?php echo $CategoryName; ?> </option>
<?php } ?>
</select>
</div>

The footer of my website's homepage isn't coming

I have been trying to make a website. It is an online shopping website.
This is my code-
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Books And Beyond</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Bootstrap styles open source -->
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" crossorigin="anonymus">
<!-- Customize styles -->
<link href="style.css" rel="stylesheet"/>
<!-- font awesome styles open source -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" crossorigin="anonymus">
<!-- Favicons -->
<link rel="shortcut icon" href="/favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style
type="text/css">
<!--
body {
background-image: url(assets/img/background.jpg);
}
-->
</style></head>
<body>
<!--
Upper Header Section
-->
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="topNav">
<div class="container">
<div class="alignR">
<?php if (isset($_SESSION['email'])) { echo $_SESSION['email']; } else { ?>
<ul class="nav pull-right">
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#"><span class="icon-lock"></span> Login <b class="caret"></b></a>
<div class="dropdown-menu">
<form class="form-horizontal loginFrm" action="checkuser.php" method="post">
<div class="control-group">
<input name="email" type="text" class="span2" id="email" placeholder="Email">
</div>
<div class="control-group">
<input name="password" type="password" class="span2" id="password" placeholder="Password">
</div>
<div class="control-group">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button name="login" type="submit" class="shopBtn btn-block">Sign in</button>
</div>
</form>
</div>
</li>
</ul>
<?php } ?>
<?php if (isset($_SESSION['email'])) { ?>
Logout
<?php } else { ?>
<span class="icon-edit"></span> Register
<?php }?>
</div>
</div>
</div>
</div>
<!--
Lower Header Section
-->
<div class="container">
<div id="gototop"> </div>
<header id="header">
<div class="row">
<div class="span4">
<h1>
<a class="logo" href="index.php"><span>Books And Beyond</span>
<img src="assets/img/logo1.jpg" alt="" width="218" height="94"> </a> </h1>
</div>
</div>
</header>
<!--
Navigation Bar Section
-->
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<div class="nav-collapse">
<ul class="nav">
<li class="active">Home</li>
<li class="">About</li>
<li class="">Bargain Books</li>
<li class="">New Releases</li>
<li class="">Bestsellers</li>
<li class="">Contact Us</li>
</ul>
<ul class="nav pull-right">
</ul>
</div>
</div>
</div>
</div>
<div class="row">
<div class="span12">
<img src="assets/img/banner.jpg"/>
<hr class="soften"/>
</div>
</div>
<!--Body Section
-->
<div class="row">
<div id="sidebar" class="span3">
<div class="well well-small">
<h3> Category </h3>
<ul class="nav nav-list">
<li><span class="icon-chevron-right"></span>Fiction</li>
<li><span class="icon-chevron-right"></span>Non-Fiction</li>
<li><span class="icon-chevron-right"></span>Young Adult</li>
<li><span class="icon-chevron-right"></span>Children's</li>
<li><span class="icon-chevron-right"></span>Travel</li>
<li><span class="icon-chevron-right"></span>Education</li>
<li style="border:0"> </li>
</ul>
</div>
<!--<div class="well well-small alert alert-warning cntr">
<h2>50% Discount</h2>
<p>
only valid for online order. <br><br><a class="defaultBtn" href="#">Click here </a>
</p>
</div>-->
<!-- <div class="well well-small" ><img src="assets/img/paypal.jpg" alt="payment method paypal"></div>-->
<!--<a class="shopBtn btn-block" href="#">Upcoming products <br><small>Click to view</small></a>-->
<ul class="nav nav-list promowrapper">
<?php
/* require_once('dbconnect.php'); */
$result = mysql_query("SELECT * from product WHERE brand='accessories'");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
$price=$row["productprice"];
$productimage=$row["productimage"];
?>
<li>
<div class="thumbnail">
<img width="200" height="80" src="getImage.php?intproductid=<?php print $intproductid;?>" />
<div class="caption">
<table width="250" border="0">
<tr>
<td align="left" valign="middle"><form action="product_detail.php" method="post" name="form2" id="form2">
<label>
<input type="hidden" name="intproductid2" value="<?php echo $intproductid; ?>" />
<input name="Submit2" type="submit" class="shopBtn" value="View" />
</label>
</form></td>
<td align="right" valign="middle"><h4> <span class="pull-right"><?php echo $price; ?>.00</span></h4></td>
</tr>
</table>
</div>
</div>
</li>
<li style="border:0"> </li>
<?php } ?>
</ul>
</div>
<div class="span9">
<!--
New Products
-->
<div class="well well-small">
<h3>New Products </h3>
<hr class="soften"/>
<div class="row-fluid">
<div id="newProductcar" class="carousel slide">
<div class="">
<div class="item active">
<ul class="thumbnails">
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='bousni' LIMIT 1");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
//$productimage=$row["productimage"];
?>
<li class="span3">
<div class="thumbnail">
<img width="200" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
</div>
</li>
<?php } ?>
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='hela couture' LIMIT 1");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
//$productimage=$row["productimage"];
?>
<li class="span3">
<div class="thumbnail">
<img width="200" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
</div>
</li>
<?php } ?>
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='zey' LIMIT 1");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
//$productimage=$row["productimage"];
?>
<li class="span3">
<div class="thumbnail">
<img width="200" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
</div>
</li>
<?php } ?>
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='AL-JUMAIRA' LIMIT 1");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
//$productimage=$row["productimage"];
?>
<li class="span3">
<div class="thumbnail">
<img width="200" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
</div>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="well well-small">
<div class="span8">
<div class="row-fluid">
<h3>Features Products </h3>
<hr class="soften"/>
<ul class="thumbnails">
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='roza' LIMIT 3");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
$productname=$row["productname"];
$brand=$row["brand"];
$price=$row["productprice"];
$productimage=$row["productimage"];
?>
<li class="span4">
<div class="thumbnail">
<img width="250" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
<div class="caption cntr">
<p style="color:#990033"><?php echo $productname; ?></p>
<p><?php echo $brand; ?></p>
<p><strong>SAR <?php echo $price; ?>.00</strong></p>
<div class="btn-group">
<form id="form2" name="form2" method="post" action="product_detail.php">
<label>
<input type="hidden" name="intproductid2" value="<?php echo $intproductid; ?>" />
<input name="Submit2" type="submit" class="shopBtn" value="View" />
<input name="Submit2" type="submit" class="defaultBtn" value="Add to cart" />
</label>
</form>
</div>
<br class="clr">
</div>
</div>
</li>
<?php } ?>
</ul>
<hr class="soften"/>
<ul class="thumbnails">
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='haya' LIMIT 3");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
$productname=$row["productname"];
$brand=$row["brand"];
$price=$row["productprice"];
$productimage=$row["productimage"];
?>
<li class="span4">
<div class="thumbnail">
<img width="250" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
<div class="caption cntr">
<p style="color:#990033"><?php echo $productname; ?></p>
<p><?php echo $brand; ?></p>
<p><strong>SAR <?php echo $price; ?>.00</strong></p>
<div class="btn-group">
<form id="form2" name="form2" method="post" action="product_detail.php">
<label>
<input type="hidden" name="intproductid2" value="<?php echo $intproductid; ?>" />
<input name="Submit2" type="submit" class="shopBtn" value="View" />
<input name="Submit2" type="submit" class="defaultBtn" value="Add to cart" />
</label>
</form>
</div>
<br class="clr">
</div>
</div>
</li>
<?php } ?>
</ul>
</div>
</div>
<div class="row">
</div>
</div>
</div></div></div>
<!--
Footer
-->
<footer class="footer" style="float: bottom;">
<div class="row-fluid">
<div class="span3">
<h5>ORDER SUPPORT</h5>
Store pickup<br>
Return and Refund<br>
</div>
<div class="span3">
<h5>PRODUCT SUPPORT</h5>
FAQs<br>
Inquiry<br>
</div>
<div class="span3">
<h5>COOPORATIVE INFO</h5>
Terms and Condition <br>
Contact us<br>
</div>
<div class="span3">
<h5>GET CONNECTED</h5>
About us <br>
Create Account<br>
</div>
</div>
</footer>
</div><!-- /container -->
<div class="copyright">
<div class="container">
<p class="pull-right"> </p>
<span>Copyright 2019, Fatimatuz Johura - s201403034- Jeddah (Ladies Branch);<br> Books And Beyond</span>
</div>
</div>
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/jquery.easing-1.3.min.js"></script>
<script src="assets/js/jquery.scrollTo-1.4.3.1-min.js"></script>
<script src="assets/js/shop.js"></script>
</body>
</html>
The 'New Products' and the footer section is not coming and I cant figure out why. I dont have a webhost yet so I am using localhost for now. I have tried editing the code but whatever I do, it does not seem to work. If anyone can help, I would really appreciate it. Thank you.
On line 152 (new products is on line ~ 185[ish])
/* require_once('dbconnect.php'); */
$result = mysql_query("SELECT * from product WHERE brand='accessories'");
As I said in the comments you use this require_once('dbconnect.php'); multiple times when it should be only once at the top of your file.
The above code is the first occurrence I could find, and as it's commented out, that query is going to bomb out on you. Execution happens top to bottom and the first uncommitted occurrence of that is line 196[ish], which is way to late for that first query.
Also as I said in the comments
Try turning on Error reporting - error_reporting(-1); and ini_set('display_errors', '1'); put those right after the <?php tag
You can save yourself, and us a lot of time that way.
So in Summery,
Remove all of these require_once('dbconnect.php'); and then add just one after the opening <?php tag.
PS you can easily test this, by just commenting that first query out, or by uncommenting that first require_once.

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

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

PHP login redirect results in headers already sent [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 6 years ago.
I'm trying to create a login script, which generates a session after the user signed in, now the user would be redirected to a new url, sadly I receive the following error:
[Fri Sep 23 20:09:17.125738 2016] [fcgid:warn] [pid 27802] [client 91.97.73.183:12550] mod_fcgid: stderr: PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/pr0b.com/httpdocs/index.php:109) in /var/www/vhosts/pr0b.com/httpdocs/handling/classes/user_login_class.php on line 74, referer: http://pr0b.com/
My code looks like the following:
Index.php
<?php
require_once('handling/classes/database_class.php');
require_once('handling/classes/site_config_class.php');
require_once('handling/classes/main_class.php');
$site_config = new site_config_class();
$site_informations = new main_class();
$site_informations_response = $site_informations->class_handler();
?>
<!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><?php echo $site_config->site_title_home; ?></title>
<!-- Global stylesheets -->
<link href="https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900" rel="stylesheet" type="text/css">
<link href="assets/css/icons/icomoon/styles.css" rel="stylesheet" type="text/css">
<link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="assets/css/core.css" rel="stylesheet" type="text/css">
<link href="assets/css/components.css" rel="stylesheet" type="text/css">
<link href="assets/css/colors.css" rel="stylesheet" type="text/css">
<link href="assets/css/stylesheet.css" rel="stylesheet" type="text/css">
<!-- Core JS files -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/ui/nicescroll.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/ui/drilldown.js"></script>
<script type="text/javascript" src="assets/js/pages/form_select2.js"></script>
<script type="text/javascript" src="assets/js/core/app.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/selects/select2.min.js"></script>
<script type="text/javascript" src="../assets/js/plugins/notifications/noty.min.js"></script>
</head>
<body class="navbar-top-md-md login-container">
<div class="navbar-fixed-top">
<div class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="index.html"><div class="logo"></div></a>
<ul class="nav navbar-nav pull-right visible-xs-block">
<li><a data-toggle="collapse" data-target="#navbar-mobile"><i class="icon-tree5"></i></a></li>
</ul>
</div>
<div class="navbar-collapse collapse" id="navbar-mobile">
<ul class="nav navbar-nav navbar-right">
<li><a data-toggle="modal" data-target="#modal-registration"><i class="icon-users4 position-left"></i> Register Account</a></li>
<li><a data-toggle="modal" data-target="#modal-login"><i class="icon-user-lock position-left"></i> Log In</a></li>
<li><a data-toggle="modal" data-target="#modal-recover"><i class="icon-reply position-left"></i> Resend Credentials</a></li>
</ul>
</div>
</div>
<!-- /main navbar -->
<!-- Second navbar -->
<div class="navbar navbar-default" id="navbar-second">
<ul class="nav navbar-nav no-border visible-xs-block">
<li><a class="text-center collapsed" data-toggle="collapse" data-target="#navbar-second-toggle"><i class="icon-menu7"></i></a></li>
</ul>
<div class="navbar-collapse collapse" id="navbar-second-toggle">
<ul class="nav navbar-nav">
<li class="active"><i class="icon-home position-left"></i> Home</li>
<li><i class="icon-heart6 position-left"></i> Community</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><i class="icon-facebook2"></i></li>
<li><i class="icon-twitter"></i></li>
<li><i class="icon-youtube"></i></li>
</ul>
</div>
</div>
<!-- /second navbar -->
</div>
<!-- /fixed navbars wrapper -->
<!-- Page container -->
<div class="page-container">
<div class="page-content">
<div class="content-wrapper">
<div class="row">
<div class="col-lg-3">
<div class="panel bg-slate-400">
<div class="panel-body">
<div class="heading-elements">
<span class="heading-text badge bg-slate-300">Registered users</span>
</div>
<h3 class="no-margin"><?php echo $site_informations_response['registered_users']; ?></h3>
Registered users
</div>
</div>
</div>
<div class="col-lg-3">
<div class="panel bg-slate-400">
<div class="panel-body">
<div class="heading-elements">
<span class="heading-text badge bg-slate-300">Online users</span>
</div>
<h3 class="no-margin"><?php echo $site_informations_response['online_users']; ?></h3>
Online users
</div>
</div>
</div>
<div class="col-lg-3">
<div class="panel bg-slate-400">
<div class="panel-body">
<div class="heading-elements">
<span class="heading-text badge bg-slate-300">Male users</span>
</div>
<h3 class="no-margin"><?php echo $site_informations_response['male_users']; ?></h3>
Male users
</div>
</div>
</div>
<div class="col-lg-3">
<div class="panel bg-slate-400">
<div class="panel-body">
<div class="heading-elements">
<span class="heading-text badge bg-slate-300">Female users</span>
</div>
<h3 class="no-margin"><?php echo $site_informations_response['female_users']; ?></h3>
Female users
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
Content
</div>
</div>
<!-- Login form -->
<div id="modal-login" class="modal fade">
<div class="modal-dialog">
<div class="modal-content login-form">
<!-- Form -->
<form class="modal-body" method="post">
<div class="text-center">
<div class="icon-object border-slate-300 text-slate-300"><i class="icon-reading"></i></div>
<h5 class="content-group">Login to your account <small class="display-block">Your credentials</small></h5>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Username" name="username">
<div class="form-control-feedback">
<i class="icon-user text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Password" name="password">
<div class="form-control-feedback">
<i class="icon-lock2 text-muted"></i>
</div>
</div>
<input type="hidden" name="action" value="login">
<div class="form-group">
<button type="submit" class="btn bg-slate-600 btn-block">Login</button>
<button type="button" class="btn btn-default btn-block" data-dismiss="modal">Cancel</button>
</div>
<span class="help-block text-center no-margin">By continuing, you're confirming that you've read our Terms & Conditions and Cookie Policy</span>
</form>
<!-- /form -->
</div>
</div>
</div>
<!-- /login form -->
<!-- Registration form -->
<div id="modal-registration" class="modal fade">
<div class="modal-dialog">
<div class="modal-content login-form">
<!-- Form -->
<form class="modal-body" method="post">
<div class="text-center">
<div class="icon-object border-slate-300 text-slate-300"><i class="icon-plus3"></i></div>
<h5 class="content-group">Create account <small class="display-block">All fields are required</small></h5>
</div>
<div class="content-divider text-muted form-group"><span>Your credentials</span></div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Username" name="username">
<div class="form-control-feedback">
<i class="icon-user-check text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input id="password" type="password" class="form-control" placeholder="Password" name="password">
<div class="form-control-feedback">
<i class="icon-user-lock text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input id="password_confirm" type="password" class="form-control" placeholder="Repeat password" name="password_confirm">
<div class="form-control-feedback">
<i class="icon-user-lock text-muted"></i>
</div>
</div>
<div class="form-group">
<span id="password_status" class="help-block text-center no-margin"></span>
</div>
<div class="content-divider text-muted form-group"><span>Your privacy</span></div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Email" name="email">
<div class="form-control-feedback">
<i class="icon-mention text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Reset pin code" name="pin_code">
<div class="form-control-feedback">
<i class="icon-sync text-muted"></i>
</div>
</div>
<div class="form-group">
<select data-placeholder="Select a gender..." class="select" name="gender">
<option></option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="content-divider text-muted form-group"><span>Additions</span></div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" id="terms" class="styled" name="terms">Accept terms of service
</label>
</div>
</div>
<input type="hidden" name="action" value="register">
<div class="form-group">
<button id="registerButton" type="submit" class="btn bg-slate-600 btn-block" disabled>Register account</button>
<button type="button" class="btn btn-default btn-block" data-dismiss="modal">Cancel</button>
</div>
<span class="help-block text-center no-margin">By continuing, you're confirming that you've read our Terms & Conditions and Cookie Policy</span>
</form>
<!-- /form -->
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#password_confirm").keyup(validate);
});
$('#terms').change(function(){
$("#registerButton").prop('disabled', !$(this).is(':checked'));
});
function validate() {
var password1 = $("#password").val();
var password2 = $("#password_confirm").val();
if(password1 == password2) {
$("#password_status").text("Passwords match!");
}
else {
$("#password_status").text("Passwords do not match!");
}
}
</script>
<!-- /registration form -->
<!-- Password recovery form -->
<div id="modal-recover" class="modal fade">
<div class="modal-dialog">
<div class="modal-content login-form">
<!-- Form -->
<form class="modal-body" action="index.html">
<div class="text-center">
<div class="icon-object border-slate-300 text-slate-300"><i class="icon-spinner11"></i></div>
<h5 class="content-group">Password recovery <small class="display-block">We'll send you instructions in email</small></h5>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Username">
<div class="form-control-feedback">
<i class="icon-user-check text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Reset pin code">
<div class="form-control-feedback">
<i class="icon-sync text-muted"></i>
</div>
</div>
<input type="hidden" name="action" value="recover">
<button type="submit" class="btn bg-slate-600 btn-block">Reset password</button>
<button type="button" class="btn btn-default btn-block" data-dismiss="modal">Cancel</button>
</form>
<!-- /form -->
</div>
</div>
</div>
<!-- /password recovery form -->
<?php
if(!empty($_POST)){
$action = $_POST['action'];
switch ($action) {
case 'login':
require_once('handling/classes/user_login_class.php');
$user_login = new user_login_class($_POST['username'], $_POST['password']);
$user_login_response = $user_login->class_handler();
echo $user_login_response;
break;
case 'register':
require_once('handling/classes/register_class.php');
$register_account = new register_class($_POST['username'], $_POST['password'], $_POST['password_confirm'], $_POST['email'], $_POST['pin_code'], $_POST['gender']);
$register_account_response = $register_account->class_handler();
echo $register_account_response;
break;
case 'recover':
#code
break;
}
}
?>
</div>
</div>
</div>
<!-- /Page container -->
<!-- Footer -->
<div class="footer text-muted text-center">
<?php echo $site_config->site_footer; ?>
</div>
<!-- /footer -->
</body>
</html>
user_login_class
<?php
class user_login_class extends database_class {
// Class constructor
function __construct($username, $password) {
$this->username = $username;
$this->password = $password;
$this->salt = 'zWorlDs4lt';
$this->hashed_password = md5($this->salt.$this->password);
}
// Function to check the user credentials
function check_user_credentials() {
$this->connect();
$result = $this->execute_query("SELECT password FROM Users WHERE username = '" . $this->username . "'");
while($row = mysqli_fetch_assoc($result)) {
$response = $row['password'];
}
if($response !== $this->hashed_password) {
return false;
}else {
return true;
}
}
// Function to check the account status
function get_account_status() {
$this->connect();
$result = $this->execute_query("SELECT status FROM Users WHERE username = '" . $this->username . "'");
while($row = mysqli_fetch_assoc($result)) {
$response = $row['status'];
}
return $response;
}
// Function to update user informations
function update_user_variables() {
$this->connect();
$result = $this->execute_query("UPDATE Users SET ip = '" . $_SERVER['REMOTE_ADDR'] . "', online = '1' WHERE username = '" . $this->username . "'");
if(!$result) {
return false;
}else {
return true;
}
}
// Function to execute the class
function class_handler() {
if(!$this->username) {
return 'Error: Username is required. Please enter a valid username.';
}else if(!$this->password) {
return 'Error: Password is required. Please enter a valid password.';
}else {
$check_account_status = $this->get_account_status();
if($check_account_status == 1) {
return 'Error: This account was banned. Please contact our support.';
}else {
$check_user_credentials_resonse = $this->check_user_credentials();
if($check_user_credentials_resonse == false) {
return 'Error: Wrong credentials. Please try again.';
}else if($check_user_credentials_resonse == true) {
$update_user = $this->update_user_variables();
if($update_user == false) {
return 'Error: Wrong credentials. Please try again.';
}else if($update_user == true) {
session_start();
$_SESSION['logged_in'] = true;
$_SESSION['username'] = $this->username;
header('Location: /zworld');
exit();
}
}
}
}
}
}
?>
But yea, it would not redirect the user, does anyone know why? I would appreciate any kind of help, cause I have no clue where to search.
at the very top of your script, put ob_start()
<?php
ob_start();
require_once('handling/classes/database_class.php');
require_once('handling/classes/site_config_class.php');
require_once('handling/classes/main_class.php');
$site_config = new site_config_class();
$site_informations = new main_class();
$site_informations_response = $site_informations->class_handler();
...
?>

Update query won't update my product list

I am having serious problems with my product details not updating. It fetches all the product information when I click edit but when I press the submit button to update the product details it does not have an affect on the database. I have been spending quite some time on this and have looked at solutions online as well. None of them seem to work
Here is my code :
<?php
include("functions/mysqli_connect.php");
if(isset($_GET['edit'])) {
$get_id = $_GET['edit'];
$get_pro = "select * from shop where product_id='$get_id'";
$run_pro = mysqli_query($con, $get_pro);
$row_pro=mysqli_fetch_array($run_pro);
$pro_id = $row_pro['product_id'];
$pro_name = $row_pro['name'];
$pro_cat = $row_pro['category'];
$pro_description = $row_pro['description'];
$pro_quantity = $row_pro['quantity'];
$pro_price = $row_pro['price'];
$image = $row_pro['images'];
}
?>
<!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">
<meta name="description" content="">
<meta name="author" content="">
<title>SB Admin - Bootstrap Admin Template</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/sb-admin.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-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">SB Admin</a>
</div>
<!-- Top Menu Items -->
<ul class="nav navbar-right top-nav">
<li class="dropdown">
<i class="fa fa-user"></i> <?php echo $_SESSION['admin_username']; ?> <b class="caret"></b>
<ul class="dropdown-menu">
<li>
<i class="fa fa-fw fa-power-off"></i> Log Out
</li>
</ul>
</li>
</ul>
<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li class="active">
<i class="fa fa-fw fa-dashboard"></i> Insert Products
</li>
<li>
<i class="fa fa-fw fa-table"></i> View Products
</li>
<li>
<i class="fa fa-fw fa-bar-chart-o"></i> Edit Products
</li>
<li>
<i class="fa fa-fw fa-table"></i> Delete Products
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-6">
<form action="edit_pro.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="name">Product Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo $pro_name;?>" >
</div>
<div class="form-group">
<label for="category">Category</label>
<select type="text" class="form-control" id="category" name="category" >
<option><?php echo $pro_cat;?></option>
<option>Henna</option>
<option>Gliter</option>
<option>Cajeput Oil</option>
<option>Henna Cones</option>
</select>
</div>
<div class="form-group">
<label for="image">Image</label>
<input type="file" id="image" name="image" ><img src="stock_images/<?php echo $image; ?>"width="60" height="60" />
<p class="help-block"></p>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" id="description" name="description"><?php echo $pro_description;?></textarea>
</div>
<div class="form-group">
<label for="quantity">Quantity</label>
<input type="number" class="form-control" id="quantity" name="quantity" value="<?php echo $pro_quantity;?>" >
</div>
<div class="form-group">
<label for="price">Price</label>
<input type="number" class="form-control" id="price" name="price" value="<?php echo $pro_price;?>" >
</div>
<div class="form-group">
<input name="id" type="hidden" id="id" value="<? echo $pro_id; ?>">
</div>
<input type="submit" name="update" class="btn btn-default" value="Add Stock"></a>.
</form>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
<?php
if(isset($_POST['update'])){
//getting the text data from the form
$id=mysql_real_escape_string($_GET['product_id']);
$update_id = $pro_id;
$pro_name = $_POST['name'];
$pro_cat = $_POST['category'];
$pro_description = $_POST['description'];
$pro_quantity = $_POST['quantity'];
$pro_price = $_POST['price'];
$image = $_FILES['image'] ['name'];
$image_tmp = $_FILES['image'] ['tmp_name'];
move_uploaded_file($image_tmp, "stock_images/$image");
$servername = "localhost";
$username = "Naina";
$password = "Mhendi2015";
$dbname = "farhanaina";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE shop SET name='$pro_name', category='$pro_cat', images='$image', description='$pro_description', quantity='$pro_quantity', price='$pro_price' WHERE product_id='$id'";
// Prepare statement
$stmt = $conn->prepare($sql);
// execute the query
$stmt->execute();
// echo a message to say the UPDATE succeeded
echo $stmt->rowCount() . " records UPDATED successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
}
?>
You're using PDO and a prepared statement here. You can't feed a ready SQL query with the variable values into PDO::prepare. Quoting an example from the manual:
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < ? AND colour = ?');
$sth->execute(array(150, 'red'));
The array you pass into your PDO::execute will replace each ? with a value in order of the values in the array. Otherwise, you can pass in an associative array and do it with named parameters:
$sql = 'SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour';
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->execute(array(':calories' => 150, ':colour' => 'red'));

Categories