Codeigniter: post is not working in form - php

I am uploading images to "images" directory and some info to my database in codeigniter. But when I click to submit button after completing form, It posts nothing. It gives error that there is not posted any input(not the same as error message just meaning). If someone could please look over this code, and tell me why it's not working. Thank you in advance. Here my controller code:
<?php
public function create()
{
// image1
$ImageName = $_FILES['image']['name'];
$imageSize= $_FILES['image']['size'];
$imageSource = $_FILES['image']['tmp_name'];
move_uploaded_file($_FILES['image']['tmp_name'], "images/$ImageName");
$this->create_thumb($ImageName);
$this->compress($ImageName, $imageSize, "images/$ImageName");
// image2
if ($this->input->post('image2'))
{
$ImageName2 = $_FILES['image2']['name'];
$imageSize2= $_FILES['image2']['size'];
$imageSource2 = $_FILES['image2']['tmp_name'];
$this->compress($ImageName2, $imageSize2, $imageSource2);
}
// image3
if ($this->input->post('image3'))
{
$ImageName3 = $_FILES['image3']['name'];
$imageSize3= $_FILES['image3']['size'];
$imageSource3 = $_FILES['image3']['tmp_name'];
$this->compress($ImageName3, $imageSize3, $imageSource3);
}
// image4
if ($this->input->post('image4'))
{
$ImageName4 = $_FILES['image4']['name'];
$imageSize4= $_FILES['image4']['size'];
$imageSource4 = $_FILES['image4']['tmp_name'];
$this->compress($ImageName4, $imageSize4, $imageSource4);
}
$this->news_model->set_news();
$this->load->view('News/success');
}
?>
Here my view code:
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="content">
<form action="<?php echo base_url();?>index.php/news/create/" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label>Сарлавха:</label>
<input type="text" name="title" class="form-control" placeholder="Сарлавха">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Автомобил тури:</label>
<select name="category" class="form-control">
<option value="yuk">Юк</option>
<option value="kichik">Кичик тижорат</option>
<option value="yengil">Енгил</option>
<option value="maxsus">Махсус техника</option>
<option value="tyagach">Тягач</option>
<option value="prisep">Прицеп</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Нархи:</label>
<input type="number" name="price" class="form-control" placeholder="Нархи">
</div>
</div>
<div class="col-md-8">
<div class="form-group">
<label>Исми ва шарифи:</label>
<input type="text" name="name" class="form-control" placeholder="Исми ва шарифи">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Телефон рақам:</label>
<input type="text" name="telno" class="form-control" value="+998" placeholder="Телефон рақам">
</div>
</div>
<div class="col-md-8">
<div class="form-group">
<label>Жойи:</label>
<select name="location" class="form-control">
<option value="Қорақалпоғистон Республикаси">Қорақалпоғистон Республикаси</option>
<option value="Бухоро вилояти">Бухоро вилояти</option>
<option value="Жиззах вилояти">Жиззах вилояти</option>
<option value="Қашқадарё вилояти">Қашқадарё вилояти</option>
<option value="Навоий вилояти">Навоий вилояти</option>
<option value="Наманган вилояти">Наманган вилояти</option>
<option value="Сурхондарё вилояти">Сурхондарё вилояти</option>
<option value="Сирдарё вилояти">Сирдарё вилояти</option>
<option value="Тошкент вилояти">Тошкент вилояти</option>
<option value="Фарғона вилояти">Фарғона вилояти</option>
<option value="Хоразм вилояти">Хоразм вилояти</option>
<option value="Тошкент шаҳар">Тошкент шаҳар</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Қўшимча маълумот:</label>
<textarea rows="5" name="info" class="form-control" placeholder="Қўшимча маълумот" ></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Асосий расмни танланг:</label>
<input type="file" name='image' class="form-control" accept="image/*" >
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Қўшимча расмни танланг:</label>
<input type="file" name='image2' class="form-control" accept="image/*" >
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Қўшимча расмни танланг:</label>
<input type="file" name='image3' class="form-control" accept="image/*" >
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Қўшимча расмни танланг:</label>
<input type="file" name='image4' class="form-control" accept="image/*" >
</div>
</div>
</div>
<button type="submit" class="btn btn-info btn-fill pull-right" name="submit" value="submit">Юклаш</button>
<div class="clearfix" ></div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>

