input multiple value to one row in codeigniter - php

I have 3 pieces of the column, which I will inserting in one table in my database. The name of each form like this:
<h3><?= $title; ?></h3><?php echo form_open("admin/artikel/buat/");?>
<table width="95%">
<tr>
<td><b>Pilih Referensi Jurnal</b></td>
<td>
<input type="hidden" name="IDJurnal" id="IDJurnal" value="<?php echo $IDJurnal; ?>" />
<input type="text" name="volume" id="volume" value="<?php echo $volume; ?>" readonly="readonly" class="sedang" />
<?php echo anchor_popup('admin/artikel/popup', 'Referensi Jurnal', array('class' => 'button')); ?>
</td>
</tr>
<tr>
<td><b>Kategori</b></td>
<td>
<?php
echo form_dropdown('IDKategori', $kategori) . "";
?>
</td>
</tr>
<tr>
<td width="125"><strong>Judul</strong></td>
<td><input type="text" name="judul" class="panjang"></td>
</tr>
<tr>
<td width="125"><strong>Pengarang</strong></td>
<td>
<input type="text" name="pengarang" class="panjang">
<input type="text" name="pengarang" class="panjang">
<input type="text" name="pengarang" class="panjang">
</td>
</tr>
<tr>
<td><b>Abstract</b></td>
<td>
<?php
$data = array('name' => 'abstract');
echo $this->ckeditor->editor($data['name']);
?>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" class="button" value="Simpan">
<input type="button" class="button" value="Batal" onClick="javascript: history.go(-1)" />
</td>
</tr>
<?php
echo form_close();
?>
i want inserting the value from each form name to my sql table, like this:
CREATE TABLE `pengarang`(
`IDPengarang` INT(11)NOT NULL AUTO_INCREMENT,
`IDArtikel` INT(11)NOT NULL,
`nama_pengarang` VARCHAR(255)NOT NULL,
PRIMARY KEY(`IDPengarang`))ENGINE = INNODB DEFAULT CHARSET = utf8;
in my model like this:
function addArtikel() {
$now = date("Y-m-d H:i:s");
$data = array(
'IDJurnal' => $this->input->post('IDJurnal'),
'IDKategori' => $this->input->post('IDKategori'),
'judul' => $this->input->post('judul'),
'abstract' => $this->input->post('abstract'),
'created_time' => $now,
'created_by' => $_SESSION['username']
);
// $data1 = array(
// 'IDJurnal' => $this->input->post('IDJurnal'),
// 'IDKategori' => $this->input->post('IDKategori'),
// 'judul' => $this->input->post('judul'),
// 'abstract' => $this->input->post('abstract'),
// 'created_time' => $now,
// 'created_by' => $_SESSION['username']
// );
// $data2 = array(
// 'IDArtikel' => $this->input->post('IDArtikel'),
// 'nama_pengarang' => $this->input->post('pengarang')
// );
$this->db->insert('artikel', $data);
// $this->db->insert_batch('artikel', $data1);
// $this->db->insert_batch('pengarang', $data1);
}
in my controller
function buat() {
if ($this->input->post('judul')) {
$this->MArtikel->addArtikel();
$this->session->set_flashdata('message', 'Artikel telah di buat !');
redirect('admin/artikel/index', 'refresh');
} else {
// konfigurasi ckfinder dengan ckeditor
$this->load->library('ckeditor');
$this->load->library('ckfinder');
$this->ckeditor->basePath = base_url() . 'asset/ckeditor/';
$this->ckeditor->config['toolbar'] = 'Full';
$this->ckeditor->config['language'] = 'en';
$this->ckfinder->SetupCKEditor($this->ckeditor, '../../../asset/ckfinder/');
$data['title'] = "Tambah Artikel";
$data['main'] = 'admin/artikel/artikel_buat';
$data['jurnal'] = $this->MJurnal->getJurnalDropDown();
$data['kategori'] = $this->MKategori->getKategoriDropDown();
$this->load->vars($data);
$this->load->view('dashboard/template');
}
}
What should I add to my controller and my model, that would make the results in my table looks like this
IDPengarang IDArtikel nama_pengarang
1 1 testing 1
2 1 testing 2
3 1 testing 3
thank's before

