How to add multyply record to database - php

I don't know how to add a double record to db.
I have form with double same row content.
I would like to add a dynamic line in the next step using js but at this point I used double html to validate it.
<form class="formAddCoupon" action="/?dashboard=coupon" method="post">
<div class="windowEvents">
<div class="row">
<input type="text" class="teamInput" name="team1">
<input type="text" class="teamInput" name="team2">
<select name="score" id="selectOptions">
<option value="Liczba bramek">Liczba bramek</option>
<option value="Liczba rzutów rożnych">
Liczba rzutów rożnych</option>
<option value="Ilość kartek">Liczba kartek</option>
<option value="Wygrana drużyny">Wygrana drużyny</option>
<option value="Wygrana drużyny lub połowy">
Wygrana drużyny lub połowy</option>
<option value="Wygrana połowy">Wygrana jednej z połów</option>
<option value="Hendicap">Hendicap</option>
<option value="Ilość punktów">Liczba punktów</option>
</select>
<input type="text" class="scoreInput" name="type_score">
</div>
<div class="row">
<input type="text" class="teamInput" name="team1">
<input type="text" class="teamInput" name="team2">
<select name="score" id="selectOptions">
<option value="Liczba bramek">Liczba bramek</option>
<option value="Liczba rzutów rożnych">
Liczba rzutów rożnych</option>
<option value="Ilość kartek">Liczba kartek</option>
<option value="Wygrana drużyny">Wygrana drużyny</option>
<option value="Wygrana drużyny lub połowy">
Wygrana drużyny lub połowy</option>
<option value="Wygrana połowy">Wygrana jednej z połów</option>
<option value="Hendicap">Hendicap</option>
<option value="Ilość punktów">Liczba punktów</option>
</select>
<input type="text" class="scoreInput" name="type_score">
</div>
</div>
<div class="valueAmountRow">
<input
type="number"
name="bid_amount"
id="bid_amount"
placeholder="Stawka"
min="0"
step="any"
>
<input
type="number"
name="winner_amount"
id="winner_amount"
placeholder="Wygrana"
min="0"
step="any"
>
<input type="submit" value="Dodaj">
</div>
</form>
Controller.php:
$data = $this->getRequestPost();
If(!empty($data)) {
$couponData = [
'bid_amount' => $data['bid_amount'],
'winner_amount' => $data['winner_amount'],
'team1' => $data['team1'],
'team2' => $data['team2'],
'score' => $data['score'],
'type_score' => $data['type_score'],
];
$this->db->createCoupon($couponData);
}
Database.php
public function createCoupon(array $data)
{
try {
$this->createNewCoupon($data);
} catch(Throwable $e) {
dump($e);
throw new StorageException('Nie udało się wysłać kuponu', 400, $e);
}
}
private function createNewCoupon($data): void
{
$nr_coupon = trim($this->connection->quote($this->checkIssetCode()));
$created = $this->connection->quote(date('Y-m-d H:i:s'));
$bid_amount = trim($this->connection->quote($data['bid_amount']));
$winner_amount = trim($this->connection->quote($data['winner_amount']));
$team1 = trim($this->connection->quote($data['team1']));
$team2 = trim($this->connection->quote($data['team2']));
$score = trim($this->connection->quote($data['score']));
$typeScore = trim($this->connection->quote($data['type_score']));
$insertNumberCoupon = "INSERT INTO
coupon_number(
nr_coupon,
created,
bid_amount,
winner_amount
)
VALUES(
$nr_coupon,
$created,
$bid_amount,
$winner_amount
)";
$sql_create_number_coupon = $this->connection->prepare($insertNumberCoupon);
if($sql_create_number_coupon)
{
$sql_create_number_coupon->execute();
$id = (int) $this->connection->lastInsertId();
$addEvent = "INSERT INTO
events_at_coupon(
number_id_coupon,
team1,
team2,
score,
type_score
)
VALUES($id,$team1,$team2,$score,$typeScore)";
$sql_add_event_to_table = $this->connection->prepare($addEvent);
if($sql_add_event_to_table)
{
$sql_add_event_to_table->execute();
}
}
}
When i send a form only one record is added to database.
I know why, but what do i have to do to get a double record ?

Related

PHP: How to carry over session variables between 3 pages?