Try this for debug first check $_FILES having any data.
print_r($_FILES);
If it has any data then trying to change condition like. Instead
if ($this->input->post('image2')){
Use following
if( isset( $_FILES['image']['name']) and $_FILES['image']['name'] != '' ) {
// Your code
}

Your Controller Should Be Like This
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Controller_name extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model('your_model');
$this->load->library('upload');
}
public function function_name(){
if($this->input->post('submit')){
/* Your Function */
}
OR Use
if($_POST){
/* Your Function */
}
$this->load->view('News/success');
}
Controller Name Should Be Start From Capital Letter

The if ($this->input->post('image3')){ /* ... */ } is wrong. PHP will not see uploaded files.Check them as : if (array_key_exists($_FILES, 'image3')){ /* ... */ }

Related

Can't insert data on my database from laravel

When I try to insert data into my database, Laravel does not insert the records, but it is strange because when I migrate the tables to be able to perform the database, Laravel creates them without any problem, I do not know what I can be doing wrong if the migration run but stored no
Route:
Route::post('/proyecto', [ctrlCars::class,'store'])->name('cars');
Controler:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\cars;
class ctrlCars extends Controller
{
public function store(Request $request){
$request->validate([
'carRegistration'=> ['required','min:6'],
'name'=> ['required','min:6'],
'fromProduction' => ['required','min:6'],
'stateStored'=> ['required'],
'model'=> ['required','min:4'],
'dateAssembled' => ['required'],
]);
$car = new cars;
$car->carRegistration = $request->carRegistration;
$car->name = $request->name;
$car->fromProduction = $request->fromProduction;
$car->stateStored = $request->stateStored;
$car->model = $request->model;
$car->dateAssembled = $request->dateAssembled;
$car-> save();
return redirect()->route('cars')->with('success','Registro guardado satisfactoriamente');
}}
Template:
#extends('header')
#section('content')
<div class="container w-10 mt-5 border p-4">
<form action="{{ route('cars') }}" method="POST">
#csrf
#if (session('success'))
<h6 class="alert alert-success">{{ session('success') }}</h6>
#endif
#error('carRegistration')
<h6 class="alert alert-danger">{{ $message }}</h6>
#enderror
<p class="h2">Registro vehiculos</p>
<br>
<div class="row">
<section class="col-md-12">
<div class="form-group">
<section class="row">
<div class="col-md-4">
<label for="carRegistration" class="form-label">Placa</label>
<input type="text" class="form-control" name="carRegistration" placeholder="CDE001" maxlength="6">
</div>
<div class="col-md-4">
<label for="name" class="form-label">Nombre</label>
<input type="text" class="form-control" name="name" placeholder="Ferrari Enzo">
</div>
<div class="col-md-4">
<label for="fromProduction" class="form-label">Planta Produccion</label>
<input type="text" class="form-control" name="fromProduction" placeholder="Bmw sede1">
</div>
</section>
<section class="row mt-4">
<div class="col-md-4">
<label for="placa" class="form-label">Fecha Ensamble</label>
<input type="date" class="form-control" name="dateAssembled" placeholder="CDE001">
</div>
<div class="col-md-4">
<label for="model" class="form-label">Módelo Matricula</label>
<input type="text" class="form-control" name="model" maxlength="4" placeholder="2013">
</div>
<div class="col-md-4">
<label for="stateStored" class="form-label">Ciudad Almacenamiento</label>
<Select type="text" class="form-control" id="stateStored" placeholder="Medellin">
<option value=''>Elija una opción</option>
<option value='Medellin'>Medellín</option>
<option value="Bucaramanga">Bucaramanga</option>
<option value="Cali">Cali</option>
<option value="Bogota">Bogotá</option>
</Select>
</div>
</section>
</div>
</section>
</div>
<button type="submit" class="btn btn-success mt-4">Guardar</button>
</form>
</div>
The problem is from your template. The select tag should have a name attribute.
Change your template to this
$car->dateAssembled = $request->dateAssembled;
$car-> save();
return redirect()->route('cars')->with('success','Registro guardado satisfactoriamente');
}}
Template:
#extends('header')
#section('content')
<div class="container w-10 mt-5 border p-4">
<form action="{{ route('cars') }}" method="POST">
#csrf
#if (session('success'))
<h6 class="alert alert-success">{{ session('success') }}</h6>
#endif
#error('carRegistration')
<h6 class="alert alert-danger">{{ $message }}</h6>
#enderror
<p class="h2">Registro vehiculos</p>
<br>
<div class="row">
<section class="col-md-12">
<div class="form-group">
<section class="row">
<div class="col-md-4">
<label for="carRegistration" class="form-label">Placa</label>
<input type="text" class="form-control" name="carRegistration" placeholder="CDE001" maxlength="6">
</div>
<div class="col-md-4">
<label for="name" class="form-label">Nombre</label>
<input type="text" class="form-control" name="name" placeholder="Ferrari Enzo">
</div>
<div class="col-md-4">
<label for="fromProduction" class="form-label">Planta Produccion</label>
<input type="text" class="form-control" name="fromProduction" placeholder="Bmw sede1">
</div>
</section>
<section class="row mt-4">
<div class="col-md-4">
<label for="placa" class="form-label">Fecha Ensamble</label>
<input type="date" class="form-control" name="dateAssembled" placeholder="CDE001">
</div>
<div class="col-md-4">
<label for="model" class="form-label">Módelo Matricula</label>
<input type="text" class="form-control" name="model" maxlength="4" placeholder="2013">
</div>
<div class="col-md-4">
<label for="stateStored" class="form-label">Ciudad Almacenamiento</label>
<Select type="text" name="stateStored" class="form-control" id="stateStored" placeholder="Medellin">
<option value=''>Elija una opción</option>
<option value='Medellin'>Medellín</option>
<option value="Bucaramanga">Bucaramanga</option>
<option value="Cali">Cali</option>
<option value="Bogota">Bogotá</option>
</Select>
</div>
</section>
</div>
</section>
</div>
<button type="submit" class="btn btn-success mt-4">Guardar</button>
</form>
</div>
Thanks for help, the error come from because I call from name on the controller and in this input only have ID, and in the validation for this field have 'required';
I don't know how reply comments, but thanks aynber and Daniel L, you were nice help
First time Comment your validation section and try again. If your data successfully inserted. Then Your need to modify your required field like below.
Replace
['required','min:6']
Like this:
'required|min:6',