Related

how to display the date of birth from a database to a form and update it in php & PDO?

I have three pages where i want to update an existing row of a specific user by their unique id.But when i click to the update link it shows all the field with their values except the date of birth. I am trying to find out the problem. but failed as i am quite new to php. any one please help if you can.
Here is my HTML form
<form action="update.php" method="post">
<table>
<?php
include_once ("../vendor/autoload.php");
use Admission\Admission\Admission;
$object_for_showDetails = new Admission();
$object_for_showDetails->setData($_GET);
$data = $object_for_showDetails->details();
$values = $data;
?>
<th align="center" colspan="2"> <h3>Applicant's Information</h3></th>
<tr>
<td>Name of Applicant:<spam>*</spam></td>
<td><input class="nice" type="text" name="name" value="<?php echo $values['student_name']?>"></td>
<td><input type="hidden" name="id" value="<?php echo $values['uid']?>"></td>
</tr>
<tr>
<td>Email:<spam>*</spam></td>
<td><input class="nice" type="email" name="email" value="<?php echo $values['email']?>"></td>
</tr>
<tr>
<td> Gender:<spam>*</spam></td>
<td> <input type="radio" class="radio" value="male" name="gender" <?php echo ($values['gender']=='male')?'checked':'';?> />Male
<input type="radio" class="radio" value="female" name="gender" <?php echo ($values['gender']=='female')?'checked':'';?> /> Female </td>
</tr>
<tr>
<td> Birth Date:<spam>*</spam></td>
<td> <input class="nice" type="date" name="<?php echo $values['birth_date']?>" > </td>
</tr>
<tr>
<td> Religion:<spam>*</spam></td>
<td> <input class="nice" type="text" name="religion" value="<?php echo $values['religion']?>"></td>
</tr>
<tr>
<td> Phone:<spam>*</spam></td>
<td> <input class="nice" type="text" name="phone" value="<?php echo $values['phone']?>"></td>
</tr>
<th align="center" colspan="2"> <h3>Parent's information</h3></th>
<tr>
<td> Father Name::<spam>*</spam></td>
<td> <input class="nice" type="text" name="father_name" value="<?php echo $values['father_name']?>"></td>
</tr>
<tr>
<td> Mother Name::<spam>*</spam></td>
<td> <input class="nice" type="text" name="mother_name" value="<?php echo $values['mother_name']?>"></td>
</tr>
<tr>
<td> Guardian/Parent's Phone:<spam>*</spam></td>
<td> <input class="nice" type="text" name="guardian_phone" value="<?php echo $values['guardian_phone']?>"></td>
</tr>
<td>
Details|
Update Info|
Delete
</td>
<tr>
<td colspan="2" align="center"><input type="submit" value="update" class="btn"></td>
</tr>
</table>
</form>
Here is my update.php file
<?php
include_once ("../vendor/autoload.php");
use Admission\Admission\Admission;
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$object_of_update = new Admission();
$object_of_update->setData($_POST);
$object_of_update->update();
}
else{
header("location:create.php");
}
?>
and last the update methode under the main class file Admission.php
where setData() is for set the values and details() is for showing the data which fetch data from the database of a specific user and the update() method for updating the values from the database.
public function store()
{
try {
$pdo = new PDO ('mysql:host=localhost;dbname=university', 'root', '');
$query_for_insert = "INSERT INTO `student_form`(`id`, `uid`, `student_name`, `email`, `birth_date`, `gender`, `religion`, `phone`, `father_name`, `mother_name`, `guardian_phone`)
VALUES (:id,:uid,:student_name,:email,:birth_date,:gender,:religion,:phone,:father_name,:mother_name,:guardian_phone)";
$statement = $pdo->prepare($query_for_insert);
$statement->execute(array(
':id' => null,
':uid' => uniqid(),
':student_name' => $this->name,
':email' => $this->email,
':birth_date' => $this->birth_date,
':gender' => $this->gender,
':religion' => $this->religion,
':phone' => $this->phone,
':father_name' => $this->father_name,
':mother_name' => $this->mother_name,
':guardian_phone' => $this->guardian_phone,
));
if ($statement) {
session_start();
$_SESSION['message'] = "You have successfully Applied to the University Of Dhaka.Please Bring your Admit card during Admission test";
header("location:register.php");
}
} catch (PDOException $e) {
echo "Connection Error" . $e->getMessage();
}
}
public function update(){
echo "update method";
try {
$pdo = new PDO ('mysql:host=localhost;dbname=university', 'root', '');
$queryForUpdata = "UPDATE `student_form` SET `student_name`=:student_name,`email`= :email,`birth_date` =:birth_date,`gender`=:gender,`religion`=:religion,`phone`=:phone,`father_name`=:father_name,`mother_name`=:mother_name,`guardian_phone`=:guardian_phone WHERE uid="."'".$this->id."'";
$statement = $pdo->prepare($queryForUpdata);
$statement->execute(array(
':student_name' => $this->name,
':email' => $this->email,
':birth_date' => $this->birth_date,
':gender' => $this->gender,
':religion' => $this->religion,
':phone' => $this->phone,
':father_name' => $this->father_name,
':mother_name' => $this->mother_name,
':guardian_phone' => $this->guardian_phone
));
if ($statement) {
session_start();
$_SESSION['message'] = "You have successfully Updated Your Information";
header('location:register.php');
}
}
catch (PDOException $e) {
echo "Connection Error" . $e->getMessage();
}
}
Please if anyone can fix this out i will be grateful to you.
It looks like you are not setting "value" tag on "Birth date" input so when your record updates and page refreshes you are missing its value.
Also, your input name is birth_data while in php you are trying to access birth_date
<input class="nice" type="date" name="birth_date" value="<?php echo is_object($values["birth_date"]) ? $values["birth_date"]->format("Y-m-d") : $values["birth_date"]?>">