So as of now, i can successfully get the results to move from page one to page two using post and get, but no matter what im doing it will not move the info to the 3rd page. Im trying to switch it over to sessions after reading its made exactly for this but for some reason im doing something wrong and after hours of searching i cant for the life of me figure out what it is. I've followed guides, followed videos, and other post related to the topic on this website. I have now come to the conclusion that it is just me and i need some assistance. Any help would be greatly appreciated.
Page 1 (Index Page | Input Your Variables):
<?php session_start();
$_GET['q'] = $q;
$_GET['s'] = $s;
?>
<form action="search.php" method="get">
<input name="q" maxlength="8" type="text" placeholder="License Plate" id="textbox" required />
<select name="s" id="s" required aria-required="true">
<option value="" disabled selected>CHOOSE STATE</option>
<option value="AL">ALABAMA</option>
<option value="AK">ALASKA</option>
<option value="AZ">ARIZONA</option>
<option value="AR">ARKANSAS</option>
<option value="CA">CALIFORNIA</option>
<option value="CO">COLORADO</option>
<option value="CT">CONNECTICUT</option>
etc...
</select>
<input type="submit" value="SEARCH" id="submitbtn"></form>
Page 2 (Search.php that will take you directly to page specified if its already been created):
<?php session_start();
$q = $_POST['q'];
$s = $_POST['s'];
?>
<?php
$dir = 'states';
$s = (isset($_GET['s']))? strtolower($_POST['s']) : '';
$q = (isset($_GET['q']))? strtoupper($_POST['q']) : '';
$res = opendir($dir);
while(false!== ($file = readdir($res))) {
if(strpos(strtoupper($file),$q)!== false &&!in_array($file)) {
echo "<a href='$dir/$s/$q.htm'>$file</a>";
}
}
closedir($res);
?>
<?php
echo $htmlHeader;
while($stuff){
echo $stuff;
}
echo "<script>window.location =
'http://www.somesite.com/$dir/$s/$q.htm'</script>";
?>
Page 3 (404 page for catch all that are not in the system):
<?php session_start();
?>
<form action="" method="" name="FormChoice">
<input name="q" maxlength="8" type="text" value="<?php echo $_POST['q']; ?>" id="q" required>
<select name="s" id="s" required aria-required="true">
<option value="" disabled>CHOOSE STATE</option>
<option value="AL" <?php if($_POST['s'] == al) {echo ' selected="selected"';} ?>>ALABAMA</option>
<option value="AK" <?php if($_POST['s'] == ak) {echo ' selected="selected"';} ?>>ALASKA</option>
<option value="AZ" <?php if($_POST['s'] == az) {echo ' selected="selected"';} ?>>ARIZONA</option>
<option value="AR" <?php if($_POST['s'] == ar) {echo ' selected="selected"';} ?>>ARKANSAS</option>
<option value="CA" <?php if($_POST['s'] == ca) {echo ' selected="selected"';} ?>>CALIFORNIA</option>
<option value="CO" <?php if($_POST['s'] == co) {echo ' selected="selected"';} ?>>COLORADO</option>
<option value="CT" <?php if($_POST['s'] == ct) {echo ' selected="selected"';} ?>>CONNECTICUT</option>
</select>
<input type="submit" id="submitbtn2" value="SEARCH" name="submit" OnClick="search()" />
<span id="or">OR</span>
<input type="submit" id="addbtn" value="ADD" name="submit" OnClick="add()" />
</form>
page1
<?php
session_start();
// next 2 lines do NOTHING remove them
// as you have not yet loaded any values into $q and $s
//$_GET['q'] = $q;
//$_GET['s'] = $s;
?>
<form action="search.php" method="get">
<input name="q" maxlength="8" type="text" placeholder="License Plate" id="textbox" required />
<select name="s" id="s" required aria-required="true">
<option value="" disabled selected>CHOOSE STATE</option>
<option value="AL">ALABAMA</option>
<option value="AK">ALASKA</option>
<option value="AZ">ARIZONA</option>
<option value="AR">ARKANSAS</option>
<option value="CA">CALIFORNIA</option>
<option value="CO">COLORADO</option>
<option value="CT">CONNECTICUT</option>
etc...
</select>
<input type="submit" value="SEARCH" id="submitbtn"></form>
Page 2 - Search - receives data from previous form
- Contains lots of unecessary <?php...?>
- Previous form uses method="get" so data will arrive in the $_GET array not the $_POST array
<?php
session_start();
//$q = $_POST['q'];
//$s = $_POST['s'];
// But this is silly as you have not yet tested these values exist
// but you do that in the next lines
//$q = $_GET['q'];
//$s = $_GET['s'];
$dir = 'states';
$s = (isset($_GET['s']))? strtolower($_POST['s']) : '';
$q = (isset($_GET['q']))? strtoupper($_POST['q']) : '';
$res = opendir($dir);
// Now if you want to pass the values of `q` and `s` on to the next form
// they now need to be added to the session
$_SESSION['q'] = $q;
$_SESSION['s'] = $s;
while(false!== ($file = readdir($res))) {
if(strpos(strtoupper($file),$q)!== false &&!in_array($file)) {
echo "<a href='$dir/$s/$q.htm'>$file</a>";
}
}
closedir($res);
echo $htmlHeader;
while($stuff){
echo $stuff;
}
echo "<script>
window.location = 'http://www.somesite.com/$dir/$s/$q.htm';
</script>";
// added missing semi colon ^
?>
Page 3 (404 page for catch all that are not in the system):
Now the data will be available in the SESSION, when you get to this page.