Can't get input values with enctype="multipart/form-data"

I'm working with Forms on Laravel, and I'm still learning. I thought I had it all figured out already, but I've been alted by an issue:
When I have enctype="multipart/form-data", I can't get the input values. The file I upload still gets uploaded to the disk, but the rest of the values are not printed. If I remove enctype="multipart/form-data", I do get the values.
Form:
<form id="forms" method="POST" action="alteracaocomissao" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-row">
<div class="form-group col-md-6">
<label for="nomeentidade">Nome:</label>
<input type="text" class="form-control" id="nome1" name="nome1" placeholder="Nome entidade" required>
</div>
<div class="form-group col-md-6">
<label for="numentidade">Nº:</label>
<input type="text" class="form-control" id="num1" name="num1" placeholder="Número" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6 mb-3">
<label for="conta">Conta:</label>
<input type="text" class="form-control" id="conta" name="conta" placeholder="Conta" required>
</div>
<div class="form-group col-md-3 mb-3">
<label for="balcao">Local:</label>
<select class="form-control" id="local1" name="local1" required>
<option value="">Escolher...</option>
<option value="1">Local</option>
<option value="2">Local1</option>
</select>
</div>
<div class="form-group col-md-3 mb-3">
<label for="atleracao">Tipo de alteração:</label>
<select class="form-control" id="alteracao" name="alteracao" required>
<option value="">Escolher...</option>
<option value="1">Alterar1</option>
<option value="2">Alterar2</option>
</select>
</div>
</div>
<hr>
<div class="form-row" id="buildyourform">
<div class="form-group col-md-4">
<label for="comissao">TEST:</label>
<select class="form-control" id="TEST1" name="TEST1" required>
<option value="">Escolher...</option>
<option value="1">TEST</option>
<option value="2">TEST1</option>
</select>
</div>
<div class="form-group col-md-2">
<label for="desconto">Desconto solicitado:</label>
<div class="input-group">
<input type="text" class="form-control" id="desconto" name="desconto" placeholder="Número" required>
<span class=input-group-addon>%</span>
</div>
</div>
<div class="form-group col-md-2">
<label for="add"> &nbsp </label>
<input type="button" value="Adicionar campos" class="form-control btn btn-light" id="add" />
</div>
<div class="form-group col-md-1" id="2field">
<label for="remove"> &nbsp </label>
<input type="button" value="Remover" class="form-control btn btn-light" id="remove" />
</div>
<div class="form-group col-md-2">
</div>
</div>
<hr>
<div class="form-row">
<div class="form-group col-md-12">
<label for="fundamentacao">Fundamentação:</label>
<textarea type="text" class="form-control" id="fundamentacao" name="fundamentacao" placeholder="Fundamentação do pedido" required></textarea>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-2">
<label for="file2">Anexo:</label>
<input type="file" name="file2" id="file2" required>
</div>
</div>
<hr>
<button type="submit" class="btn btn-primary">Enviar</button>
</form>
Controller:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostController extends Controller
{
public function AltComiss(Request $request)
{
session_start();
$array1 = $request -> all();
$path = $request->file('file2')->store('altComiss');
$arrayRm1 = array_shift($array1);
$_SESSION["testPostSection1"] = $array1;
return redirect('alteracaocomissao');
}
}
Route:
Route::post('alteracaocomissao', 'PostController#AltComiss');
Testing code:
#php
session_start();
if (isset($_SESSION["testPostSection1"])) {
echo '<pre>'; print_r($_SESSION["testPostSection1"]); echo '</pre>';
}
#endphp
I do have SESSION there to test if the values are getting saved, because I still havn't set up the database, and until I do I'm using SESSION to test. Obviously once I set the database up I will switch from SESSION to inserting the values into the database.
Thanks in advance!
I think it's will help you
use Illuminate\Http\Request;
//use these For Start your session and Store file
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Storage;
class PostController extends Controller{
public function AltComiss(Request $request){
$array1 = $request->all();
if ($request->hasFile('file2')) {
$file = $request->file('file2');
$destinationPath = 'altComiss';
$file->move($destinationPath,$file->getClientOriginalName());
}
$arrayRm1 = array_shift($array1);
Session::flash('allInput',$arrayRm1);
return redirect('alteracaocomissao');
}
}
On your view file for get the session data just use
#if (Session::has('allInput'))
<?php
echo '<pre>';
print_r(Session::get('allInput'));
echo '</pre>';
?>
#endif

