Get blank page after submit in Codeigniter? - php

I am working on CI and i created one simple CRUD to insert PDF with some data in table. Sometimes my code works but now its completely not working.I am getting blank page after submitting my form. And nothing is happens like print_r and var_dump etc. I dont know whats wrong in my code.
My sidebar :
From where i click to my controller to get my view.
<li>Upload Pay slips</li>
Its working fine. On click this i am able to go to my page that is add_pay_slips.
Controller for the same:
public function add_pay_slips()
{
$this->load->view('layouts/header');
$this->load->view('layouts/sidebar');
$data['salary']=$this->pay_slips->getPaySlips1();
$this->load->view('responsibilities/add_pay_slips',$data);
$this->load->view('layouts/footer');
}
After this i get my form view:
<form method="post" enctype="multipart/form-data" class="form-horizontal" action="<?php echo base_url();?>responsible/upload">
<div class="control-group">
<label class="control-label">Select Month</label>
<div class="controls">
<select name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Select Year</label>
<div class="controls">
<select name="year">
<option>2017</option>
<option>2016</option>
<option>2015</option>
<option>2014</option>
<option>2013</option>
<option>2012</option>
<option>2011</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Select Employee</label>
<div class="controls">
<select name="employee_name">
<?php
foreach ($salary as $row) {?>
<option value='<?php echo $row->EMPLOYEE_ID;?>'><?php echo $row->EMPLOYEE_NAME;}?></option>
<!--<input type="hidden" name="employee_id" value="<?php //echo $row->EMPLOYEE_ID?>">-->
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Select Country</label>
<div class="controls">
<select name="org_id">
<option value="40">UK</option>
<option value="65">INDIA</option>
<option value="47">POLAND</option>
<option value="57">GERMANY</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Upload Payslip</label>
<div class="controls">
<input type="file" name="userfile"/>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Save</button>
</div>
</form>
and for this view on submit button i created one controller to insert data.
function upload(){
$filename = 'pdf';
$config = array(
'upload_path' => 'uploads',
'allowed_types' => "pdf",
'file_name' => $filename
);
$config['allowed_types'] = 'pdf';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload())
{
$file_data = $this->upload->data();
$data1['userfile'] = $file_data['file_name'];
$data=
array(
'PAY_MONTH'=>$this->input->post('month'),
'PAY_YEAR'=>$this->input->post('year'),
'ORG_ID'=>$this->input->post('org_id'),
'EMPLOYEE_ID'=>$this->input->post('employee_name'),
'PDF'=>$data1['userfile'],
);
$this->load->model('pay_slips_model');
$result=$this->pay_slips->insert_payslips($data);
if($result==true)
{
$this->session->set_flashdata('msg',"PDF Added Successfully");
$this->load->view('layouts/header');
$this->load->view('layouts/sidebar');
$data['salary']=$this->pay_slips->getPaySlips1();
$this->load->view('responsibilities/add_pay_slips' ,$data,'refresh');
$this->load->view('layouts/footer');
}
else
{
$this->seesion->set_flashdata('msg1',"PDF Added Failed");
redirect('responsibilities/add_pay_slips');
}
}
}
And for this i have one model to insert data.
public function insert_payslips($data)
{
$this->db->insert('all_salary_slip_details',$data);
return ($this->db->affected_rows() != 1 ) ? false:true;
}
I have one page responsible.php my all controllers are on the same page.What is affecting my code. i am stuck here. Onclick Submit i just got my controller's url and blank page. payroll1/responsible/upload.

Related

How to use an if statement on the blade template. error: Undefined variable $category