Codeigniter 3: Insert array form to database

I'm new with Codeigniter and I'm having some trouble inserting arrays into my database. An error kept popping out that I can't insert array to my database.
Here's my HTML form:
<?= form_open('profile/profile_submit'); ?>
<table class="table table-hover table-striped table-responsive">
<thead>
<tr>
<th id="headCheckHide"></th>
<th><center>Name</center></th>
<th><center>Date of Birth</center></th>
<th><center>Occupation</center></th>
<th><center>Educ. attainment</center></th>
</tr>
</thead>
<tbody id="sibTable">
<tr class="product-item">
<td>
<input type="text" class="form-control form-input" name="siblingName[]">
</td>
<td>
<input type="text" class="form-control form-input" name="siblingBirthDate[]">
</td>
<td>
<input type="text" class="form-control form-input" name="siblingOccupation[]">
</td>
<td>
<select class="form-control form-input" name="siblingEducAttainment[]" >
<option value="" selected>-Please select-</option>
<option value="less than high school">less than high school</option>
<option value="Some college but no degree">Some college but no degree</option>
<option value="Associates Degree">Associates Degree</option>
<option value="Elementary Graduate">Elementary Graduate</option>
<option value="Secondary Graduate">Secondary Graduate</option>
<option value="College Graduate">College Graduate</option>
<option value="Master's Degree">Master's Degree</option>
<option value="Professional Degree">Professional Degree</option>
<option value="Doctorate Degree">Doctorate Degree</option>
</select>
</td>
</tr>
</tbody>
</table>
<?= form_submit('submit','Save', 'class="btn btn-outline-primary waves-effect"');?>
<?php echo form_close();?>
My Controller for the form
public function profile_submit(){
$siblings=array(
'name' => $this->input->post('siblingName'),
'birthDate' => $this->input->post('siblingBirthDate'),
'occupation' => $this->input->post('siblingOccupation'),
'educAttainment' => $this->input->post('siblingEducAttainment')
);
$this->profile_model->submit_profile($siblings);
redirect('profile','refresh'); //name of the html file
}
My model for (profile_model.php)
function submit_profile($siblings){
$this->db->insert('tbl_st_profile_sibling',$siblings);
}
this is my model with the error: can't insert array into database.
Can anyone please help? thank you.
I think you need to insert multiple input data at a time with the same name, don't worry please follow my instructions as given below
Changes in Controller:
public function profile_submit(){
$submit_status = $this->profile_model->submit_profile();
if( $submit_status == "TRUE"){
redirect('profile','refresh'); //name of the html file
}else{
// Do Something else..
}
}
Changes in Model:
function submit_profile(){
$siblingsCount = count($this->input->post('siblingName'));
if($siblingsCount != null){
$itemValues=0;
$query = "INSERT INTO tbl_st_profile_sibling(name,birthDate,occupation,educAttainment) VALUES ";
$queryValue = "";
for($i=0;$i<$siblingsCount;$i++) {
$name = $this->input->post('name');
$birthDate = $this->input->post('birthDate');
$occupation = $this->input->post('occupation');
$educAttainment = $this->input->post('educAttainment');
if(!empty($name[$i])) {
$itemValues++;
if($queryValue!="") {
$queryValue .= ",";
}
$queryValue .= "('" . $name[$i] . "', '" . $birthDate[$i] . "', '" . $occupation[$i] . "', '" . $educAttainment[$i] . "')";
}
}
$sql = $query.$queryValue;
if($itemValues!=0) {
if (!$this->db->query($sql)) {
echo "FALSE";
}else {
echo "TRUE";
}
}
}
}
I hope this may help you...Thanks!
If you need to store array data into DB you need to use loops to insert one.
function submit_profile($siblings){
foreach($siblings['name'] as $key => $siblingName) {
$dataToSave = array(
'name' => $siblingName,
'birthDate' => $siblings['siblingBirthDate'][$key],
'occupation' => $siblings['siblingOccupation'][$key],
'educAttainment' => $siblings['siblingEducAttainment'][$key]
);
$this->db->insert('tbl_st_profile_sibling', $dataToSave);
}
}
UPDATE : Even you can use insert_batch to skip insertion in loop
function submit_profile($siblings){
foreach($siblings['name'] as $key => $siblingName) {
$dataToSave[] = array(
'name' => $siblingName,
'birthDate' => $siblings['siblingBirthDate'][$key],
'occupation' => $siblings['siblingOccupation'][$key],
'educAttainment' => $siblings['siblingEducAttainment'][$key]
);
}
$this->db->insert_batch('tbl_st_profile_sibling', $dataToSave);
}
The issue is not with the array you are saving into database the actual issue is with the post fields thy are in array format siblingName[]. So you need to convert then into strings so that this can be saved easily.
convert the array into coma separated list and then save in database.
$siblingName = implode(",",$_POST['siblingName']);
$siblingBirthDate= implode(",",$_POST['siblingBirthDate']);
$siblingOccupation= implode(",",$_POST['siblingOccupation']);
$siblingEducAttainment= implode(",",$_POST['siblingEducAttainment']);
$siblings=array(
'name' => $siblingName,
'birthDate' => $siblingBirthDate,
'occupation' => $siblingOccupation,
'educAttainment' => $siblingEducAttainment
);
<input type="hidden" name="count" value="<?php echo count($var); ?>" />
for($i=0;$i < count($var);$i++)
{
<tr class="product-item">
<td>
<input type="text" class="form-control form-input" name="siblingName<?php echo $i; ?>">
</td>
<td>
<input type="text" class="form-control form-input" name="siblingBirthDate<?php echo $i; ?>">
</td>
<td>
<input type="text" class="form-control form-input" name="siblingOccupation<?php echo $i; ?>">
</td>
<td>
<select class="form-control form-input" name="siblingEducAttainment<?php echo $i; ?>" >
<option value="" selected>-Please select-</option>
<option value="less than high school">less than high school</option>
<option value="Some college but no degree">Some college but no degree</option>
<option value="Associates Degree">Associates Degree</option>
<option value="Elementary Graduate">Elementary Graduate</option>
<option value="Secondary Graduate">Secondary Graduate</option>
<option value="College Graduate">College Graduate</option>
<option value="Master's Degree">Master's Degree</option>
<option value="Professional Degree">Professional Degree</option>
<option value="Doctorate Degree">Doctorate Degree</option>
</select>
</td>
</tr>
}
$count = $this->input->post('count');
for($i=0;$i < $count;$i++)
{
$siblings=array(
'name' => $this->input->post('siblingName'.$i),
'birthDate' => $this->input->post('siblingBirthDate'.$i),
'occupation' => $this->input->post('siblingOccupation'.$i),
'educAttainment' => $this->input->post('siblingEducAttainment'.$i)
);
$this->profile_model->submit_profile($siblings);
}

