How to insert multiple column in codeigniter? - php

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);
}

Related

PHP - 1 form, 2 tables - Can't insert data into table 1

I'm trying to make an invoice system that adds rows, from a tutorial and data is correctly inserted into tbl_orderdetail, but I can't make it work to insert data to tbl_order.
These are the 2 MYSQL tables:
CREATE TABLE IF NOT EXISTS `tbl_order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`re_name` varchar(255) DEFAULT NULL,
`location` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `tbl_orderdetail` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) DEFAULT NULL,
`product_name` varchar(255) DEFAULT NULL,
`quantity` varchar(255) DEFAULT NULL,
`price` varchar(255) DEFAULT NULL,
`discount` int(11) DEFAULT NULL,
`amount` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=73 ;
And this is my connection code:
<?php
$cn = mysql_connect('localhost','root','');
if($cn)
{
mysql_select_db('mydb',$cn);
}
if(isset($_POST['submit']))
$re_name = $_POST['re_name'];
$location = $_POST['location'];
{
mysql_query ("INSERT INTO tbl_order(re_name,location) VALUES('{$_POST['re_name']}','{$_POST['location']}')");
$id = mysql_insert_id();
for($i = 0 ;$i < count($_POST['productname']);$i++)
{
mysql_query("INSERT INTO tbl_orderdetail
SET order_id = '{$id}',
product_name = '{$_POST['productname'][$i]}',
quantity = '{$_POST['quantity'][$i]}',
price = '{$_POST['price'][$i]}',
discount = '{$_POST['discount'][$i]}',
amount = '{$_POST['amount'][$i]}'
");
}
}
?>
What is wrong in my code?
Here is the form that submits the values:
<form action="" method="post">
<div class="box-body">
<div class="form-group">
ReceptName
<input type="text" name="re_name" id="re_name" class="form-control">
</div>
<div class="form-group">
Location
<input type="text" name="location" id="location" class="form-control">
</div>
<input type="submit" class="btn btn-primary" name="submit" id="submit" value="Save Record">
</div>
<table class="table table-bordered table-hover">
<thead>
<th>No</th>
<th>ProductName</th>
<th>Quantity</th>
<th>Price</th>
<th>Discount</th>
<th>Amount</th>
<th><input type="button" value="+" id="add" class="btn btn-primary"></th>
</thead>
<tbody class="detail">
<tr>
<td class="no">1</td>
<td><input type="text" class="form-control productname" name="productname[]"></td>
<td><input type="text" class="form-control quantity" name="quantity[]"></td>
<td><input type="text" class="form-control price" name="price[]"></td>
<td><input type="text" class="form-control discount" name="discount[]"></td>
<td><input type="text" class="form-control amount" name="amount[]"></td>
<td><a href="#" class="remove">Delete</td>
</tr>
</tbody>
<tfoot>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th style="text-align:center;" class="total">0</th>
</tfoot>
</table>
</div>
</div><!-- /.box -->
</form>
</div><!--/.col (left) -->
Thank you all for helping me.
I dropped tbl_order and created a new one called 'orcamen'.
Here's the php code that worked:
if(isset($_POST['submit']))
{
$razao = $_POST["razao"];
$local = $_POST["local"];
$condicao = $_POST["condicao"];
$estado = $_POST["estado"];
$material = $_POST["material"];
$obs = $_POST["obs"];
mysql_query
("INSERT INTO orcamen ( id , razao , local , condicao , estado , material , obs )
VALUES ( NULL , '$razao', '$local', '$condicao', '$estado', $material', '$obs')");
$id = mysql_insert_id();
for($i = 0 ;$i < count($_POST['productname']);$i++)
{
mysql_query("INSERT INTO tbl_orderdetail
SET order_id = '{$id}',
product_name = '{$_POST['productname'][$i]}',
quantity = '{$_POST['quantity'][$i]}',
price = '{$_POST['price'][$i]}',
discount = '{$_POST['discount'][$i]}',
amount = '{$_POST['amount'][$i]}'
");
}
}

Data is not inserted into the database and trying to add the most relevant category to the product

I am making a CRUD for a simple home application, and for some reason, I am not able to find out what's wrong in the code. My product creation page is not creating a product, because it's not POSTing anything, on my local PHP 5.3.2 Mamp Pro environment, and online in a server it didn't work either. I tried with both the create and update pages, and nothing. As I am really NEW to OOP and rusty in PHP and mysql, I am posting the code so you can tell me what can be wrong with it.
--
-- Table structure for table `products1`
--
CREATE TABLE IF NOT EXISTS `products1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
`description` text NOT NULL,
`price` int(11) NOT NULL,
`category_id` int(11) NOT NULL,
`created` datetime NOT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;
--
-- Table structure for table `menu`
--
CREATE TABLE IF NOT EXISTS `menu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 NOT NULL,
`parent_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=136 ;
<?php
echo "<div class='right-button-margin'>";
echo "<a href='test.php' class='btn btn-default pull-right'>Ver Todos los Productos</a>";
echo "</div>";
?>
<?php
// get database connection
include_once 'config/database.php';
$database = new Database();
$db = $database->getConnection();
// if the form was submitted
if($_POST){
// instantiate product object
include_once 'objects/product.php';
$product = new Product($db);
// set product property values
$product->name = $_POST['name'];
$product->price = $_POST['price'];
$product->description = $_POST['description'];
$product->category_id = $_POST['category_id'];
// create the product
if($product->create()){
echo "<div class=\"alert alert-success alert-dismissable\">";
echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>";
echo "Creamos el producto!";
echo "</div>";
}
// if unable to create the product, tell the user
else{
echo "<div class=\"alert alert-danger alert-dismissable\">";
echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>";
echo "No pude crear el producto!";
echo "</div>";
}
}
?>
<!-- HTML form for creating a product -->
<form action='create_product.php' method='post'>
<table class='table table-hover table-responsive table-bordered'>
<tr>
<td>Nombre</td>
<td><input type='text' name='name' class='form-control' required></td>
</tr>
<tr>
<td>Costo</td>
<td><input type='text' name='price' class='form-control' required></td>
</tr>
<tr>
<td>Descripción</td>
<td><textarea name='description' class='form-control'></textarea></td>
</tr>
<tr>
<td>Categoría</td>
<td>
<?php
// Test connection and list
try {
$objDb = new PDO('mysql:host=111.111.111.111;dbname=nat', 'nat', '123');
$objDb->exec('SET CHARACTER SET utf8');
$sql = "SELECT *
FROM `menu`
WHERE `parent_id` = 0";
$statement = $objDb->query($sql);
$list = $statement->fetchAll(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
echo 'There was a problem';
}
// end
// read the product categories from the database
include_once 'objects/category.php';
$category = new Category($db);
// $stmt = $category->read();
// put them in a select drop-down DISABLED not working
/* echo '<select class="update" name="category" id="category">';
echo "<option>Seleccioná la categoría...</option>";
while ($row_category = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row_category);
echo "<option value='{$id}'>{$name}</option>";
}
echo "</select>";*/
?>
<select name="category" id="category" class="form-control update">
<option value="">Seleccionar Categoría</option>
<?php if (!empty($list)) { ?>
<?php foreach($list as $row) { ?>
<option value="<?php echo $row['id']; ?>">
<?php echo $row['name']; ?>
</option>
<?php } ?>
<?php } ?>
</select>
<select name="level1" id="level1" class="form-control update"
disabled="disabled">
<option value="">----</option>
</select>
<select name="level2" id="level2" class="form-control update"
disabled="disabled">
<option value="">----</option>
</select>
<select name="level3" id="level3" class="form-control update"
disabled="disabled">
<option value="">----</option>
</select>
<select name="level4" id="level4" class="form-control update"
disabled="disabled">
<option value="">----</option>
</select>
<select name="level5" id="level5" class="form-control update"
disabled="disabled">
<option value="">----</option>
</select>
<select name="level6" id="level6" class="form-control update"
disabled="disabled">
<option value="">----</option>
</select>
</td>
</tr>
</td>
</tr>
<tr>
<td></td>
<td>
<button type="submit" class="btn btn-primary">Crear</button>
</td>
</tr>
</table>
Besides this I want to know what is the lowest most relevant subcategory is passed to the POST, so the product is assigned to it.

how to add images to mysql database when a user submit their images

I want to add multiple images into mysql database using a form. Whenever a user submits that form then it captures all data and stores that into mysql database. (it is right way, but i need)
My database table is looking like this.
CREATE TABLE `Owner_detail` (
`id` int(10) NOT NULL auto_increment,
`fullname` varchar(30) NOT NULL,
`List1` varchar(20) NOT NULL,
`List2` varchar(20) NOT NULL,
`List3` varchar(20) NOT NULL,
`area` varchar(30) NOT NULL,
`ownermobile` varchar(20) NOT NULL,
`email` varchar(20) NOT NULL,
`image_one` blob NOT NULL,
`image_two` blob NOT NULL,
`image_three` blob NOT NULL,
`otherdetail` varchar(300) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=49 ;
My html form is looking like this.
<table width="60%"><form action="process.php" method="post" enctype="multipart/form-data" name="tripleplay" onsubmit="MM_validateForm('fullname','','R','area','','R','ownermobile','','RisNum','email','','RisEmail','otherdetail','','R');return document.MM_returnValue">
<tr>
<td width="44%">Full Name : </td>
<td width="56%"><input size="25" type="text" name="fullname" id="fullname" /></td>
</tr>
<tr>
<td valign="top">Rental Type:</td>
<td>
<select name='List1' id="List1" onchange="fillSelect(this.value,this.form['List2'])">
<option selected>Make a Selection</option>
</select>
<br /><br />
<select name='List2' id="List2" onchange="fillSelect(this.value,this.form['List3'])">
<option selected>Make a Selection</option>
</select><br /><br />
<select name='List3' id="List3" onchange="getValue(this.value, this.form['List2'].value,
this.form['List1'].value)">
<option selected>Make a Selection</option>
</select>
</td>
</tr>
<tr>
<td>Area : </td>
<td><input size="25" type="text" name="area" id="area" />
sq.ft.</td>
</tr>
<tr>
<td>Owner Mobile / Landline</td>
<td><input size="25" type="text" name="ownermobile" id="ownermobile" /></td>
</tr>
<tr>
<td><p>E-mail</p></td>
<td><input size="25" type="text" name="email" id="email" /></td>
</tr>
<tr>
<td valign="top">Pictures of Property</td>
<td>
<input type="file" name="image_one" id="image_one" />
<input type="file" name="image_two" id="image_two" />
<input type="file" name="image_three" id="image_three" />
</td>
</tr>
<tr>
<td valign="top">Other details you would like to share about your property:</td>
<td><textarea size="25" name="otherdetail" id="otherdetail" cols="45" rows="5"> </textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</form>
</table>
and my processing form in php is looking like this
<?
if( $_POST )
{
$con = mysql_connect("","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("vkrental", $con);
$users_fullname = $_POST['fullname'];
$users_area = $_POST['area'];
$users_List1 = $_POST['List1'];
$users_List2 = $_POST['List2'];
$users_List3 = $_POST['List3'];
$users_ownermobile = $_POST['ownermobile'];
$users_email = $_POST['email'];
$users_image_one = $_POST['image_one'];
$users_image_two = $_POST['image_two'];
$users_image_three = $_POST['image_three'];
$users_otherdetail = $_POST['otherdetail'];
$users_fullname = htmlspecialchars($users_fullname);
$users_area = htmlspecialchars($users_area);
$users_List1 = htmlspecialchars($users_List1);
$users_List2 = htmlspecialchars($users_List2);
$users_List3 = htmlspecialchars($users_List3);
$users_ownermobile = htmlspecialchars($users_ownermobile);
$users_email = htmlspecialchars($users_email);
$users_image_one = htmlspecialchars($users_image_one);
$users_image_two = htmlspecialchars($users_image_two);
$users_image_three = htmlspecialchars($users_image_three);
$users_otherdetail = htmlspecialchars($users_otherdetail);
$query = "
INSERT INTO `vkrental`.`Owner_detail` (
`fullname` ,
`area` ,
`List1` ,
`List2` ,
`List3` ,
`ownermobile` ,
`email` ,
`image_one` ,
`image_two` ,
`image_three` ,
`otherdetail`
)
VALUES ( '$users_fullname',
'$users_area', '$users_List1','$users_List2','$users_List3', '$users_ownermobile', '$users_email', '$users_image_one','$users_image_two','$users_image_three', '$users_otherdetail'
);";
mysql_query($query);
echo "<h2>Success.</h2>";
mysql_close($con);
}
?>
My Problem is when ever I am inserting images from mysql database it stores successfully.
but when i am doing that from my html form it is not storing images. it is storing only data(text).
I don't know what is the actual error in my forms.
I wonder what using htmlspecialchars() for binary data would do.
$users_image_one = htmlspecialchars($users_image_one);
$users_image_two = htmlspecialchars($users_image_two);
[Edit:]
htmlspecialchars() is used to preserve special characters of text data. However, if you use it for binary data, it would mess up everything.
Troubleshoot them yourself:
You can try to find out the problem by first just uploading only the images.
Also have a look at this link : File upload using POST method
Does not sound like there is an error . . . .
You don't store the actual images in your database, but rather just their name, or a reference to the images
e.g. product_one.jpg
Then when you want to display it you would do something like
<img src=" <?php $echo \images\$users_image_one ?> ">

Onclick radio buttons run its respective mysql query and display it in a table

I've been searching a whole day for this code but no luck, I came across a code while googling obvious it was not working, so I edited it in my own way , but still I had no luck in getting it to actually work, So please guys I would be very happy if someone helps me with this code.
What I want is when I select a radio button and hit enter the next page I see should display my database data according to the radio button.. ITS LIKE A DATABASE FILTER which filter outs my database data..
So first of all here's the first page..... FILTERPAGE.HTML
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>FILTER PAGE</title>
</head>
<body>
<form action="search.php" method="post" name="filter_option">
<table width="100%" border="0">
<tr>
<td>
<label>
<input name="filter_options" type="radio" id="filter_options_0" value="default_filter" checked>
Default</label>
</td>
<td><label>
<input type="radio" name="filter_options" value="special_id_filter" id="filter_options_1">
Special ID</label></td>
<td><label>
<input type="radio" name="filter_options" value="company_name_filter" id="filter_options_2">
Company Name</label></td>
<td><label>
<input type="radio" name="filter_options" value="brand_name_filter" id="filter_options_3">
Brand Name</label></td>
<td><label>
<input type="radio" name="filter_options" value="model_id_filter" id="filter_options_4">
Model ID</label></td>
<td><label>
<input type="radio" name="filter_options" value="colour_filter" id="filter_options_5">
Colour</label></td>
<td><label>
<input type="radio" name="filter_options" value="size_filter" id="filter_options_6">
Size</label></td>
<td><label>
<input type="radio" name="filter_options" value="frame_type_filter" id="filter_options_7">
Frame Type</label></td>
<td><label>
<input type="radio" name="filter_options" value="frame_for_filter" id="filter_options_8">
Frame For</label></td>
<td><label>
<input type="radio" name="filter_options" value="quantity_filter" id="filter_options_9">
Quantity</label></td>
<td><label>
<input type="radio" name="filter_options" value="price_filter" id="filter_options_10">
Price</label></td>
</tr>
</table>
<input name="submit" type="submit">
</form>
</body>
</html>
And Now here's the Second One which is the PHP Stuff.......... SEARCH.PHP
<?php
mysql_connect("localhost","root","password") or die(mysql_error());
mysql_select_db("stock_entry") or die(mysql_error());
$filteroption= $_POST['filter_options'];
//To use different queries while searching
if ($filteroption == 'default_filter')
{
$queres = "SELECT * FROM stock_entry_spectacles ORDER BY 'id'";
}
else if ($filteroption == 'special_id_filter')
{
$queres = "SELECT * FROM stock_entry_spectacles ORDER BY 'special_id'";
}
else if ($filteroption == 'company_name_filter')
{
$queres = "SELECT * FROM stock_entry_spectacles ORDER BY 'company_name'";
}
else if ($filteroption == 'brand_name_filter')
{
$queres = "SELECT * FROM stock_entry_spectacles ORDER BY 'brand_name'";
}
else if ($filteroption == 'model_id_filter')
{
$queres = "SELECT * FROM stock_entry_spectacles ORDER BY 'model_id'";
}
$query = $queres;
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)){
echo "<table class='data' border='0' cellspacing='2' align='center'>
<tr>
<td align='center' class='special_id'><input type='text' name='id' value='".$row['special_id']."'></td>
<td align='center' class='company_nametd'><input type='text' name='company_name' value='".$row['company_name']."'></td>
<td align='center' class='brand_namestd'> <input type='text' name='brand_name' value='".$row['brand_name']."'></td>
<td align='center' class='model_idtd'> <input type='text' name='model_id' value='".$row['model_id']."'></td>
<td align='center' class='colour_selecttd'> <input type='text' name='colour_select' value='".$row['colour_select']."'></td>
<td align='center' class='size_selecttd'> <input type='text' name='size_select' value='".$row['size_select']."'></td>
<td align='center' class='type_selecttd'><input type='text' name='type_select' value='".$row['type_select']."'></td>
<td align='center' class='for_selecttd'> <input type='text' name='for_select' value='".$row['for_select']."'></td>
<td align='center' class='quantitytd'> <input type='text' name='quantity' value='".$row['quantity']."'></td>
<td align='center' class='pricetd'> <input type='text' name='price' value='".$row['price']."'></td>
<tr>
</table>";
}
?>
And the Last but not the least the Mysql Structure......
Database Name: stock_entry
Table structure for table stock_entry_spectacles
CREATE TABLE IF NOT EXISTS `stock_entry_spectacles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`special_id` int(225) DEFAULT NULL,
`company_name` text COLLATE utf8_unicode_ci,
`brand_name` text COLLATE utf8_unicode_ci,
`model_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_polish_ci DEFAULT NULL,
`colour_select` text COLLATE utf8_unicode_ci,
`size_select` int(11) DEFAULT NULL,
`type_select` text COLLATE utf8_unicode_ci,
`for_select` text COLLATE utf8_unicode_ci,
`quantity` int(11) DEFAULT NULL,
`price` int(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
Dumping data for table stock_entry_spectacles
INSERT INTO `stock_entry_spectacles` (`id`, `special_id`, `company_name`, `brand_name`, `model_id`, `colour_select`, `size_select`, `type_select`, `for_select`, `quantity`, `price`) VALUES
(1, NULL, 'Titan', 'abc', '123', 'GunMetal', 50, 'Metal', 'Male', 2, NULL),
(2, NULL, 'AO Specs', 'def', '456', 'Black', 48, 'Metal', 'Male', 6, 500),
(3, NULL, 'Sinora', 'ghi', '789', 'Blue', 13, 'broad sided', 'Female', 3, 460),
(4, NULL, 'Tommy', 'jkl', '963', 'GunMetal', 40, 'Shell', 'Male', 8, 800),
(5, 14873273, 'Manav', 'mno', '852', 'Black', 50, 'Metal', 'Male', 5, 120);
Please anyone try to help me as I needed this code for one of my projects....
Replace
mysql_connect("localhost","root","password") or die(mysql_error());
With
mysql_connect("localhost","root","") or die(mysql_error());

input multiple value to one row in codeigniter

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

Categories