I have created a function to retrieve a specific column in the database using eloquent, on my productsController
public function create()
{
$category = Product::select('category')->get();
return view('products.create');
}
And Now I want to use an if statement on the create.blade.php to check whether the value in the database is equal to 'liquor',
<div class="row mb-4">
<label for="category" class="col-md-4 col-form-label text-md-end">Category</label>
<div class="col-md-6">
<select name="category" id="category" class="form-select col-md-6">
<option value="liquor">liquor</option>
<option value= "food">food</option>
<option value="DIY">DIY</option>
<option value= "thrift shops">thrift shops</option>
<option value= "home decor">home decor</option>
<option value= "phones and tablets">phones and tablets</option>
<option value= "computing">computing</option>
<option value= "electronics">electronics</option>
<option value= "beauty products">beauty products</option>
<option value= "others">others</option>
</select>
</div>
</div>
#if($category == 'liquor')
<div class="row mb-4">
<label for="subcategory" class="col-md-4 col-form-label text-md-end">Sub Category</label>
<div class="col-md-6">
<select name="subcategory" id="subcategory" class="form-select col-md-6">
<option value="null">Select subcategory</option>
<option value="wine">Wine</option>
<option value="whisky">Whisky</option>
<option value="brandy">Brandy</option>
<option value="scotch">Scotch</option>
<option value="spirit">Spirit</option>
<option value="gin">Gin</option>
<option value="vodka">Vodka</option>
<option value="beer">Beer</option>
<option value="rum">Rum</option>
<option value="mixers">Mixers</option>
<option value="bourbon">Bourbon</option>
<option value="cognac">Cognac</option>
<option value="other">Other</option>
</select>
</div>
</div>
<div class="row mb-4">
<label for="volume" class="col-md-4 col-form-label text-md-end">Volume</label>
<div class="col-md-6">
<select name="volume" id="volume" class="form-select col-md-6">
<option value="null">Choose volume</option>
<option value="5ltr">5ltr</option>
<option value="1ltr">1ltr</option>
<option value="750ml">750ml</option>
<option value="500ml">500ml</option>
<option value="250ml">250ml</option>
<option value="other">Other</option>
</select>
</div>
</div>
#endif
However, I get the following error: Undefined variable $category
What could be the issue?
I think you forgot to send the $category to the view:
return view('products.create', compact("category"));
or like this:
return view('products.create')
->with('category', $category)
->with('title', 'New Title');
or like this:
return view('products.create', ['category' => $category]);
You can add as many vars/collections/or whatever as you wish both ways.
use this
#if(isset($category) && $category == 'liquor')
//your code
#endif
Also check this link for validation
you need to send $category from controller to your blade like this
public function create()
{
$category = Product::select('category')->get();
return view('products.create')->with('category',$category);
}
you can also do this with another way
public function create()
{
$category = Product::select('category')->get();
return view('products.create',compact('category'));
}

Passing data to Queue Job gives 404 - Not other Error

From My Controller
use App\Jobs\MonthlyReport;
public function store(Request $request)
{
$report = new Report;
...
$report->save();
$this->dispatch(new MonthlyReport($report));
return $report;
}
MonthlyReport.php
use App\Report;
private $rep;
public function __construct(Report $report)
{
$this->rep = $report;
}
public function handle()
{
dd($this->rep);
}
It gives 404, no other error. But If I didn't pass $report variable then it's working. What should be the problem that trigger 404 instead of error or dd();
Note: The same logic is used in another project and it's working, but not here
My Web.php
Route::resource('report', 'ReportController');
My Form (Year and month data are coming from JQuery)
<form method="POST" action="/report">
#csrf
<div class="form-group">
<label class="required">Office</label>
<select class="form-control" id="change_office" required name="office">
<option value>choose office</option>
#foreach ($offices as $office)
<option value="{{ $office->id }}">{{ $office->name }}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label class="required" for="year">Option</label>
<select id="option" class="form-control" name="option" required>
<option value="">Choose options</option>
<option value="Monthly">Monthly</option>
<option value="Quarterly">Quarterly</option>
<option value="Yearly">Yearly</option>
<option value="Custom">Custom</option>
<option value="Time Base">Entry/Exit Report</option>
</select>
</div>
<div class="form-group" id="yearly_wrapper" style="display: none;">
<label class="required" for="year">Year</label>
<select id="year" class="form-control" name="year">
<option value="">Choose year</option>
</select>
</div>
<div class="form-group" id="monthly_wrapper" style="display: none;">
<label class="required">Select Month</label>
<select id="monthly" class="form-control" name="monthly">
<option value="">Select month</option>
</select>
</div>
<div>
<button type="submit" class="btn btn-outline-warning btn-round">
<i class="now-ui-icons ui-1_check"></i> Generate
</button>
</div>
</form>
If you just want to check the $report in your job handle, try something like this:
Job Class
public function handle()
{
Log::info('Report created', $this->rep);
return;
}
Controller
public function store(Request $request)
{
$report = new Report;
...
$report->save();
return MonthlyReport::dispatch($report);
}
If everything is ok, you should see the created report in your log file.

sending value from view to controller