How to update image with form hidden?

Hi all I am a new codeigniter .I have create code update image with form hidden but I have problam the from hidden not passing value to form image userfile :( Iam very need help now ?or could anyone give the source code about update image in to database on codigniter.
<form action="<?php echo base_url()."./site_admin/update_menu/".$this->uri->segment(3); ?>" method="post" enctype="multipart/form-data">
<?php
$id = $this->uri->segment(3);
$sql = $this->db->get_where('menu',array('id_menu' => $id));
$row = $sql->row(); ?>
<?php $idcat = $row->cate_id ?>
<table class="tab" style="width:100%">
<tr>
<td>Categories Name:</td>
<td>
<select style="padding:6px;background:#C2C2C2;font-weight: bold;" name="cate">
<?php
$query = $this->db->get('categories_menu');
foreach($query->result() as $lazy){
$select = "";
if($lazy->id == $idcat){
$select = "selected";
}
echo "<option $select value='".$lazy->id."'>".$lazy->cate_name_menu."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Upload image:</td>
<td><input type="file" name="userfile" style="width:190px;height:35px;font-weight: bold;background:#C2C2C2;" ></td>
<td><input type="hidden" name="mono" value="<?php echo $row->image; ?>"></td>
</td>
</tr>
<tr>
<td>Title:</td>
<td><textarea class="title" name="title" cols="100" rows="4"><?php echo $row->title; ?></textarea></td>
</tr>
<tr>
<td>Description:</td>
<td><textarea rows="15" name="description" class="dess" ><?php echo $row->description; ?></textarea><td>
</tr>
<tr>
<td>Prices</td>
<td><textarea class="price" name="price" cols="40" rows="4"><?php echo $row->prices; ?></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input style="width:100px; padding:10px;font-weight: bold;background:#1F1F1F;color:white;" type="submit" value="Submit" name="submit">
</td>
</tr>
</table>
</form>
Controller:
function update_menu(){
$id = $this->uri->segment(3);
$img1 = $this->input->post('userfile');
$img2 = $this->input->post('mono');
if($img1 == ""){
$img1 = $img2;
$datas = array(
'cate_id' => $this->input->post('cate'),
'title' => $this->input->post('title'),
'description' => $this->input->post('description'),
'prices' => $this->input->post('price'),
'image' => $img1
);
$this->db->where('id_menu', $id);
$this->db->update('menu',$datas);
redirect('./site_admin/edit_menu/'.$id);
}else{
$id = $this->uri->segment(3);
$updata = array(
'upload_path' => './images/',
'allowed_types' => 'gif|jpg|png',
'max_size' => '5000',
'max_width' => '4000',
'max_height' => '2800'
);
$this->load->library('upload',$updata);
$this->upload->do_upload('userfile');
$nampic = $this->upload->data();
$data = array(
'cate_id' => $this->input->post('cate'),
'title' => $this->input->post('title'),
'description' => $this->input->post('description'),
'prices' => $this->input->post('price'),
'image' => $nampic['file_name']
);
$this->db->where('id_menu', $id);
$this->db->update('menu',$data);
redirect('./site_admin/edit_menu/'.$id);
}
}

Copy database contents from one table to another table in codeigniter

I need to copy table contents from table: user_openletter to table: country on clicking archive button. How to write a query to copy from,to,title,openletter,open_id from user_openletter to another table country. This a codeigniter app.
my controller code is :
public function store_user_data_archieve()
{
$match = $this->input->post('submit');
echo $match;
if($match == "Archieve")
{
$data = array(
'open_id' => $this->input->post('open_id'),
'featured' => '1',
'from' => $this->input->post('from'),
'to' => $this->input->post('to'),
'title' => $this->input->post('title'),
'archieve' => '1',
'latest' => '0',
'sponsor' => 'images/sponsor.png'
);
$this->load->database();
//load the model
$this->load->model('select');
//load the method of model
$data['r']=$this->select->store_user_data_archieve($data);
echo "success";
}
else if(!$match == "new")
{
$data = array(
'open_id' => $this->input->post('open_id'),
'featured' => '1',
'from' => $this->input->post('from'),
'to' => $this->input->post('to'),
'title' => $this->input->post('title'),
'openletter' => $this->input->post('openletter'),
'archieve' => '0',
'latest' => '1',
'sponsor' => 'images/sponsor.png'
);
$this->load->database();
//load the model
$this->load->model('select');
//load the method of model
$data['r']=$this->select->store_user_data_archieve($data);
echo "success";
}
else if(!$match == "Discard")
{
echo "failure";
}
}
My view code is:
<?php
foreach ($r->result() as $row)
{
?>
<table border="1" cellpadding="4" cellspacing="0">
<tr>
<td>from</td>
<td>to</td>
<td>title</td>
<td>openletter</td>
<td>Date & Time</td>
<td>open_id</td>
</tr>
<tr>
<form action="/index.php/welcome/store_user_data_archieve" method="post">
<td><input type="text" name="from" value="<?php echo $row->from;?>" /></td>
<td><input type="text" name="to" value="<?php echo $row->to;?>" /></td>
<td><input type="text" name="title" value="<?php echo $row->title;?>" /></td>
<td><input type="text" name="openletter" value="<?php echo $row->openletter;?>" /></td>
<td><input type="text" name="datetime" value="<?php echo $row->datetime;?>" /></td>
<td><input type="text" name="open_id" value="<?php echo $row->open_id;?>" /></td>
<td><div><input type="submit" name="submit" value="Archieve" /></div></td>
<td><div><input type="submit" name="new" value="new" /></div></td>
</form>
</tr>
</table>
<?php } ?>
My model code is:
public function store_user_data_archieve($data)
{
//data is retrieved from this query
$this->db->insert('country', $data);
$this->db->set('openletter');
$this->db->select('openletter');
$this->db->where('open_id', $data[open_id]);
$this->db->from('user_openletter');
// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
}
As per our discussion you need to copy from,to,title,openletter,open_id from table user_openletter to country table
$this->db->select('from,to,title,openletter,open_id');// select your filed
$q = $this->db->get('user_openletter')->result(); // get result from table
foreach ($q as $r) { // loop over results
$this->db->insert('country', $r); // insert each row to country table
}
$this->db->select('from, to, title,openletter, open_id');
$result_set = $this->db->get('user_openletter')->result();
if(count($result_set) > 0) {
$this->db->insert_batch('country', $result_set);
}

How to insert multiple column in codeigniter?

I want insert 2 column to database [artikel & pengarang], when I save that form it will be insert $data from to table artikel and $data to table pengarang [IDArtikel from Artikel &nama_pengarang].
This is my artikel SQL:
CREATE TABLE `artikel`(
`IDArtikel` INT(11)NOT NULL AUTO_INCREMENT,
`IDJurnal` INT(11)NOT NULL,
`IDKategori` INT(11)NOT NULL,
`judul` VARCHAR(255)NOT NULL,
`abstract` text NOT NULL,
`nama_file` VARCHAR(255)NOT NULL,
`dilihat` INT(50)NOT NULL,
`didownload` INT(50)NOT NULL,
`created_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by` VARCHAR(255)NOT NULL,
`updated_time` datetime NOT NULL,
`updated_by` VARCHAR(255)NOT NULL,
PRIMARY KEY(`IDArtikel`))ENGINE = INNODB DEFAULT CHARSET = utf8;
and this is pengarang SQL:
CREATE TABLE `pengarang`(
`IDPengarang` INT(11)NOT NULL AUTO_INCREMENT,
`IDArtikel` INT(11)NOT NULL,
`nama_pengarang` VARCHAR(255)NOT NULL,
PRIMARY KEY(`IDPengarang`))ENGINE = INNODB DEFAULT CHARSET = utf8;
this is my view:
<h3><?= $title; ?></h3><?php echo form_open("admin/artikel/buat/"); ?>
<table width="95%">
<tr>
<td><b>Pilih Referensi Jurnal</b></td>
<td>
<input type="hidden" name="IDJurnal" id="IDJurnal" value="<?php echo $IDJurnal; ?>" />
<input type="text" name="volume" id="volume" value="<?php echo $volume; ?>" readonly="readonly" class="sedang" />
<?php echo anchor_popup('admin/artikel/popup', 'Referensi Jurnal', array('class' => 'button')); ?>
</td>
</tr>
<tr>
<td><b>Kategori</b></td>
<td>
<?php
echo form_dropdown('IDKategori', $kategori) . "";
?>
</td>
</tr>
<tr>
<td width="125"><strong>Judul</strong></td>
<td><input type="text" name="judul" class="panjang"></td>
</tr>
<tr>
<td width="125"><strong>Pengarang</strong></td>
<td>
<input type="text" name="pengarang" class="panjang">
</td>
</tr>
<tr>
<td><b>Abstract</b></td>
<td>
<?php
$data = array('name' => 'abstract');
echo $this->ckeditor->editor($data['name']);
?>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" class="button" value="Simpan">
<input type="button" class="button" value="Batal" onClick="javascript: history.go(-1)" />
</td>
</tr>
<?php
echo form_close();
?>
this is my controller:
function buat() {
if ($this->input->post('judul')) {
$this->MArtikel->addArtikel();
$this->session->set_flashdata('message', 'Artikel telah di buat !');
redirect('admin/artikel/index', 'refresh');
} else {
// konfigurasi ckfinder dengan ckeditor
$this->load->library('ckeditor');
$this->load->library('ckfinder');
$this->ckeditor->basePath = base_url() . 'asset/ckeditor/';
$this->ckeditor->config['toolbar'] = 'Full';
$this->ckeditor->config['language'] = 'en';
$this->ckfinder->SetupCKEditor($this->ckeditor, '../../../asset/ckfinder/');
$data['title'] = "Tambah Artikel";
$data['main'] = 'admin/artikel/artikel_buat';
$data['jurnal'] = $this->MJurnal->getJurnalDropDown();
$data['kategori'] = $this->MKategori->getKategoriDropDown();
$this->load->vars($data);
$this->load->view('dashboard/template');
}
}
and this my model
function addArtikel() {
$now = date("Y-m-d H:i:s");
$data = array(
'IDJurnal' => $this->input->post('IDJurnal'),
'IDKategori' => $this->input->post('IDKategori'),
'judul' => $this->input->post('judul'),
'abstract' => $this->input->post('abstract'),
'created_time' => $now,
'created_by' => $_SESSION['username']
);
$this->db->insert('artikel', $data);
}
form in pengarang, can insert multiple data
Take a look at $this->db->insert_batch();
create new function in model addPengarang add the following code in your model, and change the values of data array as per your requirement it will insert values in Pengarng table
function addPengarang() {
$data = array(
'IDPengarang' => 'value for IDPegarang',
'IDArtikel' => 10,
'nama_pengarang' => 'value for nama pengarang'
);
$this->db->insert('pengarang', $data);
}

Code Igniter CRUD app: thumbnail image doesn't upload. Receive database error because NULL

Making a form that will accept a bunch of textual data and an image upload.
Keep getting this error when adding new item to both tables:
Error Number: 1048
Column 'id_path' cannot be null
INSERT INTO thumbnails (id_path, id_data_row) VALUES (NULL, 17)
Filename: C:\wamp\www\project\system\database\DB_driver.php
Line Number: 330
What I'm trying to do is add text data(stuff like title, text, price, etc.) into one table(data) and then upload an image and add its full upload path(as primary key in thumbnails table) and the id of the inserted text data row(to link it with the thumbnail in thumbnails table) into thumbnails table.
For some reason it keeps passing NULL as the full upload path to thumbnails table.
crud.php(the controller):
function add()
{
//Set validation properties
$this->_set_fields();
//Set common properties
$data['title'] = 'Add new data row';
$data['message'] = '';
$data['action'] = site_url('crud/addDataRow');
$data['link_back'] = anchor('crud/index', 'Back to list', array('class' => 'back'));
//Load the view
$this->load->view('templates/header', $data);
$this->load->view('pages/crud_edit', $data);
$this->load->view('templates/footer');
}
function addDataRow()
{
//Set common properties
$data['title'] = 'Add new data row';
$data['action'] = site_url('crud/addDataRow');
$data['link_back'] = anchor('crud/index/', 'Back to list', array('class' => 'back'));
//Set validation properties
$this->_set_fields();
$this->_set_rules();
//Run validation
if($this->form_validation->run() == FALSE)
{
$data['message'] = '';
}
else
{
//Save the data
$full_file_path = null;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$path_to_uploads='./uploads';
$config['upload_path'] = $path_to_uploads;
$this->load->library('upload', $config);
//add this
$this->upload->initialize($config);
if (!$this->upload->do_upload()){
$error = $this->upload->display_errors();
echo "<script>alert($error);</script>";
}else{
$upload_data=$this->upload->data();
$file_name=$upload_data['file_name'];
$full_file_path = $path_to_uploads.'/'.$file_name;
}
$data_row = array(
'title' => $this->input->post('title'),
'text' => $this->input->post('text'),
'price' => $this->input->post('price'),
'status' => $this->input->post('status'),
'type' => $this->input->post('type')
);
$id = $this->crud_model->save($data_row);
$thumbnail_row = array(
'id_path' => $full_file_path,
'id_data_row' => $id
);
$this->crud_model->save_thumbnail($thumbnail_row);
//Set form input name="id"
$this->form_validation->id = $id;
//Set user message
$data['message'] = '<div class="success">New data row added!</div>';
}
$this->load->view('templates/header', $data);
$this->load->view('pages/crud_edit', $data);
$this->load->view('templates/footer');
}
crud_model.php(the model):
//Add new data row
function save($data)
{
$this->db->insert($this->tbl_data, $data);
return $this->db->insert_id();
}
//Add the thumbnail upload path and id of the row in data table to link them
function save_thumbnail($data)
{
$this->db->insert($this->tbl_thumbnails, $data);
return $this->db->insert_id();
}
EDIT(html form code):
crud_edit.php(html form code for adding a new item or updating an existing one):
<div id="contentColumn">
<h1><?php echo $title; ?></h1>
<?php echo $message; ?>
<form method="post" action="<?php echo $action; ?>" multipart="multipart">
<div class="data">
<table>
<tr>
<td width="30%">ID</td>
<td>
<input type="text" name="id" disabled="disabled" class="text" value="<?php echo set_value('id'); ?>"/>
<input type="hidden" name="id" value="<?php echo set_value('id',$this->form_data->id); ?>"/>
</td>
</tr>
<tr>
<td valign="top">Title<span style="color:red;">*</span></td>
<td>
<input type="text" name="title" class="text" value="<?php echo set_value('title',$this->form_data->title); ?>"/>
<?php echo form_error('title'); ?>
</td>
</tr>
<tr>
<td valign="top">Text<span style="color:red;">*</span></td>
<td>
<textarea name="text" class="text">
<?php echo set_value('text',$this->form_data->text); ?>
</textarea>
<?php echo form_error('text'); ?>
</td>
</tr>
<tr>
<td valign="top">Price<span style="color:red;">*</span></td>
<td>
<input type="text" name="price" class="text" value="<?php echo set_value('price',$this->form_data->price); ?>"/>
<?php echo form_error('price'); ?>
</td>
</tr>
<tr>
<td valign="top">Thumbnail<span style="color:red;">*</span></td>
<td>
<?php echo form_upload(array('name'=>'thumb', 'type'=>'file', 'accept'=>'image/*'))?>
<!--<input type="file" name="thumb" size="20" />-->
<?php echo form_error('thumb'); ?>
</td>
</tr>
<!--
<tr>
<td valign="top">Images<span style="color:red;">*</span></td>
<td>
<input type="text" name="images" class="text" value="<?php echo set_value('images',$this->form_data->images); ?>"/>
<?php echo form_upload(array('name'=>'images', 'type'=>'file', 'multiple'=>'multiple', 'accept'=>'image/*'))?>
<?php echo form_error('images'); ?>
</td>
</tr>
-->
<tr>
<td valign="top">Status</td>
<td>
<input type="text" name="status" class="text" value="<?php echo set_value('status',$this->form_data->status); ?>"/>
<?php echo form_error('status'); ?>
</td>
</tr>
<tr>
<td valign="top">Type<span style="color:red;">*</span></td>
<td>
<input type="text" name="type" class="text" value="<?php echo set_value('type',$this->form_data->type); ?>"/>
<?php echo form_error('type'); ?>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Save" /></td>
</tr>
</table>
</div>
</form>
<br />
<?php echo $link_back; ?>
</div>
Change php code as below
$image1=$this->input->post('thumb');
if (!$this->upload->do_upload($image1)){
if (!$this->upload->do_upload()){
$error = $this->upload->display_errors();
echo "<script>alert($error);</script>";
}else{
$upload_data=$this->upload->data();
$file_name=$upload_data['file_name'];
$full_file_path = $path_to_uploads.'/'.$file_name;
$thumbnail_row = array(
'id_path' => $full_file_path,
'id_data_row' => $id
);
$this->crud_model->save_thumbnail($thumbnail_row);
}
My guess is the upload is failing, since you're trying to do the save regardless of the upload failing the value for full_file_path is going to be empty. By the way save ONLY the file name and put the path in your display code. Saving the path makes it a huge headache to move those files to another location

Categories