At the backend of my opencart e-commerce package, there is the possibility to insert vouchers for customers. However, there is standard no possibility to set a start and end date (1 year later) for the voucher. Therefore I have adapted the voucher.tpl template to include this possibility. I have implemented this completely identical as for the coupon.tpl where there is the possibility to enter a start date and end date.
The input field for the start date and end date is using the datetimepicker script. The datepicker is showing up correctly when I click the calendar button (see image 1) and the date is showing up.
The dates are used in a form, but unfortunately the data seem not be transferred with the form when the save button is clicked. I see no difference with the coupon.tpl page where everything is working properly. I spent already many hours in founding the error but did not succeed yet. Could somebody help me on my way?
Thanks,
SabKo
The voucher.tpl has the following code:
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-voucher" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
<i class="fa fa-reply"></i>
</div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><?php echo $breadcrumb['text']; ?></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_form; ?></h3>
</div>
<div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-voucher" class="form-horizontal">
<div class="tab-content">
<div class="tab-pane active" id="tab-general">
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-code"><span data-toggle="tooltip" title="<?php echo $help_code; ?>"><?php echo $entry_code; ?></span>
</label>
<div class="col-sm-10">
<input type="text" name="code" value="<?php echo $code; ?>" placeholder="<?php echo $entry_code; ?>" id="input-code" class="form-control" />
<?php if ($error_code) { ?>
<div class="text-danger"><?php echo $error_code; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-from-name"><?php echo $entry_from_name; ?>
</label>
<div class="col-sm-10">
<input type="text" name="from_name" value="<?php echo $from_name; ?>" placeholder="<?php echo $entry_from_name; ?>" id="input-from-name" class="form-control" />
<?php if ($error_from_name) { ?>
<div class="text-danger"><?php echo $error_from_name; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-to-name"><?php echo $entry_to_name; ?></label>
<div class="col-sm-10">
<input type="text" name="to_name" value="<?php echo $to_name; ?>" placeholder="<?php echo $entry_to_name; ?>" id="input-to-name" class="form-control" />
<?php if ($error_to_name) { ?>
<div class="text-danger"><?php echo $error_to_name; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-amount"><?php echo $entry_amount; ?></label>
<div class="col-sm-10">
<input type="text" name="amount" value="<?php echo $amount; ?>" placeholder="<?php echo $entry_amount; ?>" id="input-amount" class="form-control" />
<?php if ($error_amount) { ?>
<div class="text-danger"><?php echo $error_amount; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-date-start"><?php echo $entry_date_start; ?></label>
<div class="col-sm-3">
<div class="input-group date">
<input type="text" name="date_start" value="<?php echo $date_start; ?>" placeholder="<?php echo $entry_date_start; ?>" data-date-format="YYYY-MM-DD" id="input-date-start" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-date-end"><?php echo $entry_date_end; ?></label>
<div class="col-sm-3">
<div class="input-group date">
<input type="text" name="date_end" value="<?php echo $date_end; ?>" placeholder="<?php echo $entry_date_end; ?>" data-date-format="YYYY-MM-DD" id="input-date-end" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
</div>
<?php if ($voucher_id) { ?>
<div class="tab-pane" id="tab-history">
<div id="history"></div>
</div>
<?php } ?>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript"><!--
$('.date').datetimepicker({
pickTime: false
});
//--></script>
</div>
The controller page has the following code, so should be able to read the input of the dates:
if (isset($this->request->post['date_start'])) {
$data['date_start'] = $this->request->post['date_start'];
} elseif (!empty($voucher_info)) {
$data['date_start'] = ($voucher_info['date_start'] != '0000-00-00' ? $voucher_info['date_start'] : '');
} else {
$data['date_start'] = date('Y-m-d', time());
}
if (isset($this->request->post['date_end'])) {
$data['date_end'] = $this->request->post['date_end'];
} elseif (!empty($voucher_info)) {
$data['date_end'] = ($voucher_info['date_end'] != '0000-00-00' ? $voucher_info['date_end'] : '');
} else {
$data['date_end'] = date('Y-m-d', strtotime('+1 month'));
}
You're initialize your datetime picker on div with class .date but you have to initialize it on inputs with their classes or ids.
replace this code:
<script type="text/javascript"><!--
$('.date').datetimepicker({
pickTime: false
});
//--></script>
with this one:
<script type="text/javascript"><!--
$('#input-date-start').datetimepicker({
pickTime: false
});
$('#input-date-end').datetimepicker({
pickTime: false
});
//--></script>
Related
I have a shortcode where I display some information from a form that was submited on another page. The question is how do I 'redirect' to the same form passing the id of the item that I press the button edit? Can someone give some advice
Here is the code for the shortcode:
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'property';
$properties = $wpdb->get_results("SELECT * FROM $table_name");
?>
<?php foreach ($properties as $property) : ?>
<div class="col-sm-4 my-4 card-selector">
<div class="card bg-light text-dark card-height">
<?php if ($property->sale_rent == 0) : ?>
<div class="corner-ribbon top-left sticky red shadow">Sale</div>
<?php elseif ($property->sale_rent == 1): ?>
<div class="corner-ribbon top-left sticky red shadow">Rent</div>
<?php endif; ?>
<img class="img-responsive card-img-top" src="" alt="">
<div class="card-body">
<h2 class="card-title"><?php echo $property->country ?></h2>
<h3 class="card-title"><?php echo $property->price ?> £</h3>
<h5 class="card-title"><?php echo $property->county, $property->town ?></h5>
<h6 class="card-title"><?php echo $property->displayable_address ?></h6>
<i class="fas fa-bed"><?php echo $property->nr_of_bedrooms ?></i> <i
class="fas fa-bath"><?php echo $property->nr_of_bathrooms ?></i>
<p id="description" class="description card-text"><?php echo $property->property_description ?></p>
<?php if ($property->custom) : ?>
Edit
<a class="deleterow card-link"
href="">Delete</a>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
and here is a part of my form that I submited:
url: http://test.localhost/wordpress/add-property/
<h1>Add Property</h1>
<hr>
<div id="property-status"></div>
<form id="add-form" method="post" action="#" enctype="multipart/form-data">
<div class="row">
<div class="col-md-8">
<form name="contact-form" action="" method="post" id="contact-form">
<div class="form-group ">
<label>County*</label>
<input type="text" id="county" class="form-control" name="county" value="" required/>
</div>
<div class="form-group">
<label>Country*</label>
<input type="text" id="country" class="form-control" name="country" value="" required/>
</div>
<div class="form-group">
<label>Town</label>
<input type="text" id="town" class="form-control" name="town" required/>
</div>
<div class="form-group">
<label>Postcode</label>
<input type="number" id="postcode" class="form-control" name="postcode" value="" required/>
</div>
<div class="form-group">
<label>Description</label>
<textarea name="property_description" id="property_description" class="form-control"></textarea>
</div>
If you want to make your add and edit page same, you will need to add some more code in the add page.
First of all, make a change something like this
Edit
<a class="deleterow card-link" href="">Delete</a>
I am guessing $property->id is the primary key.
This way edit link will navigate to the same page when clicked.
Then, you will need to get the id in your add page at the top and fetch the data from database.
global $wpdb;
$id = $_GET['id'];
$table_name = $wpdb->prefix . 'property';
$properties = $wpdb->get_results("SELECT * FROM $table_name WHERE property_id=$id");
Hope this help!
You need to do like this
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'property';
$properties = $wpdb->get_results("SELECT * FROM $table_name");
?>
<?php foreach ($properties as $property) : ?>
<div class="col-sm-4 my-4 card-selector">
<div class="card bg-light text-dark card-height">
<?php if ($property->sale_rent == 0) : ?>
<div class="corner-ribbon top-left sticky red shadow">Sale</div>
<?php elseif ($property->sale_rent == 1): ?>
<div class="corner-ribbon top-left sticky red shadow">Rent</div>
<?php endif; ?>
<img class="img-responsive card-img-top" src="" alt="">
<div class="card-body">
<h2 class="card-title"><?php echo $property->country ?></h2>
<h3 class="card-title"><?php echo $property->price ?> £</h3>
<h5 class="card-title"><?php echo $property->county, $property->town ?></h5>
<h6 class="card-title"><?php echo $property->displayable_address ?></h6>
<i class="fas fa-bed"><?php echo $property->nr_of_bedrooms ?></i> <i
class="fas fa-bath"><?php echo $property->nr_of_bathrooms ?></i>
<p id="description" class="description card-text"><?php echo $property->property_description ?></p>
<?php if ($property->custom) : ?>
Edit
<a class="deleterow card-link"
href="">Delete</a>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'property';
if(isset($_GET['id'])){
$properties = $wpdb->get_results("SELECT * FROM $table_name where id= $_GET['id']");
print_r($properties);
}
?>
<h1>Add Property</h1>
<hr>
<div id="property-status"></div>
<form id="add-form" method="post" action="#" enctype="multipart/form-data">
<div class="row">
<div class="col-md-8">
<form name="contact-form" action="" method="post" id="contact-form">
<div class="form-group ">
<label>County*</label>
<input type="text" id="county" class="form-control" name="county" value="" required/>
</div>
<div class="form-group">
<label>Country*</label>
<input type="text" id="country" class="form-control" name="country" value="" required/>
</div>
<div class="form-group">
<label>Town</label>
<input type="text" id="town" class="form-control" name="town" required/>
</div>
<div class="form-group">
<label>Postcode</label>
<input type="number" id="postcode" class="form-control" name="postcode" value="" required/>
</div>
<div class="form-group">
<label>Description</label>
<textarea name="property_description" id="property_description" class="form-control"></textarea>
</div>
</form>
</div>
</div>
I want to make a profile page edit for my project. I try something to profile page. But I gave an error.
How can I do profile page ? The error is:
An uncaught Exception was encountered
Type: ArgumentCountError
Message: Too few arguments to function CProfile_edit::update(), 0 passed in C:\xampp\htdocs\erp\system\core\CodeIgniter.php on line 532 and exactly 1 expected
Filename: C:\xampp\htdocs\erp\application\controllers\CProfile_edit.php
Line Number: 14
Backtrace:
File: C:\xampp\htdocs\erp\index.php
Line: 315
Function: require_once
I gave it always. I use session data for take data from customer table. But I can not profile edit. I take this error.
This is my view:
<section class="panel">
<div class="bio-graph-heading">
<?php echo $this->lang->line('profile_edit_top_text'); ?>
</div>
<div class="panel-body bio-graph-info">
<h1> <?php echo $this->lang->line('profile_edit_text_informations'); ?></h1>
<form class="form-horizontal" role="form" method="post" action="<?php echo base_url("CProfile_edit/update/$user->cosId"); ?>">
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_username'); ?></label>
<div class="col-lg-6">
<input type="text" class="form-control" id="f-name" name="cosUserName" placeholder="<?php echo $this->session->userdata('people_username'); ?>" />
</div>
</div>
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_email'); ?></label>
<div class="col-lg-6">
<input type="email" class="form-control" id="email" name="cosEmail" placeholder="<?php echo $this->session->userdata('people_email'); ?>" />
</div>
</div>
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_firstname'); ?></label>
<div class="col-lg-6">
<input type="text" class="form-control" id="f-name" name="cosName" placeholder="<?php echo $this->session->userdata('people_username'); ?>" />
</div>
</div>
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_lastname'); ?></label>
<div class="col-lg-6">
<input type="text" class="form-control" id="l-name" name="cosSurname" placeholder="<?php echo $this->session->userdata('people_surname'); ?>" />
</div>
</div>
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_phone'); ?></label>
<div class="col-lg-6">
<input type="text" class="form-control" id="f-name" name="cosPho" placeholder="<?php echo $this->session->userdata('people_phone'); ?>" />
</div>
</div>
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_mobile'); ?></label>
<div class="col-lg-6">
<input type="text" class="form-control" id="f-name" name="cosGsm" placeholder="<?php echo $this->session->userdata('people_mobile'); ?>" />
</div>
</div>
<!-- Basic select -->
<div class="form-group">
<label class="control-label col-lg-3"><?php echo $this->lang->line('cprofile_profile_lang'); ?> <span class="text-danger">*</span></label>
<div class="col-lg-9">
<select name="cosLang" class="form-control">
<option value="<?php echo $this->session->userdata('people_lang'); ?>"><?php echo $this->session->userdata('people_lang'); ?></option>
<option value="en">English</option>
<option value="ar">Arabic</option>
</select>
</div>
</div>
<!-- /basic select -->
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-success">Save</button>
<button type="button" class="btn btn-default">Cancel</button>
</div>
</div>
</form>
</div>
</section>
There is my controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class CProfile_edit extends CI_Controller {
public function index()
{
//redirect(base_url('calendar'));
$this->lang->load('content', $this->session->userdata('people_lang'));
$this->load->view('cprofile_edit');
}
public function update($cusId = 1)
{
if (! empty($cusId))
{
$data = array (
"cosUserName" => $this->input->post("cosUserName"),
"cosEmail" => $this->input->post("cosEmail"),
"cosName" => $this->input->post("cosName"),
"cosSurname" => strtoupper($this->input->post("cosSurname")),
"cosPho" => $this->input->post("cosPho"),
"cosGsm" => $this->input->post("cosGsm"),
"cosLang" => $this->input->post("cosLang"),
"cosEditDate" => date('Y-m-d H:i:s')
);
$update = $this->db->where("cusId", $cusId)->update("customer", $data);
if($update)
{
redirect(base_url("cprofile"));
}
else
{
echo "Hata!";
}
}
}
}
?>
Line Number: 14 error: public function update($cusId) {
Edit Your View and use this code.
<section class="panel">
<div class="bio-graph-heading">
<?php echo $this->lang->line('profile_edit_top_text'); ?>
</div>
<div class="panel-body bio-graph-info">
<h1> <?php echo $this->lang->line('profile_edit_text_informations'); ?></h1>
<form class="form-horizontal" role="form" method="post" action="<?php echo base_url("CProfile_edit/update/".$this->session->userdata('people_id')); ?>">
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_username'); ?></label>
<div class="col-lg-6">
<input type="text" class="form-control" id="f-name" name="cosUserName" placeholder="<?php echo $this->session->userdata('people_username'); ?>" />
</div>
</div>
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_email'); ?></label>
<div class="col-lg-6">
<input type="email" class="form-control" id="email" name="cosEmail" placeholder="<?php echo $this->session->userdata('people_email'); ?>" />
</div>
</div>
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_firstname'); ?></label>
<div class="col-lg-6">
<input type="text" class="form-control" id="f-name" name="cosName" placeholder="<?php echo $this->session->userdata('people_username'); ?>" />
</div>
</div>
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_lastname'); ?></label>
<div class="col-lg-6">
<input type="text" class="form-control" id="l-name" name="cosSurname" placeholder="<?php echo $this->session->userdata('people_surname'); ?>" />
</div>
</div>
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_phone'); ?></label>
<div class="col-lg-6">
<input type="text" class="form-control" id="f-name" name="cosPho" placeholder="<?php echo $this->session->userdata('people_phone'); ?>" />
</div>
</div>
<!-- Form -->
<div class="form-group">
<label class="col-lg-2 control-label"><?php echo $this->lang->line('cprofile_profile_mobile'); ?></label>
<div class="col-lg-6">
<input type="text" class="form-control" id="f-name" name="cosGsm" placeholder="<?php echo $this->session->userdata('people_mobile'); ?>" />
</div>
</div>
<!-- Basic select -->
<div class="form-group">
<label class="control-label col-lg-3"><?php echo $this->lang->line('cprofile_profile_lang'); ?> <span class="text-danger">*</span></label>
<div class="col-lg-9">
<select name="cosLang" class="form-control">
<option value="<?php echo $this->session->userdata('people_lang'); ?>"><?php echo $this->session->userdata('people_lang'); ?></option>
<option value="en">English</option>
<option value="ar">Arabic</option>
</select>
</div>
</div>
<!-- /basic select -->
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-success">Save</button>
<button type="button" class="btn btn-default">Cancel</button>
</div>
</div>
</form>
</div>
</section>
With a WordPress PHP template - I what doing an if statement to check if user is logged in, if he is then I want to show an email form and if he's not I want to ask users to login.
<?php if ( is_user_logged_in() ) {
<div role="tabpanel" class="tab-panel active" id="nomessage">
<div class="row">
<div class="col-lg-12">
<h4>You have to be logged in to send a message</h4>
</div>
</div>
</div>
} else {
<div class="tab-content">
<?php if($classieraToAuthor == 1){?>
<div role="tabpanel" class="tab-pane active" id="message">
<!--ShownMessage-->
<?php if(isset($_POST['submit']) && $_POST['submit'] == 'send_message'){?>
<div class="row">
<div class="col-lg-12">
<?php if($hasError == true){ ?>
<div class="alert alert-warning">
<?php echo $errorMessage; ?>
</div>
<?php } ?>
<?php if($emailSent == true){ ?>
<div class="alert alert-success">
<?php echo $classieraContactThankyou; ?>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
<!--ShownMessage-->
<form method="post" class="form-horizontal" data-toggle="validator" name="contactForm" action="<?php the_permalink(); ?>">
<div class="form-group">
<label class="col-sm-3 control-label" for="name"><?php esc_html_e('Name', 'classiera') ?> :</label>
<div class="col-sm-9">
<input id="name" data-minlength="5" type="text" class="form-control form-control-xs" name="contactName" placeholder="<?php esc_html_e('Type your name', 'classiera') ?>" required>
</div>
</div><!--name-->
<div class="form-group">
<label class="col-sm-3 control-label" for="email"><?php esc_html_e('Email', 'classiera') ?> :</label>
<div class="col-sm-9">
<input id="email" type="email" class="form-control form-control-xs" name="email" placeholder="<?php esc_html_e('Type your email', 'classiera') ?>" required>
</div>
</div><!--Email-->
<div class="form-group">
<label class="col-sm-3 control-label" for="subject"><?php esc_html_e('Subject', 'classiera') ?> :</label>
<div class="col-sm-9">
<input id="subject" type="text" class="form-control form-control-xs" name="subject" placeholder="<?php esc_html_e('Type your subject', 'classiera') ?>" required>
</div>
</div><!--Subject-->
<div class="form-group">
<label class="col-sm-3 control-label" for="msg"><?php esc_html_e('Message', 'classiera') ?> :</label>
<div class="col-sm-9">
<textarea id="msg" name="comments" class="form-control" placeholder="<?php esc_html_e('Type Message', 'classiera') ?>" required></textarea>
</div>
</div><!--Message-->
<?php
$classieraFirstNumber = rand(1,9);
$classieraLastNumber = rand(1,9);
$classieraNumberAnswer = $classieraFirstNumber + $classieraLastNumber;
?>
<div class="form-group">
<div class="col-sm-9">
<p>
<?php esc_html_e("Please input the result of ", "classiera"); ?>
<?php echo $classieraFirstNumber; ?> + <?php echo $classieraLastNumber;?> =
</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="humanTest"><?php esc_html_e('Answer', 'classiera') ?> :</label>
<div class="col-sm-9">
<input id="humanTest" type="text" class="form-control form-control-xs" name="humanTest" placeholder="<?php esc_html_e('Your answer', 'classiera') ?>" required>
<input type="hidden" name="humanAnswer" id="humanAnswer" value="<?php echo $classieraNumberAnswer; ?>" />
<input type="hidden" name="classiera_post_title" id="classiera_post_title" value="<?php the_title(); ?>" />
<input type="hidden" name="classiera_post_url" id="classiera_post_url" value="<?php the_permalink(); ?>" />
</div>
</div><!--answer-->
<input type="hidden" name="submit" value="send_message" />
<button class="btn btn-primary btn-block btn-sm sharp btn-style-one" name="send_message" value="send_message" type="submit"><?php esc_html_e( 'Send Message', 'classiera' ); ?></button>
</form>
</div>
};
?>
First, I have added an if statement to check whether the user is logged in or not, if he is the first element is shown where is tells the user it has to be logged in to send a message. Then, if he is logged in a message form is shown instead.
Cannot get it to work, would appreciate all help a lot! Thanks in advance!
You couldn't mix PHP and HTML like this. You're missing to close PHP tag ?> before to write HTML.
EDIT As pointed by #mmm, your test is the inverse of what you want. You have to negate your test using the character !.
Try this :
<?php if ( ! is_user_logged_in() ) : ?>
<div role="tabpanel" class="tab-panel active" id="nomessage">
<div class="row">
<div class="col-lg-12">
<h4>You have to be logged in to send a message</h4>
</div>
</div>
</div>
<?php else: ?>
<!-- other HTML -->
<?php endif; ?>
Or :
<?php if ( is_user_logged_in() ) { ?>
<div role="tabpanel" class="tab-panel active" id="nomessage">
<div class="row">
<div class="col-lg-12">
<h4>You have to be logged in to send a message</h4>
</div>
</div>
</div>
<?php } else { ?>
<!-- other HTML -->
<?php } ?>
EDIT.PHP
<?php
//error_reporting(0);
include("DB.php");
if(isset($_GET['id']))
{
$id=$_GET['id'];
$sql="SELECT * FROM hrmsinfo WHERE emp_id='$id'";
$sqll=mysqli_query($link,$sql);
while($profile=mysqli_fetch_array($link,$sqll))
{
$username=$profile['emp_name'];
$usermail=$profile['emp_email'];
$userdob=$profile['emp_dob'];
$usermobile=$profile['emp_phno'];
$useraddress=$profile['emp_address'];
$userproof=$profile['emp_proof'];
?>
<div class="display">
<form action="UPDATE.php" method="post" name="insertform">
<p>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Name:</div>
<div class="col-xs-4"><input type="text" class="form-control" name="ename" placeholder="Enter Name" value="<?php echo $username; ?>" id="inputid"></div>
</div>
</div>
</p>
<p>
<div class="form-group">
<div class="row">
<div class="col-xs-3">EMAIL:</div>
<div class="col-xs-4"><input type="text" class="form-control" name="eemail" placeholder="Enter Email" value="<?php echo $usermail; ?>" id="inputid"></div>
</div>
</div>
</p>
<p>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Date Of Birth:</div>
<div class="col-xs-5">
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="date" class="form-control pull-right" name="edateofbirth" value="<?php echo $userdob; ?>" id="inputid">
</div>
</div>
</div>
</div>
</p>
<p>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Mobile Number:</div>
<div class="col-xs-5">
<input type="text" class="form-control" placeholder="Enter Mobile" name="emobile" value="<?php echo $usermobile; ?>" id="inputid">
</div>
</div>
</div>
</p>
<p>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Address:</div>
<div class="col-xs-5">
<textarea class="form-control" rows="3" placeholder="Enter Address" name="epresentaddress" value="<?php echo $useraddress; ?>" id="inputid"></textarea>
</div>
</div>
</div>
</p>
<p>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Proof:</div>
<div class="col-xs-5">
<input type="text" class="form-control" placeholder="Enter Proof" name="edrivinglicense" value="<?php echo $userproof; ?>" id="inputid">
</div>
</div>
</div>
</p>
<p>
<div class="form-group">
<div class="row">
<div class="col-xs-3"></div>
<div class="col-xs-5">
<input type="submit" name="eupdate" value="Update" id="inputid1" />
</div>
</div>
</div>
</p>
</form>
</div>
<?php } } ?>
UPDATE.PHP
<?php
include('DB.php');
if(isset($_GET['id']))
{
$id=$_GET['id'];
if(isset($_POST['update']))
{
$name=mysqli_real_escape_string($link,$_POST["ename"]);
$email=mysqli_real_escape_string($link,$_POST["eemail"]);
$enpassword=mysqli_real_escape_string($link,$_POST["epassword"]);
$dateofbirth=mysqli_real_escape_string($link,$_POST["edateofbirth"]);
$mobile=mysqli_real_escape_string($link,$_POST["emobile"]);
$presentaddress=mysqli_real_escape_string($link,$_POST["eaddress"]);
$drivinglicense=mysqli_real_escape_string($link,$_POST["edrivinglicense"]);
$updated=mysqli_query("UPDATE `hrmsinfo` SET `emp_name`=[$name],`emp_email`=[$email],`emp_password`=[$enpassword],`emp_dob`=[$dateofbirth],`emp_phno`=[$mobile],`emp_address`=[$presentaddress],`emp_proof`=[$drivinglicense] WHERE emp_id='$id'");
if($result = mysqli_query($link, $updated))
{
$msg="Successfully Updated!!";
header('Location:VIEW.php');
}
else
{
$msg="Unsucessfull!!";
}
}
} //update ends here
?>
MY code keeps popping me error like this:-
mysqli_fetch_array() expects parameter 1 to be mysqli_result
what is wrong with this where am i wrong when i remove id it works can i get the id as parameter call for edit and update help me with this
this is because of the line:-
while($profile=mysqli_fetch_array($link,$sqll)){
Here you need to pass the Query-result-set object only.
So change it to:-
$sqll=mysqli_query($link,$sql);
while($profile=mysqli_fetch_array($sqll)){
I am karthik, in my project i have one problem, i am getting error undefine index: template_id. I have searched more in net but i can't rectify this problem i have attached my code below, please guide me
if($fetquery["template_id"] == 5){
$query = mysql_query("SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."");
$fetquery = mysql_fetch_array($query);
?>
<!-- Template5-->
<input type="hidden" name="template5" value="template5">
<div class="fillContent" id="subscreen5">
<div class="mainTitle">
<h3>Fill Content - Template E</h3>
</div>
<input type="hidden" name="template5id" value="<?php echo $fetquery['temp5_id']; ?>">
<div class="current-title">
<label>Main Title</label> <input type="text" class="fillTitleText" name="etemp5title"placeholder="Lorem Ipsum" value="<?php echo $fetquery['title']; ?>"><!-- Edit -->
</div>
<div class="section2">
<div class="contentSecTitle">
<h3>Banner Image</h3>
</div>
<div class="subSec">
<div class="subSec1">
<div class="contentSec2Left">
<input type="text" id="template5banner" value="<?php echo $fetquery['bannerimage']; ?>" class="upLoadText">
<div class="fileUpload btn btn-primary">
<span class="uploadImage"></span>
<input id="temp5_bannerimg" onchange="addtemplate5banner(this)" name="etemplate5bannerimg" type="file" class="upload" value="Browse">
</div>
</div>
<div class="contentSecRight">
<input type="hidden" name="gettopImage" value="<?php echo $fetquery['bannerimage']; ?>">
<p class="imageView3"><img src="<?php echo $fetquery['bannerimage']; ?>" style="width:82px; height:82px;" id="changetemp5banner"><br><br>Current Image</p>
<!-- <p class="imageView4">filename.jpg</p>
<div class="deLete">
</div>
-->
</div>
</div>
</div>
</div>
<div class="fillSec">
<div class="contentSecTitle">
<h3>Content</h3>
</div>
<div class="current-textarea">
<div class="text-area">
<label>Description</label> <textarea rows="4" name="etemp5desc" ><?php echo $fetquery['description']; ?></textarea>
</div>
</div>
</div>
</div>
<?php
}
if($fetquery["template_id"] == 6){
//echo "SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."";
$query = mysql_query("SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."");
$fetquery = mysql_fetch_array($query);
?>
<!-- Template6-->
<input type="hidden" name="template6" value="template6">
<div class="fillContent" id="subscreen6">
<div class="mainTitle">
<h3>Fill Content - Template F</h3>
</div>
<input type="hidden" name="template6id" value="<?php echo $fetquery['temp6_id']; ?>">
<div class="current-title">
<label>Main Title</label> <input value="<?php echo $fetquery['title']; ?>" type="text" class="fillTitleText" name="etemplate6title" placeholder="Lorem Ipsum"> <!--Edit -->
</div>
<div class="section2">
<div class="contentSecTitle">
<h3>Banner Image</h3>
</div>
<div class="subSec">
<div class="subSec1">
<div class="contentSec2Left">
<input type="text" id="template6banner" value="<?php echo $fetquery['bannerimage']; ?>" class="upLoadText">
<div class="fileUpload btn btn-primary">
<span class="uploadImage"></span>
<input id="temp6_bannerimg" onchange="addtemplate6banner(this)" name="template6bannerimg" type="file" class="upload" value="Browse">
</div>
</div>
<div class="contentSecRight">
<input type="hidden" name="gettopImage" value="<?php echo $fetquery['bannerimage']; ?>">
<p class="imageView3"><img src="<?php echo $fetquery['bannerimage']; ?>" style="width:82px; height:82px;" id="changetemp6banner"><br><br>Current Image</p>
<!-- <p class="imageView4">filename.jpg</p>
<div class="deLete">
</div> -->
</div>
</div>
</div>
</div>
<div class="fillSec">
<div class="contentSecTitle">
<h3>Content</h3>
</div>
<div class="current-textarea">
<div class="text-area">
<label>Desription</label> <textarea rows="4" name="temp6desc"><?php echo $fetquery['description']; ?></textarea>
</div>
</div>
</div>
</div>
<?php } ?>
This code was in ajax page
Try to add a check before using it. And also check if it is defined or not. -
if (!empty($fetquery["template_id"]) && $fetquery["template_id"] == 5) { ...