I create form which contain text fields and upload file(register.php), and I want to send data to sendData.php and redirect to payment.php in order user to make payment for document review. I don't know where am wrong from sendData.php, I try to submit data from register.php to sendData and output is blank no error found, I try to check mysql error also no error found.
Page contain Form data
<?php
$errors = "";
if(isset($_GET["error"])){
if($_GET["error"] === "pwd"){
$errors = '<div class="alert alert-danger col-md-3><span class="glyphicon glyphiocn-remove-circle"></span> Passowrd dismatch, please try again</div>';
}
if($_GET["error"] === "undefined"){
$errors = '<div class="alert alert-danger col-md-3><span class="glyphicon glyphiocn-remove-circle"></span> File format dismatch, please try again</div>';
}
if($_GET["error"] === "found_file"){
$errors = '<div class="alert alert-danger col-md-3><span class="glyphicon glyphiocn-remove-circle"></span> Document found error, please try again</div>';
}
}
?>
<!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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>CentralAcademy: Register</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link rel="stylesheet" href="css/jumbtron.css">
<link href="css/custom-file.css" rel="stylesheet">
<style type="text/css">
body{ padding-top: 80px; }
</style>
</head>
<body>
<?php require_once("includes/header.php"); ?>
<div class="container">
<div class="row">
<div class="col-lg-3 breadcrumb">
<h3 class="page-header">Payment</h3>
<p><img src="images/images.png" class="img img-responsive" width="70" height="50" style="display: block; float: left; padding-right:10px;"/> (+255)755-555-555</p><br>
<p><img src="images/airtelM.fw.png" class="img img-responsive" width="70" height="50" style="display: block; float: left; padding-right:10px;"/> (+255)685-555-555</p><br>
<p><img src="images/tigopesa.png" class="img img-responsive" width="70" height="50" style="display: block; float: left; padding-right:10px;"/> (+255)655-555-555</p><br>
</div>
<div class="col-lg-2"></div>
<div class="col-lg-7 breadcrumb">
<?php print $errors; ?>
<h3 class="page-header">Request for Document Review</h3>
<h5><font color="#FF0000">***</font> Please fill all fields required</h5><br>
<form action="sendData.php" method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="form-group">
<div class="col-md-6">
<input name="fname" type="text" placeholder="Enter your FirstName" value="<?php echo isset($_POST['fname']) ? $_POST['fname'] : '' ?>" class="form-control" required id="fname">
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="sname" type="text" class="form-control" value="<?php echo isset($_POST['sname']) ? $_POST['sname'] : '' ?>" placeholder="Enter your LastName" required id="sname">
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="gender" type="radio" class="radio-inline" value="F" checked="CHECKED" required/>Female <input type="radio" name="gender" class="radio-inline" value="M" required/>Male</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="email" type="text" class="form-control" value="<?php echo isset($_POST['email']) ? $_POST['email'] : '' ?>" placeholder="Enter your Email Address" required id="email">
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="phone" type="text" class="form-control" placeholder="Enter your Phone Number" value="<?php echo isset($_POST['phone']) ? $_POST['phone'] : '' ?>" maxlength="13" required id="phone" pattern="[\+]\d{3}\d{3}\d{6}">
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input type="radio" name="edlevel" value="bachelor" class="radio-inline" checked="CHECKED" required/>Bachelor
<input type="radio" name="edlevel" value="Post Graduate" class="radio-inline" />Post Grad
<input name="edlevel" type="radio" value="Masters" class="radio-inline" />Masters
<input name="edlevel" type="radio" value="PhD" class="radio-inline" />PhD
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="affi" type="text" class="form-control" value="<?php echo isset($_POST['affi']) ? $_POST['affi'] : '' ?>" placeholder="Enter organisation/College/University" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="title" type="text" class="form-control" value="<?php echo isset($_POST['title']) ? $_POST['title'] : '' ?>" placeholder="Enter your document title" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 fileUpload">
<input type="file" name="files" id="file"/>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="password" type="password" class="form-control" placeholder="Choose Your Password" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="password2" type="password" class="form-control" placeholder="Confirm Your Password" required>
</div>
</div>
<br>
<div class="form-group">
<div class="col-md-6">
<button name="Register" type="submit" class="btn btn-info"><span class="glyphicon glyphicon-user"></span> Register Now</button><br><br>
<p>If you are already registered please click here</p>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="container marketing">
<!-- START THE FEATURETTES -->
<?php require_once("includes/footer.php"); ?>
</div><!-- /.container -->
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
//sendData.php
<?php
if(isset($_FILES['files']) && $_POST["password"] === $_POST["password2"]){
session_start();
require_once("includes/dbconnect.php");
$fname = $_POST["fname"];
$sname = $_POST["sname"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$title = $_POST["title"];
$password = $_POST["password"];
$gender = $_POST["gender"];
$edlevel = $_POST["edlevel"];
$affi = $_POST["affi"];
//Keep all author data to session variable
$_SESSION["fname"] = $fname;
$_SESSION["sname"] = $sname;
$_SESSION["email"] = $email;
$_SESSION["phone"] = $email;
$_SESSION["passwprd"] = $password;
$_SESSION["gender"] = $gender;
$_SESSION["edlevel"] = $edlevel;
$_SESSION["affi"] = $affi;
$errors= array();
$extensions = array("docx");
$file_name = rand(1000,100000)."-".$_FILES['files']['name'];
$file_size = $_FILES['files']['size'];
$file_tmp = $_FILES['files']['tmp_name'];
$file_type = $_FILES['files']['type'];
$file_ext = strtolower(substr($_FILES['files']['name'],strrpos($_FILES['files']['name'],'.')+1));
if(in_array($file_ext,$extensions ) === true && $file_size < 2097152){
$result = $connect->query("INSERT INTO temp VALUES(NULL,'$title',$email','$file_name',now())");
if($result){
$desired_dir="AuthorReport";
if(empty($errors)===true){
if(is_dir($desired_dir)===false){
mkdir("$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false){
move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
}else{ // rename the file if another one exist
$new_dir="$desired_dir/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
header("location: payment.php");
exit();
}
else{ header("location:register.php?error=found_file"); exit(); }
}
}
else{ header("location:register.php?error=undefined"); exit(); }
}
else{ header("location:register.php?error=pwd"); exit(); }
?>
$email doesn't have start quote
$result = $connect->query("INSERT INTO temp VALUES(NULL,'$title',$email','$file_name',now())");
that's why you have the error.
and to be sure where are you entering these values exactly where you want use add also the column names in INSERT statement
$result = $connect->query("INSERT INTO temp
(column_title, column_email, column_filename, thedate)
VALUES
('$title','$email','$file_name',NOW() )" );
Related
I want to set default user ( Trainees role ) for newly registered user on my system.
My main problem is registration works but the 'role' tab on the database is empty. Tried adding dropdown button for trainees role but the 'role' tab on the users table is still empty.
Is it allowed to set default user role upon user registration?
Database Image
Registration.php code
<?php
// Define variables and initialize with empty values
$username = $password = $confirm_password = "";
$username_err = $password_err = $confirm_password_err = "";
require_once "php/dbconnect.php";
if(isset($_SESSION['user_id'])!="") {
header("Location: index.php");
}
if (isset($_POST['signup'])) {
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$name = mysqli_real_escape_string($conn, $_POST['name']);
$emailid = mysqli_real_escape_string($conn, $_POST['emailid']);
$age = mysqli_real_escape_string($conn, $_POST['age']);
$location = mysqli_real_escape_string($conn, $_POST['location']);
$role = mysqli_real_escape_string($conn, $_POST['role']);
if (!preg_match("/^[a-zA-Z ]+$/",$name)) {
$name_error = "Name must contain only alphabets and space";
}
if(!filter_var($emailid,FILTER_VALIDATE_EMAIL)) {
$email_error = "Please Enter Valid Email ID";
}
if(strlen($password) < 6) {
$password_error = "Password must be minimum of 6 characters";
}
if(strlen($mobile) < 10) {
$mobile_error = "Mobile number must be minimum of 10 characters";
}
if($password != $cpassword) {
$cpassword_error = "Password and Confirm Password doesn't match";
}
if(mysqli_query($conn, "INSERT INTO user(username,password,name,emailid,age,location,role) VALUES('" . $username . "', '" . md5($password) . "', '" . $name . "', '" . $emailid . "','" . $age . "','" . $location . "','" . $role . "')")) {
header("location:http://localhost/test/?url=users_index");
exit();
} else {
$error = 'Invalid Username or Password';
}
mysqli_close($conn);
}
?>
Registration Form:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>G&L Management System</title>
<!-- BOOTSTRAP STYLES-->
<link href="css/bootstrap.css" rel="stylesheet" />
<!-- FONTAWESOME STYLES-->
<link href="css/font-awesome.css" rel="stylesheet" />
<!-- GOOGLE FONTS-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
<style>
#font-face {
font-family: Poppins;
src: url("fonts/Poppins-Regular.ttf");
}
html * {
font-family: "Poppins", sans-serif;
}
.myhead{
margin-top:0px;
margin-bottom:0px;
text-align:center;
}
</style>
</head>
<body>
<center>
<img src="banner.png" style="width: 300px; height: 250px;">
</center>
<div class="container">
<div class="row ">
<div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">
<div class="panel-body" style="background-color: #E2E2E2; margin-top:70px; box-shadow: 5px 10px #888888;">
<h3 class="myhead">User Registration</h3>
<form role="form" action="register.php" method="post">
<br>
<label>Username</label>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-user" ></i><?php if (isset($username_error)) echo $username_error; ?></span>
<input type="text" class="form-control" placeholder="Username" name="username" required />
</div>
<label>Password</label>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-lock" ></i><?php if (isset($password_error)) echo $password_error; ?></span>
<input type="password" class="form-control" placeholder="Password" name="password" required />
</div>
<label>Name</label>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-user" ></i><?php if (isset($name_error)) echo $name_error; ?></span>
<input type="text" class="form-control" placeholder="Name" name="name" required />
</div>
<label>Email</label>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-envelope" ></i><?php if (isset($emailid_error)) echo $emailid_error; ?></span>
<input type="text" class="form-control" placeholder="Email" name="emailid" required />
</div>
<label>Age</label>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-child" ></i><?php if (isset($age_error)) echo $age_error; ?></span>
<input type="number" class="form-control" placeholder="Age" name="age" required />
</div>
<label>Location</label>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-map-marker" ></i><?php if (isset($location_error)) echo $location_error; ?></span>
<input type="text" class="form-control" placeholder="Location" name="location" required />
</div>
<div>
<input type="submit" class="btn btn-success" name="signup" value="Submit">
<div class="form-group text-center">
<div class="col-sm-12 mt-3">
Already have an account?
<p>Login Here</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
You can simply set default value for column "role" to trainee, that way whenever new user is created it is assigned role of trainee automatically.
ALTER TABLE `user`
ALTER `role` SET DEFAULT "trainees";
otherwise you can add drop down like this
<label for="role">Choose a role:</label>
<select id="role" name="role">
<option value="admin">Admin</option>
<option value="coach">Coach</option>
<option value="trainees">Trainees</option>
</select>
I'm new to development. Try to Learning php but I'm Having issue with php form. Here Is my Problem. I have Two Form In a page. So, When I submit data in first form then second form show > > Undefined index. Other hand, When I submit data in second form then first form show > > Undefined index. I'm try to receive data using >>> $_SERVER["PHP_SELF"]
Here Is my Enter Code
<!DOCTYPE html>
<html>
<head>
<title> Hello world</title>
<link rel= "stylesheet" href="style.css" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body class="container mt-5">
<?php
$name=$email="";
if($_SERVER["REQUEST_METHOD"]=="POST"){
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
}
function test_input($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" class="row">
<div class="col-auto">
<label class="visually-hidden" for="autoSizingInput"> Name</label>
<input type="text" class="form-control" id="autoZizingInput" name="name" placeholder="User name"></input>
</div>
<div class="col-auto">
<input type="email" class="form-control" id="autoZizingInput" name="email" placeholder="Enter Email"></input>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
<div class="container">
<div class="row mt-5">
<?php
if(!empty($name)&& !empty($email)):?>
<h1>Your Name Is <?php echo $name;?> & Email Address <?php echo $email;?></h1>
<?php
endif;
?>
</div>
</div>
<?php
$color="";
if($_SERVER["REQUEST_METHOD"]=="POST"):
$color = $_POST["color"];
endif;
?>
<form class="row mt-5" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<input type="text" class="form-control" placeholder="Enter colot name" name="color"></input>
<button type="submit" class="btn btn-danger mt-5"> Submit</button>
</form>
<div class="row">
<?php
if(!empty($color)):?>
<h1>Color Is <?php echo $color;?><h1>
<?php
endif;
?>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title> Hello world</title>
<link rel="stylesheet" href="style.css" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body class="container mt-5">
<?php
$name = "";
$email = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = test_input(isset($_POST["name"]) ? $_POST["name"] : '');
$email = test_input(isset($_POST["email"]) ? $_POST["email"] : '');
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" class="row">
<div class="col-auto">
<label class="visually-hidden" for="autoSizingInput"> Name</label>
<input type="text" class="form-control" id="autoZizingInput" name="name" placeholder="User name"></input>
</div>
<div class="col-auto">
<input type="email" class="form-control" id="autoZizingInput" name="email" placeholder="Enter Email"></input>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
<div class="container">
<div class="row mt-5">
<?php
if (!empty($name) && !empty($email)) : ?>
<h1>Your Name Is <?php echo isset($name) ? $name : ''; ?> & Email Address <?php echo isset($email) ? $email : ''; ?></h1>
<?php
endif;
?>
</div>
</div>
<?php
$color = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") :
$color = isset($_POST["color"]) ? $_POST["color"] : '';
endif;
?>
<form class="row mt-5" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<input type="text" class="form-control" placeholder="Enter colot name" name="color"></input>
<button type="submit" class="btn btn-danger mt-5"> Submit</button>
</form>
<div class="row">
<?php
if (!empty($color)) : ?>
<h1>Color Is <?php echo $color; ?><h1>
<?php
endif;
?>
</div>
</body>
</html>
The isset() function checks whether a variable is set, which means that it has to be declared and is not NULL.
This function returns true if the variable exists and is not NULL, otherwise it returns false.
I am new to PHP so please help me out
the errors that I keep getting are
Notice: Undefined index: image1 in C:\wamp\www\Tech Cube\add-product.php on line 12
Warning: file_get_contents(): Filename cannot be empty in C:\wamp\www\Tech Cube\add-product.php on line 12
Notice: Undefined index: image2 in C:\wamp\www\Tech Cube\add-product.php on line 13
Warning: file_get_contents(): Filename cannot be empty in C:\wamp\www\Tech Cube\add-product.php on line 13
and my code is
<?php
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,'techcubedb');
if(isset($_POST['add']))
{
if(!empty($_POST['name']) && !empty($_POST['price']) &&!empty($_POST['image1']) &&!empty($_POST['image2'])){
$name = $_POST['name'];
$price = $_POST['price'];
$description = $_POST['description'];
$image1 = addslashes(file_get_contents($_FILES["image1"]["tmp_name"]));
$image2 = addslashes(file_get_contents($_FILES["image2"]["tmp_name"]));
$query = "INSERT INTO 'products'('name','price','description','image1','image2')VALUES ('$name','$price','$description','$image1','$image2')";
$query_run=mysqli_query($connection,$query);
if($query_run)
{
echo '<script type="text/javascript"> alert("Product Added")</script>';
}
else{
echo '<script type="text/javascript"> alert("Product not Added")</script>';
}
}
else{
echo '<script type="text/javascript"> alert("All fields are required")</script>';
}
}
?>
<!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>add product</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<Center>
<div class="container">
<div class="col-md-6 mx-auto text-center">
<div class="header-title">
<br><br>
<h1 class="wv-heading--title">
Add Product
</h1>
</div>
<br>
</div>
<div class="row">
<div class="col-md-4 mx-auto">
<div class="myform form ">
<form action=" " method="post" encrtype="multipart/form-data">
<div class="form-group ">
<label>Product name</label>
<input type="text" name="name" class="form-control" >
<span class="help-block"></span>
</div>
<div class="form-group ">
<label>Price</label>
<input type="text" name="price" class="form-control" >
<span class="help-block"></span>
</div>
<div class="form-group ">
<label>Description</label>
<textarea type="text" name="description" class="form-control" ></textarea>
<span class="help-block"></span>
</div>
<div class="form-group ">
<label>Images</label><br>
<input type="file" name="image1" id="image1">
<span class="help-block"></span>
</div>
<div class="form-group ">
<input type="file" name="image2" id="image2">
<span class="help-block"></span>
</div>
<br>
<br>
<div class="form-group">
<input type="submit" name="add" class="btn btn-primary" value="Add Product">
</div>
</form>
</div>
</div>
</div>
</div>
</Center>
</body>
</html>
May be you will need two edits...
enctype="multipart/form-data"
instead of
encrtype="multipart/form-data"
And
!empty($_FILES['image1']['name'] ) && !empty($_FILES['image2']['name'])
And one more thing is...
you will need to check and verify uploaded file's type, size etc for security reason....
How to save the updated total of stocks after it minus ? [php-json]
i need to get the current stocks and minus it to the quantity bought by the customer. and it will post to the order.json and get the total payment and
i need to update the food.json for the stocks and to put the orderlist on order.json
This is the code to get the value of buy product but the quantity entered by the customer do not minus on the stocks and do not get the total. I think there is wrong in my codes. Please Help me. Im just a beginner to json
<?php
if (isset($_GET["id"])) {
$id = (int) $_GET["id"];
$getfile = file_get_contents('food.json');
$jsonfile = json_decode($getfile, true);
$jsonfile = $jsonfile["records"];
$jsonfile = $jsonfile[$id];
}
if (isset($_POST["id"])) {
$id = (int) $_POST["id"];
$getfile = file_get_contents('food.json');
$all = json_decode($getfile, true);
$jsonfile = $all["records"];
$jsonfile = $jsonfile[$id];
$quan = $_POST['quan'];
$stocks = $stocks - $quan; // on minusing the stocks :<
$post["pname"] = isset($_POST["pname"]) ? $_POST["pname"] : "";
$post["price"] = isset($_POST["price"]) ? $_POST["price"] : "";
$post["stocks"] = isset($_POST["stocks"]) ? $_POST["stocks"] : "";
// $post["quan"] = isset($_POST["quan"]) ? $_POST["quan"] : "";
if ($jsonfile) {
unset($all["records"][$id]);
$all["records"][$id] = $post;
$all["records"] = array_values($all["records"]);
file_put_contents("food.json", json_encode($all));
}
header("Location:index_crudjson.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="tutorial-boostrap-merubaha-warna">
<meta name="author" content="ilmu-detil.blogspot.com">
<title></title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<style type="text/css">
.navbar-default {
background-color: #3b5998;
font-size:18px;
color:#ffffff;
}
</style>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<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>
<h4>JSON Bake Shop</h4>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
</div>
</div>
</nav>
<!-- /.navbar -->
<div class="container">
<div class="row">
<div class="row">
<h3>Buy a Product</h3>
</div>
<?php if (isset($_GET["id"])): ?>
<form method="POST" action="buy.php">
<div class="col-md-6">
<input type="hidden" value="<?php echo $id ?>" name="id"/>
<div class="form-group">
<label for="inputFName">Product Name</label>
<input type="text" class="form-control" required="required" id="inputFName" value="<?php echo $jsonfile["pname"] ?>" name="pname" placeholder="Product Name">
<span class="help-block"></span>
</div>
<div class="form-group">
<label for="inputLName">Price</label>
<input type="number" class="form-control" required="required" id="inputLName" value="<?php echo $jsonfile["price"] ?>" name="price" placeholder="Price">
<span class="help-block"></span>
</div>
<div class="form-group">
<label for="inputAge">Stocks</label>
<input type="number" required="required" class="form-control" id="inputAge" value="<?php echo $jsonfile["stocks"] ?>"
name="stocks" placeholder="Stocks">
<span class="help-block"></span>
</div>
<div class="form-group">
<label for="inputAge">Quantity</label>
<input type="number" required="required" class="form-control" id="inputAge" value="<?php echo $jsonfile["quan"] ?>"
name="quan" placeholder="Quantity">
<span class="help-block"></span>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-warning">Buy</button>
<a class="btn btn btn-default" href="index_crudjson.php">Back</a>
</div>
</div>
</form>
<?php endif; ?>
</div> <!-- /row -->
</div> <!-- /container -->
</body>
</html>
This is the attached sample of order.json, food.json, index and buy.phpsample picturefood.json
You have a simple error on you $post assignment
$post["stocks"] = $stocks;
I could not understand clearly your logic, but $stocks is not used at all, and the real stocks value should not be in $_POST.
I want to know how to display a user's username inside a textbox. I'm doing this because when they edit their settings and update them, it updates their email etc to blank fields in the database:
Here's the code i'd like to change
<input type="text" name="name" class="form-control" id="name" class="required" value="<? echo $row_settings['full_name']; ?>" />
I'd like to make the `value = $row_settings['full_name'];'
How can i do this?
ALL CODE:
<?php
/********************** MYSETTINGS.PHP**************************
This updates user settings and password
************************************************************/
include 'dbc.php';
page_protect();
$err = array();
$msg = array();
if($_POST['doUpdate'] == 'Update')
{
$rs_pwd = mysql_query("select pwd from users where id='$_SESSION[user_id]'");
list($old) = mysql_fetch_row($rs_pwd);
$old_salt = substr($old,0,9);
//check for old password in md5 format
if($old === PwdHash($_POST['pwd_old'],$old_salt))
{
$newsha1 = PwdHash($_POST['pwd_new']);
mysql_query("update users set pwd='$newsha1' where id='$_SESSION[user_id]'");
$msg[] = "Your new password is updated";
//header("Location: mysettings.php?msg=Your new password is updated");
} else
{
$err[] = "Your old password is invalid";
//header("Location: mysettings.php?msg=Your old password is invalid");
}
}
if($_POST['doSave'] == 'Save')
{
// Filter POST data for harmful code (sanitize)
foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}
mysql_query("UPDATE users SET
`full_name` = '$data[name]',
`address` = '$data[address]',
`tel` = '$data[tel]',
`user_email` = '$data[user_email]',
`user_name` = '$data[user]',
`fax` = '$data[fax]',
`country` = '$data[country]',
`website` = '$data[web]'
WHERE id='$_SESSION[user_id]'
") or die(mysql_error());
//header("Location: mysettings.php?msg=Profile Sucessfully saved");
$msg[] = "Profile Sucessfully saved";
}
$rs_settings = mysql_query("select * from users where id='$_SESSION[user_id]'");
?>
<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="">
<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
<script>
$(document).ready(function(){
$("#myform").validate();
$("#pform").validate();
});
</script>
<title>The Infibox - Edit Profile</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/indexSettings.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[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 class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<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>
<?php if (isset($_SESSION['user_id'])) {?>
<a class="navbar-brand" href="#">Infibox</a>
<a class="navbar-brand">|</a>
<a class="navbar-brand" href="/recruitment">My Account</a>
<a class="navbar-brand" href="#">Settings</a>
<a class="navbar-brand" href="#">Logout</a>
<?php }
?>
<?php
if (checkAdmin()) {
/*******************************END**************************/
?>
<a class="navbar-brand" href="admin.php">Admin CP </a>
<?php } ?>
</div>
<div class="navbar-collapse collapse">
<form class="navbar-form navbar-right" role="form">
<div class="form-group">
<input type="text" placeholder="Email" class="form-control">
</div>
<div class="form-group">
<input type="password" placeholder="Password" class="form-control">
</div>
<button type="submit" class="btn btn-success">Sign in</button>
</form>
</div><!--/.navbar-collapse -->
</div>
</div>
<!-- Main jumbotron for a primary marketing message or call to action -->
<p>
<?php
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* Error - $e <br>";
}
echo "</div>";
}
if(!empty($msg)) {
echo "<div class=\"msg\">" . $msg[0] . "</div>";
}
?>
</p>
<!-- Show their details inside the correct box. E.g. their first name they registered with will be shown inside the "First Name" box. Does not occur with passwords. -->
<center>
<div class="wrapper">
<h2 class="title">Edit Profile</h2>
<?php while ($row_settings = mysql_fetch_array($rs_settings)) ?>
<form action="mysettings1.php" method="post" name="myform" id="myform">
<div class="input-group" id="fname">
<span class="input-group-addon">Name</span>
<input type="text" name="name" class="form-control" id="name" class="required" value="<? echo $row_settings['full_name']; ?>" />
</div>
<div class="input-group">
<span class="input-group-addon">Customer ID</span>
<input type="text" name="user" class="form-control" maxlength="6" id="web2" value="<? echo $row_settings['user_name']; ?>">
</div>
<div class="input-group">
<span class="input-group-addon">Email</span>
<input type="text" class="form-control" name="user_email" id="web3" value="<? echo $row_settings['user_email']; ?>">
</div>
<div class="input-group">
<span class="input-group-addon">Add Paypal Email</span>
<input type="text" class="form-control" name="tel" id="tel" class="required" value="<? echo $row_settings['tel']; ?>">
</div>
<div class="btn-group">
<input name="doSave" type="submit" id="doSave" value="Save" class="btn btn-success">
</div>
<hr class="hr" />
<!-- When Changing Password Old Password Must Be Entered + Correct-->
<h2 class="title2">Change Password</h2>
<div class="input-group">
<span class="input-group-addon">Old Password</span>
<input type="password" class="form-control" name="pwd_old" class="required password" id="pwd_old" >
</div>
<div class="input-group">
<span class="input-group-addon">New Password</span>
<input type="password" class="form-control" name="pwd_new" class="required password" id="pwd_new" >
</div>
<div class="btn-group">
<input name="doUpdate" type="submit" id="doUpdate" value="Update" class="btn btn-success">
</div>
</div>
</center>
</form>
<!-- ##################################################################################### -->
<!-- ##################################################################################### -->
</div>
</center>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
You do not need a while loop:
Change
<?php while ($row_settings = mysql_fetch_array($rs_settings)) ?>
with
<?php $row_settings = mysql_fetch_array($rs_settings); ?>