Regarding PHP form

I am working on my project I want to store my multiple selected option value in the database but when I select more than one option at one time that time my only last selected values stored in DB please help my where am I am wrong?
Here is my Code:
<?php
require_once('contact_fun.php');
require_once('contact_banner_fun.php');
$obj = new contact_banner();
$crud = new contact_us();
$banner = $obj->get_data_banner();
if(!$banner){
echo "No Banner";
exit;}
$path = 'http://localhost/THE_VELVET_WALK/contact/';
$result = $crud->getData("SELECT * FROM tb_contactus");
foreach ($result as $res) {
$id = $res['id'];
$name = $res['name'];
$business = $res['business'];
$email = $res['email'];
$phone = $res['phone'];
$message = $res['message'];
$style = $res['style'];
}
if(isset($_POST['submit']))
{
$name = $crud->escape_string($_POST['name']);
$business = $crud->escape_string($_POST['business']);
$email = $crud->escape_string($_POST['email']);
$phone = $crud->escape_string($_POST['phone']);
$message = $crud->escape_string($_POST['message']);
$style = $crud->escape_string($_POST['style']);
$result = $crud->execute(" INSERT INTO tb_contactus(name, business, email,
phone, message, style, update_dt)VALUES ('$name','$business', '$email',
'$phone', '$message', '$style', now())");
}?>
<form action="" method="POST">
<input id="00N7F000001F2j6" name="name" maxlength="40" type="text"
class="materialize-input">
<input id="company" name="business" maxlength="40" type="text"
class="materialize-input">
<input id="email" name="email" maxlength="40" type="email"
class="materialize-input">
<input id="phone" name="phone" maxlength="40" type="text" maxlength="40"
class="materialize-input">
<select multiple id="00N7F000001F2kO" name="style" multiple="multiple" >
<option name="consulting" name="styling" value=""selected disabled>image
consulting</option>
<option value="1">styling</option>
<option value="2">hair & make-up</option>
<option value="3">designing clothes</option>
<option value="4">wedding makeover</option>
<option value="5">personal shopper</option>
<option value="6">corporate services</option>
</select>
</form>
you have to specify in the name of the select that it will be an array like :
<select multiple id="00N7F000001F2kO" name="style[]" multiple="multiple" >
<option value=""selected disabled>image consulting</option>
<option value="1">styling</option>
<option value="2">hair & make-up</option>
<option value="3">designing clothes</option>
<option value="4">wedding makeover</option>
<option value="5">personal shopper</option>
<option value="6">corporate services</option>
</select>
and then you can implode it if you want a string like this
implode(',',$_POST['style']);
EDIT :
change this
$style = $crud->escape_string($_POST['style']);
to
$style = $crud->escape_string(implode(',',$_POST['style']));
you need to use an array for multiple select options :
<select multiple id="00N7F000001F2kO" name="style[]" multiple="multiple" >
<option name="consulting" name="styling" value=""selected disabled>image
consulting</option>
<option value="1">styling</option>
<option value="2">hair & make-up</option>
<option value="3">designing clothes</option>
<option value="4">wedding makeover</option>
<option value="5">personal shopper</option>
<option value="6">corporate services</option>
</select>
this is how tou get the data into your database :
.php
if(isset($_POST['styling']) && !empty($_POST['styling'])){
$Col1_Array = $_POST['styling'];
print_r($Col1_Array);
foreach($Col1_Array as $selectValue){
//show selected
echo $selectValue."<br>";
}
}

