When I add an additional field to my query, it fails. I have checked the spelling 20 or more times....I do not know what is wrong.. Please help!!
Working code BELOW
if(isset($_POST['UPDATE_RAW'])) {
extract($_POST);
$sql=mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd' WHERE ID='$id'");
if($sql) {
echo "<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else {
echo "<script>alert('Some ERRORS');</script>";
}
}
NOT WORKING CODE BELOW!
if(isset($_POST['UPDATE_RAW'])) {
extract($_POST);
$sql = mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd', Resolved_Date='$resolved_date' WHERE ID='$id'");
if($sql) {
echo "<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else {
echo "<script>alert('Some ERRORS');</script>";
}
}
HERE IS A PICTURE OF MY DB SCHEMA
enter image description here
HERE IS THE TOTAL PHP FILE
<?php include_once "header.php";?>
<section class="content">
<div class="page-body clearfix">
<?php
$id=$_REQUEST['id'];
$sql=mysqli_query($db,"SELECT NMA_RAW.*, NMA_RAW.Check_Status, NMA_RAW.Resolved_Date, NMA_RAW.Filtered_Date FROM NMA_RAW WHERE (((NMA_RAW.Check_Status)='OK') AND ((NMA_RAW.Resolved_Date) Is Null) AND ((NMA_RAW.Filtered_Date) Is Null)) AND NMA_RAW.ID = $id;");
$row = mysqli_fetch_array($sql);
?>
<div class="panel panel-default">
<div class="panel-heading">NMA Active Ticket Form</div>
<div class="panel-body">
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<div class="col-sm-4">
<label>NMA System</label>
<input type="text" id="nma_system" class="form-control" placeholder="NMA System" value="<?= $row['NMA_System']; ?>" name="nmasystem">
</div>
<div class="col-sm-4">
<label>NMA Ticket Number</label>
<input type="text" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?= $row['NMA_Ticket_Number']; ?>" name="nmaticketnum">
</div>
<div class="col-sm-4">
<label>Ticket Priority</label>
<input type="text" id="ticket_priority" class="form-control" placeholder="Ticket Priority" value="<?= $row['Tkt_Priority']; ?>" name="tktpriority">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Created On Worklist</label>
<input type="text" id="created_on_work_list" class="form-control" placeholder="Created On Worklist" value="<?= $row['Created_On_Worklist']; ?>" name="createdonworklist">
</div>
<div class="col-sm-4">
<label>Created Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="created_date" class="form-control" placeholder="Created Date" value="<?= $row['Create_Date']; ?>" name="createdate">
</div>
</div>
<div class="col-sm-4">
<label>Created time</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="time" id="created_time" class="form-control" placeholder="Created Time" value="<?= $row['Create_Time']; ?>" name="createtime">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Days Old</label>
<input type="text" id="days_old" class="form-control" placeholder="Days old" value="<?= $row['Days_Old']; ?>" name="daysold">
</div>
<div class="col-sm-4">
<label>Check</label>
<input type="text" id="check" class="form-control" placeholder="Check" value="<?= $row['Check_Status']; ?>" name="checkstatus">
</div>
<div class="col-sm-4">
<label>Ticket Status</label>
<input type="text" id="ticket_status" class="form-control" placeholder="Ticket Status" value="<?= $row['Ticket_Status']; ?>" name="ticketstatus">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Interval</label>
<input type="text" id="interval" class="form-control" placeholder="Interval" value="<?= $row['Interval_Onlist']; ?>" name="intervalonlist">
</div>
<div class="col-sm-4">
<label>Related Status</label>
<input type="text" id="relate_status" class="form-control" placeholder="Relate Status" value="<?= $row['Relate_Status']; ?>" name="relatestatus">
</div>
<div class="col-sm-4">
<label>WFA TR Num</label>
<input type="text" id="wfa_tr_num" class="form-control" placeholder="WF TR Num" value="<?= $row['WFA_TR_Num']; ?>" name="wfatrnum">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Recent WFA Dispatch Status</label>
<input type="text" id="recent_wfa_dispatch_status" class="form-control" placeholder="Recent WFA Dispatch Status"
value="<?= $row['Recent_WFA_Dispatch_Status']; ?>" name="recentwfadispatchstatus">
</div>
<div class="col-sm-4">
<label>Entity Status</label>
<input type="text" id="entity_status" class="form-control" placeholder="Intity Status" value="<?= $row['Entity_Status']; ?>" name="entitystatus">
</div>
<div class="col-sm-4">
<label>Entity</label>
<input type="text" name="entity" id="entity" class="form-control" placeholder="Entity" value="<?= $row['Entity']; ?>" name="entity">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Last Owner</label>
<input type="text" id="last_owner" class="form-control" placeholder="Last Owner" value="<?= $row['Last_Owner']; ?>" name="lastowner">
</div>
<div class="col-sm-4">
<label>First Cond Type</label>
<input type="text" id="first_cond_type" class="form-control" placeholder="First Cond Type" value="<?= $row['First_Cond_Type']; ?>" name="firstcondtype">
</div>
<div class="col-sm-4">
<label>Last Cond Type</label>
<input type="text" id="last_cond_type" class="form-control" placeholder="Last Cond Type" value="<?= $row['Last_Cond_Type']; ?>" name="lastcondtype">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>State</label>
<input type="text" id="state" class="form-control" placeholder="State" value="<?= $row['State']; ?>" name="st">
</div>
<div class="col-sm-4">
<label>Check Active</label>
<input type="text" id="check_active" class="form-control" placeholder="Check Active" value="<?= $row['Check_Active']; ?>" name="checkactive">
</div>
<div class="col-sm-4">
<label>Check Jepd</label>
<input type="text" name="check_jepd" id="check_jepd" class="form-control"placeholder="Check Jepd" value="<?= $row['Check_Jepd']; ?>" name="checkjepd">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>CLLI</label>
<input type="text" id="clli" class="form-control" placeholder="CLLI" value="<?= $row['CLLI']; ?>" name="clli">
</div>
<div class="col-sm-4">
<label>Resolved Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="resolved_date" class="form-control" placeholder="Resolved_Date" value="<?= $row['Resolved_Date']; ?>" name="resolved_date">
</div>
</div>
<div class="col-sm-4">
<label>Filtered Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="filtered_date" class="form-control" placeholder="Filtered Date" value="<?= $row['Filtered_Date']; ?>" name="filtereddate">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Filtered By</label>
<input type="text" id="filtered_by" class="form-control" placeholder="Filtered by" value="<?= $row['Filtered_By']; ?>" name="filteredby">
</div>
<div class="col-sm-4">
<label>Restored Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="restored_date" class="form-control" placeholder="Restored_Date" value="<?= $row['Restored_Date']; ?>" name="restoreddate">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4 ">
<label class="text-bold"> NMA Comments subform </label>
</div>
<div class="col-sm-4">
</div>
</div>
<hr>
<div class="form-group">
<?php
$io = mysqli_query($db,"select * from NMA_Comments where NMA_Tkt_Num='$row[NMA_Ticket_Number]'");
$tr=mysqli_fetch_assoc($io);
?>
<div class="col-sm-4">
<label>NMA Ticket Number</label>
<input type="text" name="NMA_Ticket_Number" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?php echo $tr['NMA_Tkt_Num']; ?>" >
</div>
<div class="col-sm-4">
<label>NMA Notes</label>
<textarea type="text" name="NMA_Notes" id="nma_notes" class="form-control" placeholder="NMA Notes"><?php echo $tr['NMA_Notes']; ?></textarea>
</div>
<div class="col-sm-4">
<label>NMA Note Date</label>
<input type="text" name="NMA_Ticket_Date" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?php echo $tr['NMA_Note_Date']; ?>">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<button class="btn btn-primary" name="UPDATE_RAW"> Save and Close</button>
</div>
<div class="col-sm-4">
<button class="btn btn-success" name="MOVE_TO_RESOLVED"> Resolved and Close</button>
</div>
<div class="col-sm-4">
<button class="btn btn-danger" name="MOVE_TO_INHIBITS"> Inhibit and Close</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<?php
if(isset($_POST['UPDATE_RAW'])){
extract($_POST);
//print_r($_POST);
$sql=mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd', Resolved_Date='$resolved_date' WHERE ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
}
?>
<?php
if(isset($_POST['MOVE_TO_INHIBITS'])){
extract($_POST);
//$print_r($_POSt);
$sql=mysqli_query($db,"INSERT INTO nma_main_table SELECT * FROM nma_raw where ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
// sql to delete a record
$sql=mysqli_query($db,"DELETE FROM nma_raw WHERE ID='$id'");
if ($sql){
echo "Record Inhibited successfully";
} else {
echo "<script>alert('Error in deletion');</script>";
}
}
?>
<?php
if(isset($_POST['MOVE_TO_RESOLVED'])){
extract($_POST);
//$print_r($_POSt);
$sql=mysqli_query($db,"INSERT INTO nma_main_table SELECT * FROM nma_raw where ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
// sql to delete a record
$sql=mysqli_query($db,"DELETE FROM nma_raw WHERE ID='$id'");
if ($sql){
echo "Record Resolved successfully";
} else {
echo "<script>alert('Error in deletion');</script>";
}
}
?>
<?php include_once "footer.php";?>
If the error you're getting is Incorrect date value: '' for column 15daytkt.nma_raw.Resolved_Date (as you've mentioned in the comments) :
It looks like you are passing an empty string to the Resolved_Date column, and it's invalid. Please make sure you're actually passing a valid date string in this format 2019-11-15. Usually, the HTML form inputs with the date type return this format.
You can verify this case by setting the value to NULL if it's empty. Try changing the query as below:
$sql = mysqli_query($db,"update nma_raw set NMA_System='$nmasystem', Resolved_Date=NULLIF($resolved_date, '') WHERE ID='$id'");
Note the NULLIF($resolved_date, '') part. It will basically set the value to null if it is empty.
Hope it helps.
i am creating a registration page and I want to autofill the the value of certain input field whenever i choose a specific department like .when i choose the department A . it will autofill who is the supervisor on that department on my registration .how do i do it ?
this is my html view code
<?php if (validation_errors()) { ?>
<div class="alert alert-danger" role="alert">
<center><span class="glyphicon glyphicon-alert" aria-hidden="true"></span><strong> Error!</strong><p><?= validation_errors(); } ?></p></center>
</div>
<?php if (isset($error)){ ?>
<div class="alert alert-danger" role="alert">
<center><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><strong> Error! </strong><?= $error ?> </center>
</div>
<?php } ?>
<div class="container-fluid">
<center> <h2>Register</h2></center>
<hr class="colorgraph">
<form class="form-horizontal" action="<?= base_url().'login/registeruser' ?>" method="post">
<div class="form-group">
<label for="username" class="col-sm-2 control-label "><?php if(form_error('username')){ echo '<p style="color:#a94442"> * Username </p>';} else { echo 'Username'; } ?></label>
<div class="col-sm-6">
<input type="text" class="form-control <?php if (form_error('username')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="username" name="username" placeholder="Username" value="<?php echo set_value('username'); ?>">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label "><?php if(form_error('password')||form_error('confpassword')){ echo '<p style="color:#a94442"> * Password </p>';} else { echo 'Password'; } ?></label>
<div class="col-sm-6">
<input type="password" class="form-control <?php if (form_error('password')||form_error('confpassword')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="password" name="password" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="confpassword" class="col-sm-2 control-label"><?php if(form_error('password')||form_error('confpassword')){ echo '<p style="color:#a94442"> * Confirm Password </p>';} else { echo 'Confirm Password'; } ?></label>
<div class="col-sm-6">
<input type="password" class="form-control <?php if (form_error('password')||form_error('confpassword')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="confpassword" name="confpassword" placeholder="Confirm Password">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label "><?php if(form_error('email')){
echo '<p style="color:#a94442"> * Email </p>';} else { echo 'Email'; } ?></label>
<div class="col-sm-6">
<input type="email" class="form-control <?php if (form_error('email')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="email" name="email" placeholder="Email"
value="<?php echo set_value('email'); ?>">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label"><?php if(form_error('fname')||form_error('mname')||form_error('lname')){ echo '<p style="color:#a94442"> * Full Name </p>';} else { echo 'Full Name'; } ?></label>
<div class="col-sm-2">
<input type="text" class="form-control <?php if (form_error('fname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="fname" name="fname" placeholder="First Name" value="<?php echo set_value('fname'); ?>">
</div>
<div class="col-sm-2">
<input type="text" value ="sa" class="form-control <?php if (form_error('mname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="mname" name="mname" placeholder="Middle Name" value="<?php echo set_value('mname'); ?>">
</div>
<div class="col-sm-2">
<input type="text" class="form-control <?php if (form_error('lname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="lname" name="lname" placeholder="Last Name" value="<?php echo set_value('lname'); ?>">
</div>
</div>
<div class="form-group">
<label for="gender" class="col-sm-2 control-label ">Gender</label>
<label class="radio-inline col-sm-1 control-label">
<input type="radio" name="gender" id="gender" value="M" selected="selected"> Male
</label>
<label class="radio-inline">
<input type="radio" name="gender" id="gender" value="F"> Female
</label>
</div>
<div class="form-group">
<label for="gender" class="col-sm-2 control-label ">Department</label>
<select name="Department">
<option value="stem">STEM</option>
<option value="gas">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</div>
<div class="form-group">
<div class="col-sm-4 control-label">
<h3><strong>
Captcha
<?=$image; ?></strong></h3>
<input type="text" id="captcha" name="captcha" height="50px" autocomplete="off" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span> Back</button>
<button type="submit" class="btn btn-primary">Register</button>
</div>
</div>
</form>
</div>
</body>
i want to specifically use php code .how do i do it ? thanks
You can use jquery ajax functionality for the same.
So I'm trying to insert in the database and upload a file. But when I'm trying to submit, it returns a server error.
The same code is working on my other project but it is using CI2, i checked the .htaccess and its all the same
The localhost page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500
I think the problem is in the $this->upload->do_upload('userfile') because i tried to comment out from this part and display echo the config array and there's no error but when i tried to uncomment up to this part, the error shows.
Controller
public function add_now(){
$this->load->library('form_validation');
$this->form_validation->set_rules('Event_Name', 'Event Name', 'trim|strip_tags');
$this->form_validation->set_rules('Event_Start', 'Start Date', 'trim|strip_tags');
$this->form_validation->set_rules('Event_End', 'End Date', 'trim|strip_tags');
$this->form_validation->set_rules('Event_Location', 'Location', 'trim|strip_tags');
if($this->form_validation->run() == FALSE){
$this->add();
}
else{
$query = $this->events_model->do_upload();
if($query){
$this->session->set_flashdata('success', 'Successful!');
$this->index();
}
else{
if(!$this->session->flashdata('upload_error')){
$this->session->set_flashdata('failed', 'Failed!');
}
$this->add();
}
}
}
Model
public function do_upload(){
$config['upload_path'] = './resources/images/events_photo/temp/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['file_name'] = uniqid().'.jpeg';
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
if(!$this->upload->do_upload('userfile')){
$this->session->set_flashdata('upload_error', $this->upload->display_errors());
}
}
View
<?php echo form_open_multipart('events/add_now'); ?>
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="control-label">Name</label>
<input type="text" class="form-control" name="Event_Name" value="<?php echo set_value('Event_Name'); ?>" placeholder="Enter Event Name">
<small class="text-danger"><?php echo form_error('Event_Name'); ?></small>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">Start Date</label>
<input type="text" class="form-control" name="Event_Start" value="<?php echo set_value('Event_Start'); ?>" placeholder="Enter Start Date" onclick="this.type='datetime-local'" onblur="this.type='text'" min="<?php echo date('Y-m-d'); ?>">
<small class="text-danger"><?php echo form_error('Event_Start'); ?></small>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">End Date</label>
<input type="text" class="form-control" name="Event_End" value="<?php echo set_value('Event_End'); ?>" placeholder="Enter End Date" onclick="this.type='datetime-local'" onblur="this.type='text'" min="<?php echo date('Y-m-d'); ?>">
<small class="text-danger"><?php echo form_error('Event_End'); ?></small>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-9">
<div class="form-group">
<label class="control-label">Location</label>
<input type="text" class="form-control" name="Event_Location" value="<?php echo set_value('Event_Location'); ?>" placeholder="Enter Event Location">
<small class="text-danger"><?php echo form_error('Event_Location'); ?></small>
</div>
</div>
</div>
<div class="row">
<textarea placeholder="Event Description" name="Event_Description" rows="10" class="form-control"></textarea>
</div>
<div class="row">
<div class="form-group">
<label class="control-label">Image Attachment (Optional)</label>
<input type="file" class="form-control" name="userfile" value="<?php echo set_value('userfile'); ?>" placeholder="Upload Image">
<?php if($this->session->flashdata('upload_error')): ?>
<small class="text-danger"><?php echo $this->session->flashdata('upload_error'); ?></small>
<?php endif; ?>
</div>
</div>
</div>
<div class="panel-footer text-right">
<button class="btn btn-success" type="submit">Submit</button>
</div>
</form>
So I'm trying to insert in the database and upload a file. But when I'm trying to submit, it returns a server error.
The localhost page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500
I think the problem is in the $this->upload->do_upload('userfile') because i tried to comment out from this part and display echo the config array and there's no error but when i tried to uncomment up to this part, the error shows.
Controller
public function add_now(){
$this->load->library('form_validation');
$this->form_validation->set_rules('Event_Name', 'Event Name', 'trim|strip_tags');
$this->form_validation->set_rules('Event_Start', 'Start Date', 'trim|strip_tags');
$this->form_validation->set_rules('Event_End', 'End Date', 'trim|strip_tags');
$this->form_validation->set_rules('Event_Location', 'Location', 'trim|strip_tags');
if($this->form_validation->run() == FALSE){
$this->add();
}
else{
$query = $this->events_model->do_upload();
if($query){
$this->session->set_flashdata('success', 'Successful!');
$this->index();
}
else{
if(!$this->session->flashdata('upload_error')){
$this->session->set_flashdata('failed', 'Failed!');
}
$this->add();
}
}
}
Model
public function do_upload(){
$config['upload_path'] = './resources/images/events_photo/temp/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['file_name'] = uniqid().'.jpeg';
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
if(!$this->upload->do_upload('userfile')){
$this->session->set_flashdata('upload_error', $this->upload->display_errors());
}
}
View
<?php echo form_open_multipart('events/add_now'); ?>
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="control-label">Name</label>
<input type="text" class="form-control" name="Event_Name" value="<?php echo set_value('Event_Name'); ?>" placeholder="Enter Event Name">
<small class="text-danger"><?php echo form_error('Event_Name'); ?></small>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">Start Date</label>
<input type="text" class="form-control" name="Event_Start" value="<?php echo set_value('Event_Start'); ?>" placeholder="Enter Start Date" onclick="this.type='datetime-local'" onblur="this.type='text'" min="<?php echo date('Y-m-d'); ?>">
<small class="text-danger"><?php echo form_error('Event_Start'); ?></small>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">End Date</label>
<input type="text" class="form-control" name="Event_End" value="<?php echo set_value('Event_End'); ?>" placeholder="Enter End Date" onclick="this.type='datetime-local'" onblur="this.type='text'" min="<?php echo date('Y-m-d'); ?>">
<small class="text-danger"><?php echo form_error('Event_End'); ?></small>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-9">
<div class="form-group">
<label class="control-label">Location</label>
<input type="text" class="form-control" name="Event_Location" value="<?php echo set_value('Event_Location'); ?>" placeholder="Enter Event Location">
<small class="text-danger"><?php echo form_error('Event_Location'); ?></small>
</div>
</div>
</div>
<div class="row">
<textarea placeholder="Event Description" name="Event_Description" rows="10" class="form-control"></textarea>
</div>
<div class="row">
<div class="form-group">
<label class="control-label">Image Attachment (Optional)</label>
<input type="file" class="form-control" name="userfile" value="<?php echo set_value('userfile'); ?>" placeholder="Upload Image">
<?php if($this->session->flashdata('upload_error')): ?>
<small class="text-danger"><?php echo $this->session->flashdata('upload_error'); ?></small>
<?php endif; ?>
</div>
</div>
</div>
<div class="panel-footer text-right">
<button class="btn btn-success" type="submit">Submit</button>
</div>
</form>
First load the url helper in your controller...
$this->load->helper('url');
Then set the upload file path as:
$config['upload_path'] = base_url('resources/images/events_photo/temp/');
Try it might works.
And what about these two functions
$this->add();
$this->success();
I have a "create user"form with reset and create button. This reset button is not working for some drop-downs in the form.
In addition, reset button is not clearing all the values in the form after validation. It only clears the values entered after validation.
Here is my code:
<div class="form-action clearfix">
<button type="button" onClick="clearForm()" > Reset </button>
<button class="button" type="button" id="button" onclick="doAjax('index.php/users/createUser', convertFormJson('#createUserForm'));">Create</button>
and
function clearForm() {
document.getElementById('createUserForm').reset();
}
Form:
<?php echo validation_errors(); ?>
<div class="container_12 clearfix leading" >
<div class="grid_12">
<!--<form class= "form has-validation">-->
<?php
$attributes = array('class' => 'form has-validation', 'id' => 'createUserForm');
echo form_open('/users/createUser', $attributes);
?>
<div class="clearfix">
<label for="form-name" class="form-label">First Name <em>*</em></label>
<div class="form-input">
<input type="text" id="form-name" name="firstname" required="required" placeholder="Enter the first name" value="<?php echo set_value('firstname'); ?>" />
</div>
</div>
<div class="clearfix">
<label for="form-name" class="form-label">Last Name <em>*</em></label>
<div class="form-input">
<input type="text" id="form-name" name="lastname" required="required" placeholder="Enter the last name" value="<?php echo set_value('lastname'); ?>"/>
</div>
</div>
<div class="clearfix">
<label for="form-email" class="form-label">Email <em>*</em></label>
<div class="form-input"><input type="email" id="form-email" name="email" required="required" placeholder="A valid email address" value="<?php echo set_value('email'); ?>"/></div>
</div>
<!--
<div class="clearfix">
<label for="form-birthday" class="form-label">Birthdate</label>
<div class="form-input"><input type="date" id="form-birthday" name="date" placeholder="mm/dd/yyyy" value="<?php //echo set_value('date'); ?>" class="date"/></div>
</div>
-->
<div class="clearfix">
<label for="form-username" class="form-label">Username <em>*</em></label>
<div class="form-input">
<?php echo form_error('username'); ?>
<input type="text" id="form-username" name="username" value="<?php echo set_value('username'); ?>" required="required" maxlength="30" placeholder="Alphanumeric (max 30 char.)" />
</div>
</div>
<div class="clearfix">
<label for="form-password" class="form-label">Password <em>*</em></label>
<div class="form-input">
<?php echo form_error('password'); ?>
<input type="password" id="form-password" name="password" value="<?php echo set_value('password'); ?>" maxlength="30" placeholder="Min 8 char. containing a capital, number and/or symbol" />
</div>
</div>
<div class="clearfix">
<label for="form-password-check" class="form-label">Password check <em>*</em></label>
<div class="form-input">
<?php echo form_error('passconf'); ?>
<input type="password" id="form-password-check" name="passconf" value="<?php echo set_value('passconf'); ?>" data-equals="password" maxlength="30" placeholder="Re-enter your password" />
</div>
</div>
<div class="clearfix">
<label for="form-group" class="form-label">Group <em>*</em></label>
<div class="form-input">
<?php
$groupsData[' '] = "--";
$groupJs = 'id="form-group"';
echo form_dropdown('groupId', $groupsData,' ',$groupJs);
?>
</div>
</div>
<div class="clearfix">
<label for="form-language" class="form-label" >Language <em>*</em></label>
<div class="form-input">
<select id="form-language" name="language">
<option value ="" > -- </option>
<option value ="1">English</option>
<option value ="2">French</option>
</select>
</div>
</div>
<div class="clearfix">
<label for="form-timezone" class="form-label" >Timezone <em>*</em></label>
<div class="form-input">
<?php echo timezone_menu('UM5', 'form-timezone'); ?>
</div>
</div>
Please help me out.