here is the bootstrap that i need to put into the database well im
new to bootstrap and mysql so i have no idea whether im doing it right
or wrong? i need some help badly. btw im making a simple online reservation system
<div class = "panel-group" id = "Accordion">
<div class = "panel panel-info">
<div class = "panel-heading">
<h4 class = "panel-title">
</span> Reserve Now!
</h4>
</div>
<!-- Panel Body -->
<div class ="panel-body">
<div class = "row">
<form class="form-inline" role="form" action ="" method = "post">
<div class="form-group">
<div class="input-group" name = "from">
<div class="input-group-addon">FROM</div>
<select class="form-control input-sm">
<option selected disabled>Select Destination</option>
<option value="BCD">Bacolod</option>
<option value="BSO">Basco(Batanes)</option>
<option value="USU">Busuanga(Coron)</option>
<option value="BXU">Butuan</option>
<option value="CGY">Cagayan de Oro</option>
<option value="CYP">Calbayog</option>
<option value="CRM">Catarman</option>
<option value="BOR">Catician(Boracay)</option>
<option value="CEB">Cebu</option>
<option value="COT">Cotabato</option>
<option value="DVO">Davao</option>
<option value="DPL">Dipolog</option>
<option value="DGT">Dumaguete</option>
<option value="GES">General Santos</option>
<option value="ILO">Iloilo</option>
<option value="JOL">Jolo</option>
<option value="KLO">Kalibo</option>
<option value="LAO">Laoag</option>
<option value="LGP">Legazpi</option>
<option value="MNL">Manila</option>
<option value="MBT">Masbate</option>
<option value="NAG">Naga</option>
<option value="OZC'">Ozamiz</option>
<option value="PPS">Puerto Princesa</option>
<option value="RXS">Roxas</option>
<option value="SUG'">Surigao</option>
<option value="TAC">Tacloban</option>
<option value="TAG">Tagbilaran(Bohol)</option>
<option value="TWT">Tawi Tawi</option>
<option value="TUG">Tuguegarao</option>
<option value="ZAM">Zamboanga</option>
</select>
</div>
</div>
and here is the mysql query that im tweaking right now . im using PDO. what should i do ? i edited this is now my full db.php its from my previous small blog post project.
<?php namespace ars\DB; // Global annoucement of location within the this page
$config = array(
'username' =>'root',
'password' => 'kel',
'database' => 'ars'
); // function can be reusable
//function will be put to class namespace (real world)
function connect($config)
{
try {
$conn = new \PDO('mysql:host=localhost;dbname=' .
$config['database'],
$config['username'],
$config['password']);
$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $conn;
} catch(exception $e ) {
return false;
}
}
//helper function
function query($query, $bindings, $conn)
{
$stmt = $conn->prepare($query);
$stmt->execute($bindings);
return ( $stmt -> rowCount() > 0 ) ? $stmt : false;
}
function get($tableName, $conn)
{ try{
$result = $conn->query("SELECT * FROM $tableName ORDER BY id ");
return( $result -> rowCount() > 0 )
? $result
: false;
}catch(Execption $e){
return false;
}
}
// passing the id
function get_by_id($id, $conn)
{
// querying the id
$query = query(
'SELECT * FROM posts WHERE id = :id LIMIT 1',
array('id' => $id),
$conn
);
if ($query) return $query->fetchAll();
// else
}
there are many errors in this code. i cant help you with your problem but i can just point out some of these errors. first off,
there is no need for order by in insert
your function is get but you are inserting. (can i assume you are supposed to use select? if so, learn more about it. a little google search will save you).
you can help us help you by showing your connect statement. (like
mysqli_connect() function) note:dont use mysql_connect as it is
depreciated.
a note to point out is your
has no name attribute. add a name="some_Select" in your select tag
Related
I'm trying to create a drop down menu and run specific SQL scripts depending to each option value.
Part of the php code is this (I've made labels more easy for you to understand what i want):
<div class="form-group RunningSQLScripts">
<label for="inputStatus">Running My Scripts</label>
<select id="inputStatus" name="RunningSQLScripts" class="form-control">
<option selected disabled>--</option>
<option value="RunScript1">Delete Whole Table</option>
<option value="RunScript2">Run Script 3</option>
</select>
</div>
Lets say the RunScript1 is supposed to run the SQL command
truncate table table_name1. How can i do that from inside php menu ?
The easiest way is to use onclick= and then the name_of_function ();
for example:
<div class="form-group RunningSQLScripts">
<label for="inputStatus">Running My Scripts</label>
<select id="inputStatus" name="RunningSQLScripts" class="form-control">
<option selected disabled>--</option>
<option onclick="RunScript1()">Delete Whole Table</option>
<option onclick="RunScript2()">Run Script 3</option>
</select>
</div>
And then according to the function's name.
Create the appropriate functions to run on click.
You can submit the form to the server and execute the request you need.
<?php
$db = new mysqli('localhost', 'db_user', '1234', 'db_name');
if($db->connect_errno)die('Error: '.$db->connect_error);
?>
<form name="runSQL" method="get">
<div class="form-group RunningSQLScripts">
<label for="inputStatus">Running My Scripts</label>
<select id="inputStatus" name="RunningSQLScripts" class="form-control">
<option selected disabled>--</option>
<option value="RunScript1">Delete Whole Table</option>
<option value="RunScript2">Run Script 3</option>
</select>
<input type="submit" value="Run">
</div>
</form>
<?php
$runSQL = $_GET['RunningSQLScripts'];
switch($runSQL){
case 'RunScript1':
$db->query("truncate table `name`");
echo '* Successfully deleted *';
break;
case 'RunScript2':
$db->query("SQL");
echo '* Successfully run *';
break;
}
?>
Easiest way to do it: fully working,
Just add
onchange='this.form.submit();'
<form id="companyForm" name="companyForm" class="form-horizontal" type=get>
<div class="form-group RunningSQLScripts">
<label for="inputStatus">Running My Scripts</label>
<select id="inputStatus" name="RunningSQLScripts" onchange='this.form.submit();' class="form-control">
<option selected disabled>--</option>
<option value="RunScript1">Delete Whole Table</option>
<option value="RunScript2">Run Script 3</option>
</select>
</div>
</form>
<?php
$RunningSQLScripts = $_GET['RunningSQLScripts'];
$con = mysqli_connect('host','username','password','db');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"db");
if ($RunningSQLScripts == "RunScript1")
{
$sql="truncate TABLE `table_name1`;"; // truncate table table_name1
$result = mysqli_query($con,$sql);
}
mysqli_close($con);
?>
I have a dropdownlist in my view:
<form action="./sort" method="post">
<div class="sort-dropdown">
<select name="sort">
<option value="">Sort</option>
<option value="asc">Ascending</option>
<option value="desc">Descending</option>
</select>
</div>
</form>
I want to get the value when user choose in dropdownlist, in my controller, I tried:
$sort = $request->sort;
But when I choose in dropdownlist and use dd($sort), it return null. How I can get the value? Thank you!
Update:
Here is my full controller:
public function search(Request $request) {
$search = $request->get('search');
$sort = $request->sort;
dd($search, $sort);
die;
$result = $this -> model -> getSearch($search, $sort);
$processData['processData'] = $result;
return view('datatracking', $processData);
}
use this and dd($array_name);
$array_name->sort = $request->sort;
You can get this from array
$request['sort'];
Your form is not getting submitted. To submit the form you need to add javascript .
<form action="./sort" method="post" >
<div class="sort-dropdown">
<select name="sort" onchange="this.form.submit()">
<option value="">Sort</option>
<option value="asc">Ascending</option>
<option value="desc">Descending</option>
</select>
</div>
</form>
You can always take advantage of javascript's onchange. Maybe spice it up with a switch case?
Routes/web.php
Route::post('./sort', 'YourController#show')->name('sort-records');
Blade:
<form action="./sort" method="post">
<!-- pass your csrf token -->
#csrf
<div class="sort-dropdown input-group">
<!-- note the use of the onchange -->
<select name="sort" id="sort" class="form-control" onchange="this.form.submit()">
<option value="">Sort</option>
<option value="asc">Ascending</option>
<option value="desc">Descending</option>
</select>
</div>
</form>
YourController:
public function show(Request $request)
{
switch ($request->sort)
{
case "asc":
// Grab your records accordingly
$variable = $x;
break;
case "desc":
// Grab your records accordingly
$variable = $y;
break;
default:
// Set a default sort option
$variable = $z;
break;
}
return view('datatracking', $variable);
}
<select name="sort" id="sort" class="form-control" >
<option value="Sort">Sort</option>
<option value="asc">Ascending</option>
<option value="desc">Descending</option>
</select>
I need to get database information from table by using where clause from a select options.
My view:
<div>
<select name="noSeats" class="form-control" placeholder="Seats">
<option value="">Seats</option>
<option value="45">45</option>
<option value="49">49</option>
<option value="51">51</option>
<option value="53">53</option>
<option value="56">56</option>
<option value="57">57</option>
<option value="61">61</option>
</select>
</div>
My Model:
public function getSeats($noSeats) {
$query = $this->db->get('seat');
if ($query->num_rows() > 0) {
return $query->result();
}
}
Also I have another problem with listing checkboxes; I need to list checkboxes in row of limit to 4 since I have many chechboxes.
public function getSeats($noSeats){
$query = $this->db->from('seat')->where('seat_col', $noSeats)->get();
if($query->num_rows() > 0){
return $query->result();
}
}
You can use
$query = $this->db->where('COLUMN_NAME', $noSeats )->get('seat');
i'm working on a codeigniter website and i need to use form_multiselect the select shows fine but when i post it and i try to get the selected value on the controller when i do :
$category = $this->input->get_post('category');
var_dump($category);
i get string(0) "".
here is my codes :
View
<?php echo form_multiselect('category[]', $categories); ?>
Controller
$data['categories'] = $this->blog_category_model->getblogcatDropDown($app_key);
$category = $this->input->get_post('category');
var_dump($category);
die;
Model
public function getblogcatDropDown($app_key)
{
$query = $this->db->query('SELECT * FROM `webapp_blog_categories` WHERE `app_key`=('.$this->db->escape($app_key).') ORDER BY `id` ASC')->result();
$return[''] = 'Choose blog category';
foreach ($query as $row) {
$return[$row->id] = $row->cat_name;
}
return $return;
}
update
when i use html select on the view :
<select multiple name="tst[]">
<option value="" disabled selected>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
it works fine , but the generated form not working
can any one help me ? thanks
Make sure the form method="post" and simply check the whether the value is posted when you submit the form using developer tools.
for getting the value in controller. it's simply.
$category = $this->input->post('category');
So I'm trying to get my value from a SELECT tag in HTML, I'm working with the POST method. Somehow when I get my answer back I only get my label, instead of getting my value which is what I need. I manage my form in 3 diferent documents,
here is my php doc, the visual part
<form action="actions_admin/demografica_asig.php" method="POST">
<div class="large-4 columns">
<label>Seleccione Periodo:
<select name="selec_periodo">
<option value="1">I</option>
<option value="2">II</option>
<option value="3">III</option>
<option vslue="4">IV</option>
</select>
</label>
</div>
</form>
my accion docmuent:
<?php
require_once("../../clases/demoasig.class.php");
$selec_periodo = $_POST['selec_periodo'];
$demoasig = new Demografica();
$demoasig->selec_periodo = $selec_periodo;
$resultdatos = $demoasig->demo_asig();
echo $resultdatos;
?>
my Class Document:
<?php
require_once('conexion.class.php');
class Demografica{
public $selec_periodo;
public function __construct(){
$this->asig = array();
}
public function demo_asig(){
$sql= "SELECT COUNT(*) FROM est_asig WHERE est_asig_trimestre={$this->selec_periodo}";
$resultado = mysql_query($sql, Conectar::conexion()) or die($sql);
$this->asig[]= $resultado;
return $this->asig;
}
}
?>