OOP PHP based on select values

I am doing some practicing with OOP in PHP, and am having issues with submitting form data involving subclasses.
What I am trying to do: submit form data based on the type of product it is (generic, tool, or electronic). My concern comes from not being able to submit a form that can differentiate between the different product types.
Here's the Product Class (the base class):
<?php
require_once('connectvars.php');
// Base class!!
class Product {
// Inheritable properties
protected $title;
protected $description;
protected $price;
// Getters
public function getTitle() {
return $this->title;
}
public function getDescription() {
return $this->description;
}
public function getPrice() {
return $this->price;
}
// Setters
public function setTitle($title) {
$this->title = $title;
}
public function setDescription($description) {
$this->description = $description;
}
public function setPrice($price) {
$this->price = $price;
}
public function insertProduct() {
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME);
$query = "INSERT INTO addedProducts VALUES (0,'$this->title', '$this->description', '$this->price', '', '', '')";
mysqli_query($dbc, $query)
or die("Error adding to database");
mysqli_close($dbc);
}
}
?>
Here's a subclass I made called Tools:
<?php
require_once('connectvars.php');
require_once('Product.php');
class Tools extends Product {
// Defined properties specific to Tools class
private $shipper;
private $weight;
// Getters
public function getShipper() {
return $this->shipper;
}
public function getWeight() {
return $this->weight;
}
// Setters
public function setShipper($shipper) {
$this->shipper = $shipper;
}
public function setWeight($weight) {
$this->weight = $weight;
}
public function insertTool() {
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME);
$query = "INSERT INTO addedProducts VALUES (0,'$this->title', '$this->description', '$this->price', '$this->shipper', '$this->weight', '')";
mysqli_query($dbc, $query)
or die("Error adding to database");
mysqli_close($dbc);
}
}
?>
This is where I am running into problems:
<!DOCTYPE html>
<html>
<head>
<title>Product Entry</title>
</head>
<body>
<select name="prodType" id="prodType">
<option value="" selected="selected">Select...</option>
<option value="general">General</option>
<option value="tools">Tools</option>
<option value="electronics">Electronics</option>
</select>
<br/><br/>
<?php
//require_once('connectvars.php');
require_once('Product.php');
require_once('Electronics.php');
require_once('Tools.php');
$product = new Product();
$tool = new Tools();
$electronic = new Electronics();
if (isset($_POST['submit']) && (isset($_POST['prodType']) == 'general')) {
$product_form = false;
$product->setTitle($_POST['title']);
$product->setDescription($_POST['description']);
$product->setPrice($_POST['price']);
$product->insertProduct();
/*$tool->setTitle($_POST['title']);
$tool->setDescription($_POST['description']);
$tool->setPrice($_POST['price']);
$tool->setShipper($_POST['shipper']);
$tool->setWeight($_POST['weight']);
if (!empty($tool->getTitle()) && !empty($tool->getDescription()) && is_numeric($tool->getPrice()) && !empty($tool->getShipper()) && !empty($tool- >getWeight())) {
echo 'Tool submitted <br/>';
//echo 'Go Back';
$tool->insertTool();
}
} else {
$product_form = true;
}
if ($product_form) {
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<label for="title"><strong>Product Title</strong></label>
<br/>
<input type="text" id="title" name="title" value="<?php echo $product->getTitle();?>"/>
<br/><br/>
<label for="description"><strong>Description</strong></label>
<br/>
<input type="text" id="description" name="description" value="<?php echo $product->getDescription();?>"/>
<br/><br/>
<label for="price"><strong>Price</strong></label>
<br/>
<input type="text" id="price" name="price" value="<?php echo $product->getPrice();?>"/>
<br/><br/>
<!--For Tools -->
<label for="shipper"><strong>Shipper Info</strong></label>
<br/>
<select name="shipper" id="shipper">
<option value="none" selected="selected">--</option>
<option value="usps">USPS</option>
<option value="fedex">FedEx</option>
<option value="ups">UPS</option>
</select>
<br/><br/>
<label for="weight"><strong>Weight</strong></label>
<br/>
<input type="text" id="weight" name="weight" value="<?php echo $tool->getWeight();?>"/>
<br/><br/>
<!--For Electronics -->
<label for="recyclable"><strong>Recyclable?</strong></label>
<br/>
<select name="recyclable" id="recyclable">
<option value="none" selected="selected">--</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<br/><br/>
<input type="submit" id="submit" name="submit" value="Submit Product"/>
</form>
<?php
}
?>
</body>
</html>
I'm sure there's a fairly straightforward solution, but I'm no longer thinking about this correctly anymore -_-. Any suggestions?
I would do the following:
Move all of your calculations to the top of the file.
Move your prodType into the form.
I am displaying the form always. In 1 instance it is to edit, in another it is to create. But you will want to add a hidden input for the "product_id"
Like this:
<?php
require_once('Product.php');
require_once('Electronics.php');
require_once('Tools.php');
$product = new Product();
$tool = new Tools();
$electronic = new Electronics();
if (isset($_POST['submit'])){
$prodType = $_POST['prodType'];
if($prodType == 'general') {
$product_form = false;
$product->setTitle($_POST['title']);
$product->setDescription($_POST['description']);
$product->setPrice($_POST['price']);
$product->insertProduct();
} else if($prodType == 'tools') {
} else if ($prodType == 'elecronics') {
} else {
// echo this message in the form.
$msg = 'Invalid product type';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Product Entry</title>
</head>
<body>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<select name="prodType" id="prodType">
<option value="" selected="selected">Select...</option>
<option value="general">General</option>
<option value="tools">Tools</option>
<option value="electronics">Electronics</option>
</select>
<br/><br/>
<label for="title"><strong>Product Title</strong></label>
<br/>
<input type="text" id="title" name="title" value="<?php echo $product->getTitle();?>"/>
<br/><br/>
<label for="description"><strong>Description</strong></label>
<br/>
<input type="text" id="description" name="description" value="<?php echo $product->getDescription();?>"/>
<br/><br/>
<label for="price"><strong>Price</strong></label>
<br/>
<input type="text" id="price" name="price" value="<?php echo $product->getPrice();?>"/>
<br/><br/>
<!--For Tools -->
<label for="shipper"><strong>Shipper Info</strong></label>
<br/>
<select name="shipper" id="shipper">
<option value="none" selected="selected">--</option>
<option value="usps">USPS</option>
<option value="fedex">FedEx</option>
<option value="ups">UPS</option>
</select>
<br/><br/>
<label for="weight"><strong>Weight</strong></label>
<br/>
<input type="text" id="weight" name="weight" value="<?php echo $tool->getWeight();?>"/>
<br/><br/>
<!--For Electronics -->
<label for="recyclable"><strong>Recyclable?</strong></label>
<br/>
<select name="recyclable" id="recyclable">
<option value="none" selected="selected">--</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<br/><br/>
<input type="submit" id="submit" name="submit" value="Submit Product"/>
</form>
</body>
</html>
Note: You should use and learn composer. It is a must have tool to autoload your class files.

returning null value for the array in php

I am trying to get multiple inputs from a dropdown list but its returning a no value. herewith attached is the code:
controller :-
public function mark_error($id = null, $email=null)
{
if($this->userlib->isLoggedIn())
{
if($this->userlib->isAdmin())
{
$seller_error = $this->input->post('seller_error');
if(is_null($seller_error))
{
$seller_error = array();
}
$marked_error_seller = implode(',', $seller_error);
$bank_error = $this->input->post('bank_error');
if(is_null($bank_error))
{
$bank_error = array();
}
$marked_error_bank = implode(',', $bank_error);
$store_error = $this->input->post('store_error');
if(is_null($store_error))
{
$store_error = array();
}
$marked_error_store = implode(',', $store_error);
$id2 = $this->userlib->getId();
$data['admin_data'] = $this->admin_panel_model->admin_data($id2);
$data['marked_error_seller']=$marked_error_seller;
$data['marked_error_store']=$marked_error_store;
$data['marked_error_bank']=$marked_error_bank;
$data['email']=$email;
$this->admin_panel_model->mark_error_seller($id, $marked_error_seller);
$this->admin_panel_model->mark_error_bank($id, $marked_error_bank);
$this->admin_panel_model->mark_error_store($id, $marked_error_store);
$this->load->view('send_mail', $data);
}
else
{
echo "User not Allowed";
}
}
else
{
echo "User not Logged In";
}
}
model:-
public function mark_error_seller($id, $marked_error_seller)
{
$data = array('marked_error_seller'=>$marked_error_seller, 'seller_status'=>2);
$this->db->update($this->seller_table, $data, array('id'=>$id));
$status = array('error_status'=>1, 'admin_check'=>8);
$this->db->update($this->table, $status, array('id'=>$id));
}
public function mark_error_bank($id, $marked_error_bank)
{
$data1 = array('marked_error_bank'=>$marked_error_bank, 'bank_status'=>2);
$this->db->update($this->bank_table, $data1, array('id'=>$id));
$status = array('error_status'=>1, 'admin_check'=>8);
$this->db->update($this->table, $status, array('id'=>$id));
}
public function mark_error_store($id, $marked_error_store)
{
$data2 = array('marked_error_store'=>$marked_error_store, 'store_status'=>2);
$this->db->update($this->store_table, $data2, array('id'=>$id));
$status = array('error_status'=>1, 'admin_check'=>8);
$this->db->update($this->table, $status, array('id'=>$id));
}
view:-
<form action= "<?=site_url('admin_panel/mark_error/'.$id.'/'.$email)?>" method="post" enctype="multipart/form-data">
<div class="box-body">
<label>Seller Details</label>
<select name="seller_error[]" style = "width : 100%;" multiple="multiple" id="travel_lst" placeholder="">
<option value="Business_Name">Business Name</option>
<option value="Business+Address">Business Address</option>
<option value="Mobile">Mobile</option>
<option value="City">City</option>
<option value="State">State</option>
<option value="Pincode">Pincode</option>
<option value="PAN">PAN</option>
<option value="PAN_Proof">PAN Proof</option>
<option value="TAN">TAN</option>
<option value="TIN">TIN</option>
<option value="TIN_Proof">TIN Proof</option>
<option value="STRN">STRN</option>
<option value="STRN_Proof">STRN Proof</option>
<option value="Residence_Address">Residence Address</option>
</select>
<label>Bank Details</label>
<select name="bank_error[]" style = "width : 100%;" multiple="multiple" id="travel_lst" placeholder="">
<option value="Beneficiary Name">Beneficiary Name</option>
<option value="Bank Account Number">Bank Account Number</option>
<option value="IFSC Code">IFSC Code</option>
<option value="MICR Number">MICR Number</option>
<option value="Bank Name">Bank Name</option>
<option value="City">City</option>
<option value="Branch">Branch</option>
<option value="Cancelled Cheque">Cancelled Cheque</option>
<option value="Address Proof">Address Proof</option>
<option value="Type of Address Proof">Type of Address Proof</option>
<option value="Identity Proof">Identity Proof</option>
<option value="Type of Identity Proof">Type of Identity Proof</option>
</select>
<label>Store Details</label>
<select name="store_error[]" style = "width : 100%;" multiple="multiple" id="travel_lst" placeholder="">
<option value="Billboard Image">Billboard Image</option>
<option value="Company Display Name">Company Display Name</option>
<option value="Company Description">Company Description</option>
<option value="Company Logo">Company Logo</option>
<option value="Travel Category">Travel Category</option>
<option value="Travel Sub Category">Travel Sub Category</option>
<option value="Travel Region">Travel Region</option>
</select>
</div>
<!-- /.box-body -->
<div class="box-footer">
<?php endforeach;?>
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</form>
to elaborate,the status is successfully changed in the database but the inputs from the three dropdown list are not being updated,kindly help.
Try this
In Controller
public function mark_error($id = null, $email=null)
{
if($this->userlib->isLoggedIn())
{
if($this->userlib->isAdmin())
{
$seller = $this->input->post('seller_error');
$bank = $this->input->post('bank_error');
$store = $this->input->post('store_error');
if (empty($seller) || empty($bank) || empty($store)) {
echo "Field(s) is(are) Empty";
}
else
{
$id2 = $this->userlib->getId();
if (empty($id2)) {
echo "ID Field is empty";
}
else
{
$this->admin_panel_model->mark_error_seller($id, $seller);
$this->admin_panel_model->mark_error_bank($id, $bank);
$this->admin_panel_model->mark_error_store($id, $store);
$data['admin_data'] = $this->admin_panel_model->admin_data($id2);
$this->load->view('send_mail', $data);
}
}
}
else
{
echo "User not Allowed";
}
}
else
{
echo "User not Logged In";
}
}
In Model
public function mark_error_seller($id, $seller)
{
$data = array(
'marked_error_seller' => $seller,
'seller_status' => '2',
'error_status' => '1',
'admin_check' => '8'
);
$this->db->where('id', $id);
$this->db->update('seller', $data); # I assume tabe name is seller
}
public function mark_error_bank($id, $bank)
{
$data = array(
'marked_error_bank' => $bank,
'bank_status' => '2',
'error_status' => '1',
'admin_check' => '8'
);
$this->db->where('id', $id);
$this->db->update('bank', $data); # I assume tabe name is bank
}
public function mark_error_store($id, $store)
{
$data = array(
'marked_error_store' => $store,
'store_status' => '2',
'error_status' => '1',
'admin_check' => '8'
);
$this->db->where('id', $id);
$this->db->update('store', $data); # I assume tabe name is store
}

Categories