I can't seem to find my PHP variable $quote_date. I have a form that grabs job records from the database and displays a job's current progress in the form ready to be edited, submitted and updated to the database. All of the job's other records are being collected and displayed correctly but the $quote_date is missing in action. Yet when I echo the $quote_date after the renderForm() function is executed it appears to really exist, at least at that point. Why is the $quote_date not being displayed in the form?
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Allow the user to both create new records and edit existing records.
// Connect to the database.
$connect = mysqli_connect('localhost', 'username', 'password', 'database');
if ( !$connect ) {
die( 'connect error: '.mysqli_connect_error() );
}
// creates the new/edit record form.
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($error = '', $id = '', $start_date = '', $company = '', $stock_code = '', $card_quantity = '', $fiske_print = '', $carrier_quantity = '', $quoted = '', $quote_details = '', $quoted_date = '', $quote_accepted = '', $quote_accepted_date = '', $proof_sent = '', $proof_sent_date = '', $proof_approved = '', $proof_approved_date = '', $printed = '', $print_date = '', $closed_loop_allocated = '', $invoiced = '', $invoiced_date = '', $posted = '', $tracking_number = '', $postal_date = '', $paid = '', $is_bulk_load = '', $bulk_funds_recieved = '', $cards_loaded = '', $notes = '', $completed = '')
{
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<?php
$pageName = 'overview';
?>
<?php
include('header.php');
?>
<h1><?php
if ($id != '') {
echo "Edit Record";
} else {
echo "New Record";
}
?></h1>
<?php
if ($error != '') {
echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error . "</div>";
}
?>
<form action="" method="post">
<div>
<table>
<tr>
<td colspan="2" style="text-align:center;"><strong>Job Details</strong></td>
<td colspan="2" style="text-align:center;"><strong>Job Progress</strong></td>
</tr>
<tr>
<td>ID: </td>
<td><input type="text" name="id" value="<?php echo $id; ?>" readonly></td>
<td>Quoted: </td>
<td><input type="checkbox" name="quoted" value="1" <?php if($quoted == 1){echo 'checked';} ?>></td>
</tr>
<tr>
<td>Start Date: </td>
<td><input type="date" name="start_date" value="<?php if($start_date !== ''){echo date('Y-m-d',strtotime($start_date));} ?>"></td>
<td>Quote Details: </td>
<td><input type="text" name="quote_details" size="40" value="<?php echo $quote_details; ?>"></td>
</tr>
<tr>
<td>Company: </td>
<td><input type="text" name="company" size="40" value="<?php echo $company; ?>"></td>
<td>Quote Date: </td>
// Here is where the mystery lies why is my $quote_date variable missing?
<td><input type="date" name="quote_date" value="<?php echo date('Y-m-d',strtotime($quote_date)); ?>"></td><?php echo '<script type="text/javascript">alert("'.$quote_date.'");</script>'; ?>
</tr>
<tr>
<td>Stock Code: </td>
<td>
<div id="billdesc">
<select id="test" name="stock_code">
<option class="non" value="GS01">GS01</option>
<option class="non" value="GS03">GS03</option>
<option class="non" value="SM01">SM01</option>
<option class="non" value="SM11">SM11</option>
<option class="non" value="CG01">CG01</option>
<option class="non" value="CG38">CG38</option>
<option class="editable" value="Other">Other</option>
</select>
<input class="editOption" style="display:none;" placeholder="Text juaj"></input>
</div>
</td>
<td>Quote Accepted: </td>
<td><input type="checkbox" name="quote_accepted" value="1" <?php if($quote_accepted == 1){echo 'checked';} ?>></td>
</tr>
<tr>
<td>Card Quantity: </td>
<td><input type="text" name="card_quantity" value="<?php echo $card_quantity; ?>"></td>
<td>Quote Accepted Date: </td>
<td><input type="date" name="quote_accepted_date" value="<?php if($quote_accepted_date !== ''){echo date('Y-m-d',strtotime($quote_accepted_date));} ?>"></td>
</tr>
<tr>
<td>Carrier Quantity: </td>
<td><input type="text" name="carrier_quantity" value="<?php echo $carrier_quantity; ?>"></td>
<td>Proof Sent: </td>
<td><input type="checkbox" name="proof_sent" value="1" <?php if($proof_sent == 1){echo 'checked';} ?>></td>
</tr>
<tr>
<td>Fiske Print: </td>
<td><input type="checkbox" name="fiske_print" value="1" <?php if($fiske_print == 1){echo 'checked';} ?>></td>
<td>Proof Sent Date: </td>
<td><input type="date" name="proof_sent_date" value="<?php if($proof_sent_date !== ''){echo date('Y-m-d',strtotime($proof_sent_date));} ?>"></td>
</tr>
<tr>
<td rowspan="6" colspan="2" style="text-align:center;">
Notes:<br>
<textarea name="notes" rows="8" cols="70"><?php echo $notes; ?></textarea>
</td>
<td style="text-align:right;">Proof Approved: </td>
<td style="text-align:left;"><input type="checkbox" name="proof_approved" value="1" <?php if($proof_approved == 1){echo 'checked';} ?>></td>
</tr>
<tr>
<td>Proof Approved Date: </td>
<td><input type="date" name="proof_approved_date" value="<?php if($proof_approved_date !== ''){echo date('Y-m-d',strtotime($proof_approved_date));} ?>"></td>
</tr>
<tr>
<td>Printed: </td>
<td><input type="checkbox" name="printed" value="1" <?php if($printed == 1){echo 'checked';} ?>></td>
</tr>
<tr>
<td>Print Date</td>
<td><input type="date" name="printed_date" value="<?php if($print_date !== ''){echo date('Y-m-d',strtotime($print_date));} ?>"></td>
</tr>
<tr>
<td>Closed Loop Allocated: </td>
<td><input type="checkbox" name="closed_loop_allocated" value="1" <?php if($closed_loop_allocated == 1){echo 'checked';} ?>></td>
</tr>
<tr>
<td>Invoiced: </td>
<td><input type="checkbox" name="invoiced" value="1" <?php if($invoiced == 1){echo 'checked';} ?>></td>
</tr>
<tr>
<td>Paid: </td>
<td><input type="checkbox" name="paid" value="1" <?php if($paid == 1){echo 'checked';} ?>></td>
<td>Invoice Date: </td>
<td><input type="date" name="invoice_date" value="<?php if($invoice_date !== ''){echo date('Y-m-d',strtotime($invoice_date));} ?>"></td>
</tr>
<tr>
<td>Is Bulk Load: </td>
<td><input type="checkbox" name="is_bulk_load" value="1" <?php if($is_bulk_load == 1){echo 'checked';} ?>></td>
<td>Posted: </td>
<td><input type="checkbox" name="posted" value="1" <?php if($posted == 1){echo 'checked';} ?>></td>
</tr>
<tr>
<td>Bulk Funds Recieved</td>
<td><input type="checkbox" name="bulk_funds_recieved" value="1" <?php if($bulk_funds_received == 1){echo 'checked';} ?> ></td>
<td>Postal Date: </td>
<td><input type="date" name="postal_date" value="<?php if($postal_date !== ''){echo date('Y-m-d',strtotime($postal_date));} ?>"></td>
</tr>
<tr>
<td>Cards Loaded: </td>
<td><input type="checkbox" name="cards_loaded" value="1" <?php if($cards_loaded == 1){echo 'checked';} ?>></td>
<td>Tracking Number: </td>
<td><input type="text" name="tracking_number" size="30" value="<?php echo $tracking_number; ?>"></td>
</tr>
<tr>
<td colspan="4" style="text-align:center;">
Completed: <input type="checkbox" name="completed" value="1" <?php if($completed == 1){echo 'checked';} ?>>
<input type="submit" name="submit" value="Save" style="width:90px" />
</td>
</tr>
</table>
<script type="text/javascript">
var initialText = $('.editable').val();
$('.editOption').val(initialText);
$('#test').change(function(){
var selected = $('option:selected', this).attr('class');
var optionText = $('.editable').text();
if(selected == "editable"){
$('.editOption').show();
$('.editOption').keyup(function(){
var editText = $('.editOption').val();
$('.editable').val(editText);
$('.editable').html(editText);
});
}else{
$('.editOption').hide();
}
});
</script>
</body>
</html>
<?php
}
/*
EDIT RECORD
*/
// if the 'id' variable is set in the URL, we know that we need to edit an existing record
if (isset($_GET['id'])) {
// if the form's submit button is clicked, we need to process the form
if (isset($_POST['submit'])) {
// make sure the 'id' in the URL is valid
if (is_numeric($_POST['id'])) {
// get the form data
// I'll get to this later... get form to display first...
echo 'We are saving a new edit of job ' . $id;
}
// if the 'id' variable is not valid, show an error message
else {
echo "Error!";
}
}
// if the form hasn't been submitted yet, get the info from the database and show the form
else {
// make sure the 'id' value is valid
if (is_numeric($_GET['id']) && $_GET['id'] > 0) {
// get 'id' from URL
$id = $_GET['id'];
// get the record from database
if ($stmt = $connect->prepare("SELECT id, start_date, company, stock_code, card_quantity, fiske_print, carrier_quantity, quoted, quote_details, quoted_date, quote_accepted, quote_accepted_date, proof_sent, proof_sent_date,proof_approved, proof_approved_date, printed, print_date, closed_loop_allocated, invoiced, invoiced_date, posted, tracking_number, postal_date, paid, is_bulk_load, bulk_funds_received, cards_loaded, notes, completed FROM jobs WHERE id = ?")) {
$stmt->bind_param("s", $id);
$stmt->execute();
$stmt->bind_result($id,$start_date,$company,$stock_code,$card_quantity,$fiske_print,$carrier_quantity,$quoted,$quote_details,$quote_date,$quote_accepted,$quote_accepted_date,$proof_sent,$proof_sent_date,$proof_approved,$proof_approved_date,$printed,$printed_date,$closed_loop_allocated,$invoiced,$invoice_date,$posted,$tracking_number,$postal_date,$paid,$is_bulk_load,$bulk_funds_received,$cards_loaded,$notes,$completed);
/* fetch values */
while ($stmt->fetch()) {
printf("%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n", $id,$start_date,$company,$stock_code,$card_quantity,$fiske_print,$carrier_quantity,$quoted,$quote_details,$quote_date,$quote_accepted,$quote_accepted_date,$proof_sent,$proof_sent_date,$proof_approved,$proof_approved_date,$printed,$printed_date,$closed_loop_allocated,$invoiced,$invoice_date,$posted,$tracking_number,$postal_date,$paid,$is_bulk_load,$bulk_funds_received,$cards_loaded,$notes,$completed);
}
// show the form by executing renderForm()
renderForm(NULL, $id,$start_date,$company,$stock_code,$card_quantity,$fiske_print,$carrier_quantity,$quoted,$quote_details,$quote_date,$quote_accepted,$quote_accepted_date,$proof_sent,$proof_sent_date,$proof_approved,$proof_approved_date,$printed,$printed_date,$closed_loop_allocated,$invoiced,$invoice_date,$posted,$tracking_number,$postal_date,$paid,$is_bulk_load,$bulk_funds_received,$cards_loaded,$notes,$completed);
// check to see if we have a quote date..?
echo 'quote date: '.$quote_date;
$stmt->close();
}
// show an error if the query has an error
else {
echo "Error: could not prepare SQL statement";
}
}
// if the 'id' value is not valid, redirect the user back to the view.php page
else {
header("Location: addJob.php");
}
}
}
/*
NEW RECORD
*/
// if the 'id' variable is not set in the URL, we must be creating a new record
else {
// if the form's submit button is clicked, we need to process the form
if (isset($_POST['submit'])) {
// get the form data
$start_date = date("Y-m-d", strtotime($_POST['start_date']));
$company = $_POST['company'];
$stock_code = $_POST['stock_code'];
$card_quantity = $_POST['card_quantity'];
$carrier_quantity = $_POST['carrier_quantity'];
$fiske_print = $_POST['fiske_print'];
$quoted = $_POST['quoted'];
$quote_details = $_POST['quote_details'];
$quote_date = date("Y-m-d", strtotime($_POST['quote_date']));
$quote_accepted = $_POST['quote_accepted'];
$quote_accepted_date = date("Y-m-d", strtotime($_POST['quote_accepted_date']));
$proof_sent = $_POST['proof_sent'];
$proof_sent_date = date("Y-m-d", strtotime($_POST['proof_sent_date']));
$proof_approved = $_POST['proof_approved'];
$proof_approved_date = date("Y-m-d", strtotime($_POST['proof_approved_date']));
$printed = $_POST['printed'];
$printed_date = date("Y-m-d", strtotime($_POST['printed_date']));
$closed_loop_allocated = $_POST['closed_loop_allocated'];
$invoiced = $_POST['invoiced'];
$invoice_date = date("Y-m-d", strtotime($_POST['invoice_date']));
$posted = $_POST['posted'];
$postal_date = date("Y-m-d", strtotime($_POST['postal_date']));
$tracking_number = $_POST['tracking_number'];
$paid = $_POST['paid'];
$is_bulk_load = $_POST['is_bulk_load'];
$bulk_funds_received = $_POST['bulk_funds_received'];
$cards_loaded = $_POST['cards_loaded'];
$completed = $_POST['completed'];
/* Prepare an insert statement */
$query = "INSERT INTO jobs (start_date,company,stock_code,card_quantity,fiske_print,carrier_quantity,quoted,quote_details,quoted_date,quote_accepted,quote_accepted_date,proof_sent,proof_sent_date,proof_approved,proof_approved_date,printed,print_date,closed_loop_allocated,invoiced,invoiced_date,posted,tracking_number,postal_date,paid,is_bulk_load,bulk_funds_received,cards_loaded,notes,completed) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$stmt = mysqli_prepare($connect, $query);
mysqli_stmt_bind_param($stmt, "sssssssssssssssssssssssssssss", $start_date,$company,$stock_code,$card_quantity,$fiske_print,$carrier_quantity,$quoted,$quote_details,$quote_date,$quote_accepted,$quote_accepted_date,$proof_sent,$proof_sent_date,$proof_approved,$proof_approved_date,$printed,$printed_date,$closed_loop_allocated,$invoiced,$invoice_date,$posted,$tracking_number,$postal_date,$paid,$is_bulk_load,$bulk_funds_received,$cards_loaded,$notes,$completed);
/* Execute the statement */
mysqli_stmt_execute($stmt);
/* close statement */
mysqli_stmt_close($stmt);
// redirect the user
header("Location: index.php");
}
// if the form hasn't been submitted yet, show the form
else {
error_log('SQL error ('.__FILE__.' line '.__LINE__.'): '. $connect->error);
renderForm();
}
}
// close the mysqli connection
$connect->close();
?>
I am creating a mini bio-metric application in php. i want to be able to attach the capture image to the registration form and save it to mysql database. I was able to find some source code online for capturing the image using webcam.js but I need to attach the captured image to the form for submission to the database.
here is the html source code
<div align="center">
<form method='post' id='emp-SaveForm' action="#" style="width:70%;">
<div class="row">
<div class="col-md-6">
<!-- -->
<div id="my_camera"></div>
<!--<input type=button value="Configure" onClick="configure()" class="btn btn-warning">-->
<input type=button value="Take Snapshot" onClick="take_snapshot()" class="btn btn-info">
<input type=button value="Save Snapshot" onClick="saveSnap()" class="btn btn-success">
</div>
<div class="col-md-4">
<div id="results" ></div>
</div>
</div>
<table class='table table-striped'>
<tr>
<td>Name</td>
<td><input type='text' name='name' class='form-control' placeholder='EX : Surname Othernames' /></td>
</tr>
<tr>
<td>D.o.B</td>
<td><input type='text' name='dob' class='form-control datepicker' placeholder='' ></td>
</tr>
<tr>
<td>Gender</td>
<td>
<select name="gender">
<option value="">Select Gender</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</td>
</tr>
<tr>
<td>BVN</td>
<td><input type='text' name='bvn' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Business Name</td>
<td><input type='text' name='business_name' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Contact Address</td>
<td><input type='text' name='contact_addr' class='form-control ' placeholder=''></td>
</tr>
<tr>
<td>Town/City</td>
<td><input type='text' name='Town_City' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>L.G.A</td>
<td><input type='text' name='lga' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>State</td>
<td>
<select class="form-control" name="state">
<option value="">-- Select State --</option>
<option value="Abia" >Abia</option><option value="Abuja" >Abuja</option><option value="Adamawa" >Adamawa</option><option value="Akwa_ibom" >Akwa-ibom</option><option value="Anambra" >Anambra</option><option value="Bauchi" >Bauchi</option><option value="Bayelsa" >Bayelsa</option><option value="Benue" >Benue</option><option value="Borno" >Borno</option><option value="Cross_River" >Cross-River</option><option value="Delta" >Delta</option><option value="Ebonyi" >Ebonyi</option><option value="Edo" >Edo</option><option value="Ekiti" >Ekiti</option><option value="Enugu" >Enugu</option><option value="Gombe" >Gombe</option><option value="Imo" >Imo</option><option value="International" >International</option><option value="Jigawa" >Jigawa</option><option value="Kaduna" >Kaduna</option><option value="Kano" >Kano</option><option value="Kastina" >Kastina</option><option value="Kebbi" >Kebbi</option><option value="Kogi" >Kogi</option><option value="Kwara" >Kwara</option><option value="Lagos" >Lagos</option><option value="Nasarawa" >Nasarawa</option><option value="Niger" >Niger</option><option value="Ogun" >Ogun</option><option value="Ondo" >Ondo</option><option value="Osun" >Osun</option><option value="Oyo" >Oyo</option><option value="Plateau" >Plateau</option><option value="Rivers" >Rivers</option><option value="Sokoto" >Sokoto</option><option value="Taraba" >Taraba</option><option value="Yobe" >Yobe</option><option value="Zamfara" >Zamfara</option> </select>
</td>
</tr>
<tr>
<td>Phone 1</td>
<td><input type='text' name='phone_1' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Phone 2</td>
<td><input type='text' name='phone_2' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Email Address</td>
<td><input type='text' name='email' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Products and Service Render</td>
<td><input type='text' name='products_services_rendered' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Sub Society Name</td>
<td><input type='text' name='sub_society_name' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Position</td>
<td><input type='text' name='position' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Next of kin Name</td>
<td><input type='text' name='next_kin_name' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Relationship</td>
<td><input type='text' name='relationship' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Phone of Next of Kin</td>
<td><input type='text' name='phone_of_next_kin' class='form-control' placeholder=''></td>
</tr>
<tr>
<td>Payment Status</td>
<td>
<select name="payment_status" class="from-control">
<option value=""></option>
<option value="Paid">Paid</option>
<option value="Unpaid">Unpaid</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="mem_id_no" value="" />
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save Record
</button>
</td>
</tr>
</table>
</form>
</div>
php for submitting the form
<?php
require_once 'db/dbconfig.php';
require_once 'db/db_connect.php';
if($_POST)
{
$query = "SELECT MAX(CAST(id as decimal))id from users";
if($result = mysqli_query($conn, $query))
{
$rowy = mysqli_fetch_assoc($result);
$count = $rowy['id'];
$count = $count+1;
$code_no = str_pad($count, 4, "0", STR_PAD_LEFT);
}
$str = substr(sha1(mt_rand() . microtime()), mt_rand(0,35), 3);
$name = $_POST['name'];
$dob = $_POST['dob'];
$gen = $_POST['gender'];
$bvn = $_POST['bvn'];
$bn = $_POST['business_name'];
$ca = $_POST['contact_addr'];
$tc = $_POST['Town_City'];
$lga = $_POST['lga'];
$st = $_POST['state'];
$p1 = $_POST['phone_1'];
$p2 = $_POST['phone_2'];
$email = $_POST['email'];
$psr = $_POST['products_services_rendered'];
$ssn = $_POST['sub_society_name'];
$posi = $_POST['position'];
$min = $str.$code_no;
$nkn = $_POST['next_kin_name'];
$rel = $_POST['relationship'];
$ponk = $_POST['phone_of_next_kin'];
$ps = $_POST['payment_status'];
$pho = $_POST['photo'];
$sig = $_POST['signature'];
$dat = date("y:m:d H:m:i");
try{
$stmt = $db_con->prepare("INSERT INTO users(
name,
dob,
gender,
bvn,
business_name,
contact_addr,
Town_City,
lga,
State,
phone_1,
phone_2,
email,
products_services_rendered,
sub_society_name,
position,
mem_id_no,
next_kin_name,
relationship,
phone_of_next_kin,
payment_status,
photo,
signature,
date_registered
) VALUES(:nam, :d, :gen, :bv,:bn,:ca,:tc,:lg,:st,:ph,:pha,:em,:psr,:ssn,:pos,:min,:nkn,:rel,:ponk,:ps,:ph,:sig,:dr)");
$stmt->bindParam(":nam", $name);
$stmt->bindParam(":d", $dob);
$stmt->bindParam(":gen", $gen);
$stmt->bindParam(":bv", $bvn);
$stmt->bindParam(":bn", $bn);
$stmt->bindParam(":ca", $ca);
$stmt->bindParam(":tc", $tc);
$stmt->bindParam(":lg", $lga);
$stmt->bindParam(":st", $st);
$stmt->bindParam(":ph", $p1);
$stmt->bindParam(":pha", $p2);
$stmt->bindParam(":em", $email);
$stmt->bindParam(":psr", $psr);
$stmt->bindParam(":ssn", $ssn);
$stmt->bindParam(":pos", $posi);
$stmt->bindParam(":min", $min);
$stmt->bindParam(":nkn", $nkn);
$stmt->bindParam(":rel", $rel);
$stmt->bindParam(":ponk", $ponk);
$stmt->bindParam(":ps", $ps);
$stmt->bindParam(":ph", $pho);
$stmt->bindParam(":sig", $sig);
$stmt->bindParam(":dr", $dat);
if($stmt->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
jquery for capturing the image
<script language="JavaScript">
// Configure a few settings and attach camera
function configure(){
Webcam.set({
width: 200,
height: 150,
image_format: 'jpeg',
jpeg_quality: 90
});
Webcam.attach( '#my_camera' );
}
// A button for taking snaps
// preload shutter audio clip
var shutter = new Audio();
shutter.autoplay = false;
shutter.src = navigator.userAgent.match(/Firefox/) ? 'shutter.ogg' : 'shutter.mp3';
function take_snapshot() {
// play sound effect
shutter.play();
// take snapshot and get image data
Webcam.snap( function(data_uri) {
// display results in page
document.getElementById('results').innerHTML =
'<img id="imageprev" src="'+data_uri+'"/>';
} );
Webcam.reset();
}
function saveSnap(){
// Get base64 value from <img id='imageprev'> source
var base64image = document.getElementById("imageprev").src;
Webcam.upload( base64image, 'upload.php', function(code, text) {
console.log('Save successfully');
//console.log(text);
});
}
</script>
The php code to move it to a local folder
<?php
// new filename
$filename = 'pic_'.date('YmdHis') . '.jpeg';
$url = '';
if( move_uploaded_file($_FILES['webcam']['tmp_name'],'upload/'.$filename) ){
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/upload/' . $filename;
}
// Return image url
echo $url;
here is my code ,, its working perfectly
html code:
">
Take A Picture
javascript code:
Webcam.set({
width: 300,
height: 300,
image_format: 'jpeg',
jpeg_quality: 90,
force_flash: false
});
Webcam.attach( '#my_camera' );
function take_snapshot() {
// take snapshot and get image data
Webcam.snap(function (data_uri) {
// display results in page
document.getElementById('results').innerHTML =
'<h3>Here is your image....</h3>' +
'<img src="' +data_uri+ '" width=\'280px\' height=\'250px\'/>';
Webcam.upload(data_uri, 'saveimages.php', function (code, text) {
alert("Successfull");
});
});
Webcam.reset();
}
php code:
require_once 'core/init.php';
$users_id = sanitize($_POST['users_id']);
$path = 'images/saved_images/webcam'.date('YmdHis').rand(383,1000).'.jpg';
move_uploaded_file($_FILES['webcam']['tmp_name'], $path);
$sql = "INSERT INTO trial(users_id,image) VALUES('$users_id','".$path."')";
$db->query($sql);
echo "<script>window.open('trailmodal.php','_self')</script>";
customer_register.php
<?php
session_start();
?>
<form action="customer_register.php" method="post" enctype="multipart/form-data">
<?php
if (isset($_POST['c_name']) && isset($_POST['c_email']) && isset($_POST['c_usrname']) && isset($_POST['c_password']) && isset($_POST['c_country']) && isset($_POST['c_city']) && isset($_POST['c_contact']) && isset($_POST['c_address']) && isset($_FILES['c_image']['name'])) {
$c_ip_add = getIp();
$c_name = $_POST['c_name'];
$c_email = $_POST['c_email'];
$c_username = $_POST['c_usrname'];
$c_password = $_POST['c_password'];
$c_country = $_POST['c_country'];
$c_city = $_POST['c_city'];
$c_contact = $_POST['c_contact'];
$c_address = $_POST['c_address'];
$c_image = #$_FILES['c_image']['name'];
$c_tmp_name = #$_FILES['c_image']['tmp_name'];
$location = 'customer/customer_images/';
if (!empty($c_name) && !empty($c_email) && !empty($c_username) && !empty($c_password) && !empty($c_country) && !empty($c_city) && !empty($c_contact) && !empty($c_address) && !empty($c_image)) {
move_uploaded_file($c_tmp_name, $location.$c_image);
$select_user = "SELECT customers_username FROM customers WHERE customers_username = '$c_username'";
$run_select_user = mysqli_query($conn, $select_user);
if (mysqli_num_rows($run_select_user) == NULL) {
$insert_customer = "INSERT INTO customers(customers_ip, customers_name, customers_email, customers_username, customers_pass, customers_country, customers_city, customers_contact, customers_address, customers_image) VALUES ('$c_ip_add', '$c_name', '$c_email', '$c_username', '$c_password', '$c_country', '$c_city', '$c_contact', '$c_address', '$c_image')";
$run_insert_customer = mysqli_query($conn, $insert_customer);
$select_cart = "SELECT * FROM cart WHERE ip_add = '$c_ip_add'";
$run_select_cart = mysqli_query($conn, $select_cart);
$check_cart = mysqli_num_rows($run_select_cart);
if ($check_cart == 0) {
$_SESSION['customer_email'] = $c_email;
$_SESSION['username'] = $c_username;
echo '<script>alert("Account has been successfully created")</script>';
echo '<script>window.open("customer/my_account.php","_self")</script>';
} else {
$_SESSION['customer_email'] = $c_email;
$_SESSION['username'] = $c_username;
echo '<script>alert("Account has been successfully created")</script>';
echo '<script>window.open("checkout.php","_self")</script>';
}
} else {
echo "<div align='center' style='color:white; font-size:20px; padding:20px 0px;'><b>The Username already exists. Please try another username.</b></div>";
}
} else {
echo "<div align='center' style='color:white; font-size:20px; padding:20px 0px;'><b>All Fileds are required</b></div>";
}
}
?>
<table align="center" width="750">
<thead>
<tr align="center">
<th colspan="3"><h1>Create an Account</h1></th>
</tr>
</thead>
<tbody>
<tr>
<td id="label" align="right">Name:</td>
<td><input type="text" name="c_name" size="40" required></td>
</tr>
<tr>
<td id="label" align="right">Email:</td>
<td><input type="text" name="c_email" size="40" required></td>
</tr>
<tr>
<td id="label" align="right">Username:</td>
<td><input type="text" name="c_usrname" size="40" required></td>
</tr>
<tr>
<td id="label" align="right">Password:</td>
<td><input type="password" name="c_password" size="40" required></td>
</tr>
<tr>
<td id="label" align="right">Image:</td>
<td><input type="file" name="c_image" required></td>
</tr>
<tr>
<td id="label" align="right">Country:</td>
<td>
<select name="c_country">
<option size="50">Select Country</option>
<?php countries(); ?>
</select>
</td>
</tr>
<tr>
<td id="label" align="right">City:</td>
<td><input type="text" name="c_city" size="40" required></td>
</tr>
<tr>
<td id="label" align="right">Contact:</td>
<td><input type="text" name="c_contact" size="40" required></td>
</tr>
<tr>
<td id="label" align="right">Address:</td>
<td><input type="text" name="c_address" size="40" required></td>
</tr>
<tr align="center">
<td colspan="3"><input type="submit" name="register" value="Create Account"></td>
</tr>
</tbody>
</table>
</form>
customer_login.php
<?php
session_start();
?>
<form method="post" action="">
<table width="500" align="center" bgcolor="skyblue">
<thead>
<tr align="center">
<th colspan="4"><h2>Login or Register to Buy!</h2></th>
</tr>
</thead>
<tbody>
<tr>
<td align="right"><b>Email:</b></td>
<td><input type="text" name="email" placeholder="Enter Email"></td>
</tr>
<tr>
<td align="right"><b>Password:</b></td>
<td><input type="password" name="pass" placeholder="Enter Password"></td>
</tr>
<tr align="center">
<td colspan="4">Forgot Password?</td>
</tr>
<tr align="center">
<td colspan="3"><input type="submit" name="login" value="Login"></td>
</tr>
</tbody>
</table>
<h2 style="float:right; padding:10px;">New? Register Here</h2>
</form>
<?php
if (isset($_POST['email']) && isset($_POST['pass'])) {
$email = $_POST['email'];
$pass = $_POST['pass'];
if (!empty($email) && !empty($pass)) {
$select_id = "SELECT * FROM customers WHERE customers_email = '$email' AND customers_pass = '$pass'";
$run_select_id = mysqli_query($conn, $select_id);
foreach ($run_select_id as $details) {
$usrname = $details['customers_username'];
$id = $details['customers_id'];
}
$num_run_select = mysqli_num_rows($run_select_id);
if ($num_run_select == NULL) {
echo '<script>alert("Invalid : Email/Password combination")</script>';
exit();
}
$c_ip_add = getIp();
$select_cart = "SELECT * FROM cart WHERE ip_add = '$c_ip_add'";
$run_select_cart = mysqli_query($conn, $select_cart);
$check_cart = mysqli_num_rows($run_select_cart);
if ($num_run_select > 0 AND $check_cart == 0) {
$_SESSION['customer_email'] = $email;
$_SESSION['username'] = $usrname;
$_SESSION['id'] = $id;
echo "<script>alert('You Have Logged In Succesfully')</script>";
echo "<script>window.open('customer/my_account.php','_self')</script>";
exit();
} else {
$_SESSION['customer_email'] = $email;
$_SESSION['username'] = $usrname;
$_SESSION['id'] = $id;
echo "<script>alert('You Have Logged In Succesfully')</script>";
echo "<script>window.open('checkout.php','_self')</script>";
}
} else {
echo 'Please enter valid email ID';
}
}
?>
my_account.php
<?php
session_start();
?>
<ul id="categories">
<?php
$location = 'customer_images/';
$usr_email = $_SESSION['customer_email'];
$user_name = #$_SESSION['username'];
$usr_id = $_SESSION['id'];
$select_image = "SELECT * FROM customers WHERE customers_id = '$usr_id'";
$run_image = mysqli_query($conn,$select_image);
foreach ($run_image as $select_all_data) {
$id = $select_all_data['customers_id'];
$name = $select_all_data['customers_name'];
$username = $select_all_data['customers_username'];
$email = $select_all_data['customers_email'];
$country = $select_all_data['customers_country'];
$city = $select_all_data['customers_city'];
$contact = $select_all_data['customers_contact'];
$address = $select_all_data['customers_address'];
$image = $select_all_data['customers_image'];
echo "<li style=''><img src='$location$image' height='150' width='174' style='text-align:center; border:3px solid black; padding:4px; border-radius: 109px;'></li>";
}
?>
<li>My Orders</li>
<li>Edit Account</li>
<li>Change Password</li>
<li>Delete Account</li>
<li>Logout</li>
</ul>
</div>
<div class="content_area2">
<?php cart(); ?>
<div id="my_account_menu">
<span>
<?php
if (isset($_SESSION['customer_email'])) {
echo "Welcome <i style='color:orange;'>" . $_SESSION['username']. ' </i>';
}
?>
<?php
if (!isset($_SESSION['customer_email'])) {
echo "<a href='../checkout.php' style='color:white;'>Login</a>";
} else {
echo "<a href='../logout.php' style='color:orange;'>Logout</a>";
}
?>
</span>
</div>
<?php getIp(); ?>
<div id="products_box">
<?php
if (!isset($_GET['my_orders']) && !isset($_GET['edit_account']) && !isset($_GET['change_pass']) && !isset($_GET['delete_account'])) {
?>
<div style="text-align:center;">
<table>
<tbody>
<tr>
<td id="label">Name : </td>
<td id="detail"><?php echo #$name; ?></td>
</tr>
<tr>
<td id="label">Username (Display Name) : </td>
<td id="detail"><?php echo #$username; ?></td>
</tr>
<tr>
<td id="label">Email : </td>
<td id="detail"><?php echo #$email; ?></td>
</tr>
<tr>
<td id="label">City : </td>
<td id="detail"><?php echo #$city; ?></td>
</tr>
<tr>
<td id="label">Contact : </td>
<td id="detail"><?php echo #$contact; ?></td>
</tr>
<tr>
<td id="label">Address : </td>
<td id="detail"><?php echo #$address; ?></td>
</tr>
</tbody>
</table>
</div>
<div style="padding:20px;"><b>You can see your orders by clicking this link</b></div>
<?php
}
?>
The problem is when I login it is working fine but when I register the user it gives the error undefined
$usr_id = $_SESSION['id'];
in my_account.php and all the information about the user is not displayed
I HAVE STARTED THE SESSION
I think you forget to call session_start before to do anything, even when there is no existing session.
<?php
session_start()
// your code...
You may want to look how it works with the basic example from the session_start function
As stated within the PHP session_start documentation:
To use cookie-based sessions, session_start() must be called before outputing anything to the browser.
So you may want to include this call after PHP opening tag <?php as I wrote above
You have to initiate the session by using session_start() on every page where you want to use the session. And this is missing on my_account.php
Ex:
<?php
session_start();
// your code
nowhere in your customer_register.php file do you actually set $_SESSION['id'].
in addition to this:
there are no form tags around your register form, so its hard to see how any data is getting into the script anyway.
your'e also silencing (#) errors. If this is a learning task, which from your comments I assume it is, thats a very counterproductive thing to do.
As you only set $_SESSION['id'] in the login handing script, its not going to be available across pages unless they go through that form. Its hard to tell from your code what your'e intended user journey is, but as it stands at the moment it looks like your'e expecting them to register, then be able to see the account page as a logged in user.
Just set $_SESSION['id'] in the register script, or dispense with it entirely and use the username (seeing as you validate it as unique anyway).
Also, your'e query in the my_account.php is looking for a column customer_id which (as far as I can see) you dont actually set in the insert statement.
This is the trouble with programming, it only does what you tell it to do.
when i click on delete the page get refresh but data is not deleted can you tell me what’s the problem.tell me also how should i edit the data using edit.help me out in this ... i tried my best.
this is my delete page
<?php
$database = "example";
$conn = mysql_connect("localhost","root","root");
$db_found = mysql_select_db($database, $conn);
$id=$_REQUEST['ID'];
// sending query
mysql_query("DELETE FROM my WHERE ID = '$id'")
or die(mysql_error());
header("Location: main.php");
?>
this is my main page
<!DOCTYPE html>
<html>
<head>
<title>Employee</title>
</head>
<body>
<center><b><font size=20>Employee Detail</font></b></center>
<?php
$database = "example";
$conn = mysql_connect("localhost","root","root");
$db_found = mysql_select_db($database, $conn);
$SQL = "SELECT * FROM my";
$result = mysql_query($SQL);
print "<table border='1'>";
print "<tr>";
print "<th>ID</th>";
print "<th>First name</th>";
print "<th>Last name</th>";
print "<th>Gender</th>";
print "<th>Address</th>";
print "<th>Contact_no</th>";
print "<th>Picture</th>";
print "<th>User_name</th>";
print "<th>Password</th>";
print "<th>Email_id</th>";
while ( $db_field = mysql_fetch_assoc($result) )
{
print "<tr>";
print "<td>".$db_field['ID']."</td>";
print "<td>".$db_field['F_name']."</td>";
print "<td>".$db_field['L_name']."</td>";
print "<td>".$db_field['Gender']."</td>";
print "<td>".$db_field['Address']."</td>";
print "<td>".$db_field['Contact_no']."</td>";
print "<td>".$db_field['Picture']."</td>";
print "<td>".$db_field['U_name']."</td>";
print "<td>".$db_field['Password']."</td>";
print "<td>".$db_field['Email_id']."</td>";
echo"<td> <a href ='edit.php?ID=$id'>Edit</a>";
echo"<td> <a href ='delete.php?ID=$id'><center>Delete</center></a>";
print "</tr>";
}
print "</table>";
mysql_close($conn);
?>
<form>
<a href="test1.php">
<input type="button" value="Add">
</a>
</form>
</body>
</html>
this is my add page
<?php
?>
<html>
<head>
<title>Sign up Form</title>
<script type="text/javascript">
<!--
function validation()
{
if (document.login.fname.value==null || document.login.fname.value=="")
{
alert("First name must be filled out");
document.login.fname.focus();
return false;
}
if((document.login.fname.value.length<3))
{
alert("First name is too short");
document.login.psw.focus();
return false;
}
if (document.login.lname.value==null || document.login.lname.value=="")
{
alert("Last name must be filled out");
document.login.lname.focus();
return false;
}
if((document.login.lname.value.length<3))
{
alert("Last name is too short");
document.login.psw.focus();
return false;
}
if( document.login.select.selectedIndex==0)
{
alert( "Gender must be filled out" );
document.login.select.focus();
return false;
}
if (document.login.address.value==null || document.login.address.value=="")
{
alert("Address must be filled out");
document.login.address.focus();
return false;
}
if((document.login.address.value.length < 20))
{
alert(" Your address must be 20 characters");
document.login.address.select();
return false;
}
if (document.login.contact_no.value==null || document.login.contact_no.value=="")
{
alert("Contact number must be filled out");
document.login.contact_no.focus();
return false;
}
if(isNaN(document.login.contact_no.value))
{
alert("You use charecter in contact number");
document.login.contact_no.focus();
return false;
}
if((document.login.contact_no.value.length < 1) || (document.login.contact_no.value.length > 10))
{
alert("you enter more than 10 digit in contact");
document.login.contact_no.focus();
return false;
}
if (document.login.picture.value==null || document.login.picture.value=="")
{
alert("You must select an Image or Images");
document.login.picture.focus();
return false;
}
if (document.login.uname.value==null || document.login.uname.value=="")
{
alert("Login name must be filled out");
document.login.uname.focus();
return false;
}
if((document.login.psw.value.length<4))
{
alert("Password is too short");
document.login.psw.focus();
return false;
}
if (document.login.psw.value==null || document.login.uname.value=="")
{
alert("Password must be filled out");
document.login.psw.focus();
return false;
}
var emailfilter=/^\w+[\+\.\w-]*#([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
var b=emailfilter.test(document.login.e_id.value);
if(b==false)
{
alert("Please Enter a valid Mail ID");
document.login.e_id.focus();
return false;
}
}
//-->
</script>
</head>
<body>
<form name="login" action="insert.php" onsubmit="return(validation())" method="post" enctype= multipart/form-data>
<table>
<tr>
<td>First Name:</td>
<td><input type="text" name="fname" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lname" /></td>
</tr>
<tr>
<td>Gender:</td>
<td><select name="select">
<option value="-1" selected>[Select option]</option>
<option value="male">Male</option>
<option value="female">Female</option>
</td>
</tr>
<tr>
<td>Address:</td>
<td><textarea name="address" col="60" row="10"></textarea></td>
</tr>
<tr>
<td>Contact no:</td>
<td><input type="number" name="contact_no"></td>
</tr>
<tr>
<td>Picture:</td>
<td><input type="file" name="picture"> </td>
</tr>
<tr>
<td>User name:</td>
<td><input type="text" name="uname"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="psw"></td>
</tr>
<tr>
<td>Email id:</td>
<td><input type="email" name="e_id"></td>
</tr>
<tr>
<td><input type="reset" value="Reset"></td>
<td><input type="submit" name="submit"></td>
</tr>
</table>
</form>
</body>
</html>
this is my edit page
<?php
$database = "example";
$conn = mysql_connect("localhost","root","root");
$db_found = mysql_select_db($database, $conn);
$id =$_REQUEST['ID'];
$result = mysql_query("SELECT * FROM my WHERE ID = '$id'");
$db_field = mysql_fetch_array($result);
if (!$result)
{
die("Error: Data not found..");
}
$F_name=$db_field['F_name'];
$L_name=$db_field['L_name'];
$Gender=$db_field['Gender'];
$Address=$db_field['Address'];
$Contact_no=$db_field['Contact_no'];
$Picture=$db_field['Picture'];
$U_name=$db_field['U_name'];
$Password=$db_field['Password'];
$Email_id=$db_field['Email_id'];
if(isset($_POST['save']))
{
$fname_save = $_POST['fname'];
$lname_save = $_POST['lname'];
$gender_save = $_POST['select'];
$address_save = $_POST['address'];
$contactno_save = $_POST['contact_no'];
$picture_save = $_POST['picture'];
$uname_save = $_POST['u_name'];
$password_save = $_POST['psw'];
$emailid_save = $_POST['e_id'];
mysql_query("UPDATE my SET F_name='$fname_save', L_name='$lname_save', Gender='$gender_save', Address='$address_save', Contact_no='$contactno_save', Picture='$picture_save', U_name='$uname_save', Password='$password_save', Email_id='$emailid_save' WHERE ID = '$id'")
or die(mysql_error());
echo "Saved!";
header("Location: main.php");
}
mysql_close($conn);
?>
</head>
<body>
<form method="post">
<table>
<tr>
<td>First Name:</td>
<td><input type="text" name="fname" value="<?php echo $F_name ?>" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lname" value="<?php echo $L_name ?>" /></td>
</tr>
<tr>
<td>Gender:</td>
<td><select name="select" value="<?php echo $Gender ?>">
<option value="-1" selected>[Select option]</option>
<option value="male">Male</option>
<option value="female">Female</option>
</td>
</tr>
<tr>
<td>Address:</td>
<td><textarea name="address" col="60" row="10" value="<?php echo $Address ?>"></textarea></td>
</tr>
<tr>
<td>Contact no:</td>
<td><input type="number" name="contact_no" value="<?php echo $Contact_no ?>"></td>
</tr>
<tr>
<td>Picture:</td>
<td><input type="file" name="picture" value="<?php echo $Picture ?>"> </td>
</tr>
<tr>
<td>User name:</td>
<td><input type="text" name="uname" value="<?php echo $U_name ?>"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="psw" value="<?php echo $Password ?>"></td>
</tr>
<tr>
<td>Email id:</td>
<td><input type="email" name="e_id" value="<?php echo $Email_id ?>"></td>
</tr>
<tr>
<td><input type="submit" name="save" value="save"></td>
</tr>
</table>
</form>
</body>
</html>
this is my database
<?php
// Create connection
$conn = mysql_connect('localhost', 'root', 'root');
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected Successfully';
$sql = "CREATE TABLE my(
ID INT NOT NULL AUTO_INCREMENT,
F_name VARCHAR(20) NOT NULL,
L_name VARCHAR(20) NOT NULL,
Gender VARCHAR(10) NOT NULL,
Address VARCHAR(80) NOT NULL,
Contact_no INT NOT NULL,
Picture BLOB NOT NULL,
U_name VARCHAR(20) NOT NULL,
Password VARCHAR(25) NOT NULL,
Email_id VARCHAR(30) NOT NULL,
primary key ( ID ))";
mysql_select_db('example');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not create table: ' . mysql_error());
}
echo "Table my created successfully\n";
mysql_close($conn);
?>
echo ("<td>Delete</td></tr>")
Add:
$id = $db_field['ID'];
to the beginning of the while loop on the main page. You're using this variable in the URLs in your echo statements, but never setting it.