How can i upload form data with file and insert all form data with uploaded file name with the following code in Codeigniter

I am having one form with text, select, file fields.
I am using Codeigniter Framework.
I want to upload the selected file in 'uploads' folder and insert all form data with uploaded file name.
My code is below.
Please help me to complete this.
View :
<?php echo form_open_multipart('assign/task_assign'); ?>
<fieldset>
<div class="row">
<div class="col-md-2">Title</div>
<div class="col-md-10">
<div class="form-group">
<input class="form-control" name="task_title" type="text" required="required">
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Description</div>
<div class="col-md-10">
<div class="form-group">
<textarea class="form-control" cols="80" rows="7" name="task_description"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Priority</div>
<div class="col-md-10">
<div class="form-group">
<select class="form-control" name="task_priority" required>
<option value="" disabled="disabled" selected="selected">Priority
</option>
<option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Start Date</div>
<div class="col-md-10">
<div class="form-group">
<input class="form-control" name="task_start" id="datepicker" type="text" required="required" autocomplete="off">
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Due Date</div>
<div class="col-md-10">
<div class="form-group">
<input class="form-control" name="task_due" id="datepicker1" type="text" required="required" autocomplete="off">
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Assign To</div>
<div class="col-md-10">
<div class="form-group">
<select class="form-control" name="task_to" value="" required>
<option value="" disabled="disabled" selected="selected">To
</option>
<?php foreach ($h->result() as $row) { ?>
<option value="<?php echo $row->name; ?>"><?php echo $row->name; ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Attachments</div>
<div class="col-md-10">
<div class="form-group">
<input type="file" class="form-control" name="userfile">
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Additional Information</div>
<div class="col-md-10">
<div class="form-group">
<textarea class="form-control" cols="80" rows="6" name="task_info"></textarea>
</select>
</div>
</div>
</div>
<input class="btn btn-primary btn-block" type="submit" value="Assign" required="required" name="assign">
</fieldset>
<?php echo form_close(); ?>
Controller :
public function task_assign()
{
$name=$this->session->userdata('name');
date_default_timezone_set('Asia/Calcutta');
$config = array(
'upload_path' => "./uploads/",
'overwrite' => TRUE,
'max_size' => "2048000",
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$data=array('upload_data' => $this->upload->data());
$task=array(
'title'=>$this->input->post('task_title'),
'description'=>$this->input->post('task_description'),
'priority'=>$this->input->post('task_priority'),
'status'=>'Ongoing',
'start_date'=>$this->input->post('task_start'),
'due_date'=>$this->input->post('task_due'),
'end_date'=>$this->input->post('task_due'),
'assigned_to'=>$this->input->post('task_to'),
'assigned_by'=> $name,
'time'=> date('d-m-Y H:i:s'),
'task_file' => $upload_data['file_name'],
'additional_info'=>$this->input->post('task_info')
);
print_r($task);
$assign=$this->assign_model->assign_task($task);
if($assign)
{
$this->session->set_flashdata('error_msg', 'Could not Assign task');
redirect('assign');
}
else
{
$this->session->set_flashdata('success_msg', 'Task Assigned to ' .$task['assigned_to']. ' Successfully...');
redirect('assign');
}
}
Model :
class Assign_model extends CI_model{
/* Loading Parent Construct */
function __construct()
{
parent::__construct();
}
/* Get User Data From User Table */
public function fetchtable()
{
$query = $this->db->get('user');
return $query;
}
/* Insert Task Into 'issues' Database */
public function assign_task($task)
{
$this->db->insert('issues', $task);
}
}
I think the file name should give in the controller to upload. But i dont about how add it.
Only the file upload and getting file name is problem here. Please help me to do this..

Update Database tables with values input by user in CodeIgniter using PHP

I'm trying to update one of my user tables in the Database with values taken from the the user. But for some reason it's not updating anything.
HTML Form
<form class="form-horizontal" method = "post">
<fieldset>
<!-- Form Name -->
<legend>User Details</legend>
<div>
<?php echo $this->session->flashdata('msg'); ?>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Full Name</label>
<div class="col-md-8">
<input id="name" name="name" type="text" placeholder="something" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="dob">Date of Birth</label>
<div class="col-md-4">
<input id="dob" name="dob" type="text" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Multiple Radios -->
<div class="form-group">
<label class="col-md-4 control-label" for="gender">Gender</label>
<div class="col-md-2">
<select id="gender" name="gender" class="form-control">
<option value="1">Male</option>
<option value="2">Female</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="degree">Degree</label>
<div class="col-md-8">
<input id="degree" name="degree" type="text" placeholder="degree" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="specialization">Specialization</label>
<div class="col-md-8">
<input id="specialization" name="specialization" type="text" placeholder="specialization" class="form-control input-md">
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="year">Degree Year</label>
<div class="col-md-2">
<select id="year" name="year" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="semester">Semester</label>
<div class="col-md-2">
<select id="semester" name="semester" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
</div>
<!-- File Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="filebutton">Upload Profile Picture</label>
<div class="col-md-4">
<input id="filebutton" name="filebutton" class="input-file" type="file">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<a href="<?php echo base_url("/index.php/studentDashboardController/saveUserDetails"); ?>" >
<button id="submit" name="submit" class="btn btn-primary">Save Changes</button>
</a>
</div>
</div>
</fieldset>
studentDashboardController
public function saveUserDetails()
{
$this->load->model('userModel');
if (isset($this->session->userdata['logged_in']))
{
$username = ($this->session->userdata['logged_in']['username']);
}
$user = $this-> userModel-> getUserUid($username); //Gets the uid of the current user
$this->userModel->saveUserDetails($user);
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">Successfully Inserted Data</div>');
$this->load->view('studentDashboard/common',$data);
redirect(base_url('index.php/studentDashboard/editProfile',$data1));
}
userModel
public function saveUserDetails($uid)
{
$data = array(
'name' => $this->input->post('name')
);
$this->db->where("uid",$uid);
$this->db->update("sysuser",$data);
}
The sysuser has the uid and name fields.I' not sure what I'm doing wrong here. Any help in this regard will be appreciated
You dont send your post data to controller. Change $this->userModel->saveUserDetails($user); as
$this->userModel->saveUserDetails($user,$this->input->post('name'));
Now Model should be like
public function saveUserDetails($uid,$name)
{
$data = array(
'name' => $name
);
$this->db->where("uid",$uid);
$this->db->update("sysuser",$data);
}
and make sure you have set correctly form action like
<form class="form-horizontal" method="post" action="<?php echo site_url('studentDashboardController/saveUserDetails');?>">

how to create multiple query in one. when i want fetch date from database which is search from user

here my html code.
i want fetch data from database. when a user search profile then i want display only searched data which enter in form.
the problem is query doesn't work. can you tell me can we run multiple query in single query.
<form method="get" action="search.php" enctype="multipart/form-data">
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">Gender : </label>
<div class="col-sm-7 form_radios">
<div class="select-block1">
<select name="gender">
<option value="">Select Gender</option>
<option value="">Male</option>
<option value="">Female</option>
</select>
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">Marital Status : </label>
<div class="col-sm-7 form_radios">
<div class="select-block1">
<select name="mstatus">
<option>Select status</option>
<option value="Single">Single</option>
<option value="Married">Married</option>
<option value="Widow">Widow</option>
<option value="Widower">Widower</option>
<option value="Divorcee">Divorcee</option>
<option value="Seprated">Seprated</option>
</select>
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">Gotra : </label>
<div class="col-sm-7 form_radios">
<div class="select-block1">
<select name="gotra">
<option>Select gotra</option>
<option value="Aalakuntor">Aalakuntor</option>
<option value="Bantalor">Bantalor</option>
<option value="Batalor">Batalor</option>
<option value="Bayamuttalor">Bayamuttalor</option>
</select>
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">District / City : </label>
<div class="col-sm-7 form_radios">
<div class="select-block1">
<input type="text" class="form-control" placeholder="city" name="city" >
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">Education : </label>
<div class="col-sm-7 form_radios">
<div class="select-block1">
<input type="text" class="form-control" placeholder="education" name="education" >
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">Age : </label>
<div class="col-sm-7 form_radios">
<div class="col-sm-5 input-group1">
<input class="form-control has-dark-background" name="age1" id="slider-name" placeholder="28" type="text" >
</div>
<div class="col-sm-5 input-group1">
<input class="form-control has-dark-background" name="age2" id="slider-name" placeholder="40" type="text" >
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<div class="col-sm-5 input-group1">
<div class="select-block1">
<input type="submit" class="btn btn-success" value="Search" name="search">
</div>
</div>
<div class="clearfix"> </div>
</div>
</form>
here my search.php code.
<div class="paid_people">
<h1></h1>
<div class="row_1">
<?php
include("includes/db.php");
global $con;
if(isset($_GET['search']))
{
$search_gender = $_GET['gender'];
$search_mstatus = $_GET['mstatus'];
$search_gotra = $_GET['gotra'];
$search_city = $_GET['city'];
$search_education = $_GET['education'];
$search_age1 = $_GET['age1'];
$search_age2 = $_GET['age2'];
$get_user = "SELECT * FROM users WHERE age BETWEEN '$search_age1' AND '$search_age2' AND gender like '$search_gender' AND mstatus like '$search_mstatus' AND gotra like '$search_gotra' AND education like '$search_education' AND city like'$search_city'";
$run_user = mysqli_query($con, $get_user);
while ($row_user = mysqli_fetch_array($run_user))
{
$u_id = $row_user['user_id'];
$u_fname = $row_user['first_name'];
$u_age = $row_user['age'];
$u_education = $row_user['education'];
$u_occupation = $row_user['occupation'];
$u_city = $row_user['city'];
$u_image = $row_user['photo'];
$profile_id = $row_user['profile_id'];
echo "<div class='col-sm-6 paid_people-left'>
<ul class='profile_item'>
<a href='view_profile.php?userdetail_id=$u_id'>
<li class='profile_item-img'>
<img src='admin_vadarshadi/users-photo/resized_$u_image' class='img-responsive' alt='$u_fname' />
</li>
<li class='profile_item-desc'>
<h4>Profile ID: $profile_id</h4>
<h4>Name: $u_fname Age: $u_age Yrs </h4>
<p>City: $u_city, Education: $u_education</p>
<h5>View Full Profile</h5>
</li>
<div class='clearfix'> </div>
</a>
</ul>
</div>";
}
}
?>
</div>
</div>

Categories