I have a dropdown list to display values for certain building: i am not sure how can I send the value to a new page to display the values for that selected building only. i am getting the error when trying to load the page with the dropdown menu. I am not sure what i am doing wrong.
here is my index.blade:
<form action="{{ route('custom'),$datacenter }}">
<div class="form-group" id="dropdown">
<label>Data Center:</label>
<select name="datacenter" id="datacenter" class="form-group">
<option value="RDC46">RDC46</option>
<option value="RDC03">RDC03</option>
<option value="RDC05">RDC05</option>
<option value="DDC21">DDC21</option>
</select>
<button type="submit" class="btn btn-info">Submit</button>
</div>
here is my web route:
Route::get('custom\{datacenter}', 'AssigneeController#custom')->name('custom');
and here is my controller:
public function custom($datacenter)
{
$assignees = assignee::findorfail('datacenter')->paginate(10);
return view('custom',compact('assignees'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
I am getting the following error:
Missing required parameters for [Route: custom] [URI:
custom{datacenter}]. (View:
/Users/Documents/Laravel/blog/resources/views/assignees/index.blade.php)
You should try this:
<form action="{{ route('custom',[$datacenter]) }}">
<div class="form-group" id="dropdown">
<label>Data Center:</label>
<select name="datacenter" id="datacenter" class="form-group">
<option value="RDC46">RDC46</option>
<option value="RDC03">RDC03</option>
<option value="RDC05">RDC05</option>
<option value="DDC21">DDC21</option>
</select>
<button type="submit" class="btn btn-info">Submit</button>
</div>
</form>
It feels like a simple GET request to me.
Change your form to the following:
<form action="{{ route('custom') }}">
<div class="form-group" id="dropdown">
<label>Data Center:</label>
<select name="datacenter" id="datacenter" class="form-group">
<option value="RDC46">RDC46</option>
<option value="RDC03">RDC03</option>
<option value="RDC05">RDC05</option>
<option value="DDC21">DDC21</option>
</select>
<button type="submit" class="btn btn-info">Submit</button>
</div>
</form>
In your controller:
public function custom(Request $request)
{
// You will have access to the datacenter using $request->datacenter
$assignees = assignee::findorfail($request->datacenter)->paginate(10);
return view('custom',compact('assignees'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
There's no need for the datacenter segment in your route:
Route::get('custom', 'AssigneeController#custom')->name('custom');
Try this code,
<form action="{{ route('custom', $datacenter)}}">
<div class="form-group" id="dropdown">
<label>Data Center:</label>
<select name="datacenter" id="datacenter" class="form-group">
<option value="RDC46">RDC46</option>
<option value="RDC03">RDC03</option>
<option value="RDC05">RDC05</option>
<option value="DDC21">DDC21</option>
</select>
<button type="submit" class="btn btn-info">Submit</button>
</div>
</form>

How to get the selected dropdown value using jQuery

I want to get the selected value in dropdown for edit. But I got all the values in dropdown are selected.
function getinstruments() {
var model=$('#model').val();
var brand=$('#brand').val();
brand = brand.split('%') ;
model = model.split('%') ;
$.getJSON("{!! URL::route('appraisal.getinstrument') !!}", {brand: brand[0],model:model[0]}, function(data) {
if(data.success)
{
$('select[name="sub_model"]').find(":selected").html(data.sub_models_array);
$('select[name="color"]').find(":selected").html(data.colors_array);
$('select[name="top"]').find(":selected").html(data.top_array);
$('select[name="neck"]').find(":selected").html(data.neck_array);
}
});
}
Don't know what the problem with this code is. Reply of the question is highly appreciated
<div class="col-lg-6 col-xsm-6">
<h4>Enter Body wood details</h4>
<div class="form-group">
<label>Top Wood</label>
<select name='top_wood' class='form-control' placeholder ='Enter Top wood' id='top'>
<option value=''>Pick a topWood</option>
</select>
</div>
<div class="form-group">
<label>Back Woord</label>
<select name='back_wood' class='form-control' placeholder ='Enter Back wood' id='back'>
<option value=''>Pick a topWood</option>
</select>
</div>
<div class="form-group">
<label>Neck Wood</label>
<select name='neck_wood' class='form-control' placeholder ='Enter Neck wood' id='neck'>
<option value=''>Pick a NeckWood</option>
</select>
</div>
<div class="form-group">
<label>Select color</label>
<select name='color' class='form-control' id='color' >
<option value=''>Pick a color</option>
</select>
</div>
<div class="form-group">
<label>Frets</label>
<select name='frets' class='form-control' placeholder ='Enter Frets' id='frets'>
<option value=''>Pick a Fingerboard Material</option>
</select>
</div>
<div class="form-group">
<label>Turner</label>
<select name='turner' class='form-control' placeholder ='Enter Turner' id='turner'>
<option value=''>Pick a Fingerboard Material</option>
</select>
</div>
this is my view file where i want selected value of dropdaown

php how do I make a textbox unchangeable or passive and a syntax error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
ive been all around trying to fix the code but i still get an error
Parse error: syntax error, unexpected 'userfirstName' (T_STRING), expecting ',' or ';' in /home/crosswayprinting/public_html/ztest2/functions/shop.php on line 66
here's the code btw
whats my mistake :/ ?
<?php if($user_home->is_logged_in()){
echo '
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h2 class="section-heading">Place an Order</h2>
<div class="text-center" style="input, select, textarea{
color: #000;
}">
</div><BR>
<form role="form" class="userTrans" method="POST">
<input type="hidden" value="OrderInsert" name="act_userTrans">
<div class="form-group">
<label for="typeofservice">Select Type of Service</label>
<select id="typeofservice" class="form-control" name="typeofservice">
<option value="Tarpaulin">Tarpaulin</option>
<option value="Rush ID">Rush ID</option>
<option value="Photocopy">Photocopy</option>
<option value="Graphic Layout">Graphic Layout</option>
<option value="Invitation">Invitation</option>
<option value="Panaflex">Panaflex</option>
<option value="Signages">Signages</option>
<option value="Stickers">Stickers</option>
<option value="Sintra board">Sintra board</option>
<option value="Large Format Photo">Large Format Photo</option>
<option value="PVC ID">PVC ID</option>
<option value="Lamination">Lamination</option>
<option value="Bag Tags">Bag Tags</option>
<option value="Notary Public">Notary Public</option>
<option value="Scan">Scan</option>
</select>
</div>
<div class="form-group">
<label for="templateselect">Template Selection</label>
<select id="templateselect" class="form-control" name="templateselect">
<option value="Own Made Template">Own Made Template</option>
<option value="Pre-made Template">Pre-made Template</option>
</select>
</div>
<div class="form-group">
<label for="text">More details about your order</label>
<input type="text" class="form-control" id="orderdetails" name="orderdetails">
</div>
<div class="form-group">
<label for="text"> Customer Name</label>
<input type="text" value=" <?php echo $row['userfirstName']; ?> " class="form-control" id="customer" name="customer">
</div>
/* this is the code btw what makes it an error, i am trying to
echo a customer's name and make it Passive or uneditable textbox so it can
register to my orderlist to whom ordered */
<button type="submit" class="btn btn-default userTrans">Submit</button>
</form>
';
}
else{
echo '
<center> Please Login to Place an Order </center>
';}
?>
Get rid of the echo statements wrapping your HTMl. There's no need, just escape out of the PHP interpreter and print your HTML. Then you won't get an error when you're doing <?php echo $row['userFirstName']; ?>....Something like this:
<?php if($user_home->is_logged_in()){ ?>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h2 class="section-heading">Place an Order</h2>
<form role="form" class="userTrans" method="POST">
<input type="hidden" value="OrderInsert" name="act_userTrans">
<div class="form-group">
<label for="typeofservice">Select Type of Service</label>
<select id="typeofservice" class="form-control" name="typeofservice">
<option value="Tarpaulin">Tarpaulin</option>
<option value="Rush ID">Rush ID</option>
<option value="Photocopy">Photocopy</option>
<option value="Graphic Layout">Graphic Layout</option>
<option value="Invitation">Invitation</option>
<option value="Panaflex">Panaflex</option>
<option value="Signages">Signages</option>
<option value="Stickers">Stickers</option>
<option value="Sintra board">Sintra board</option>
<option value="Large Format Photo">Large Format Photo</option>
<option value="PVC ID">PVC ID</option>
<option value="Lamination">Lamination</option>
<option value="Bag Tags">Bag Tags</option>
<option value="Notary Public">Notary Public</option>
<option value="Scan">Scan</option>
</select>
</div>
<div class="form-group">
<label for="templateselect">Template Selection</label>
<select id="templateselect" class="form-control" name="templateselect">
<option value="Own Made Template">Own Made Template</option>
<option value="Pre-made Template">Pre-made Template</option>
</select>
</div>
<div class="form-group">
<label for="text">More details about your order</label>
<input type="text" class="form-control" id="orderdetails" name="orderdetails">
</div>
<div class="form-group">
<label for="text"> Customer Name</label>
<input type="text" value=" <?php echo $row['userfirstName']; ?> " class="form-control" id="customer" name="customer">
<!-- now the above won't give an error -->
</div>
<button type="submit" class="btn btn-default userTrans">Submit</button>
</form>
</div>
</div>
<?php } else { ?>
<!-- Do not use center tags when you're using bootstrap framework -->
<!--<center> Please Login to Place an Order </center>-->
<div class="text-center"> Please Login to Place an Order </div>
<?php } ?>
Also what's going on with your inline styles? That's not how this works:
<div class="text-center" style="input, select, textarea{
color: #000;
}">
Just move that CSS somewhere else. You can't use targeted selectors within the style="" tag, only relevant CSS.

Categories