i want this code should not be run if user call upate route code
if($getDistanceValue * 1000 > 300){
if($chk_ord == 0)
{
$order->chk_ord_vst = 1;
}
elseif($chk_ord != 0){
$order->chk_ord_vst = $chk_ord + 1;
}
}
elseif($getDistanceValue * 1000 <= 300 ){
if($chk_ord >= 4){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 3){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 2){
$order->chk_ord_vst = 1;
}
elseif($chk_ord <= 1){
$order->chk_ord_vst = 0;
}
}
i am using a same fucntion to update or store order but on update i donot want to run above code i know it is very simple but i am a student and learning help me here it is controller function first user create order the if wants to update then we use get function to pass value to edit view and then pass again to stor function
public function storeOrder(Request $request , $update = null , $customer_id){
$order = !is_null($update) ? Order::find($update) : new Order();
$cus_det = explode("-", $request->customer_id);
$tt_amount = array_sum($request->amount) + $request->old_balance;
if(is_null ($update))
$balance = $tt_amount + $request->old_balance;
$auth_id = Auth::id();
if(Auth::user()->role == 4){
$auth_id = Customer::where('user_id', $auth_id)->first()->created_by;
}
$order->customer_id = $cus_det[0];
$order->user_id = Auth::id();
$order->ot_id = !is_null($update) ? $order->ot_id : $auth_id;
$order->unit = array_sum($request->unit);
$order->amount = $tt_amount;
$order->subtotal = array_sum($request->amount);
$order->order_comments = $request->order_comments;
if( Auth::user()->role == 5){
$order->location_url_ot = $request->location_url_ot;
$order->received_amount = 0;
}
else{
$order->received_amount = $request->received_amount;
}
$order->discount = $request->discount;
$order->order_date= date('Y/m/d', strtotime($request->order_date));
if($tt_amount >= $request->received_amount){
$order->amount_left = ($tt_amount - $request->received_amount - $request->discount);
}
else{
$order->advance = $request->received_amount - $tt_amount;
$order->amount_left = $request->old_balance - $request->received_amount - $request->discount;
}
$checkB = $this->checkMinBalance($cus_det[0] , $order->amount_left);
if($checkB){
return redirect()->back()->with('error' , 'Customer Balance Limit Exceeded ( Limit is '.$checkB.' )');
}
if($request->has('important')){
$order->is_important=1;
}
if($request->has('urgent')){
$order->urgent = urgent ;
}
$getothomDistanceValue = ($this->getothomDistance($order) * 1.37);
$getDistanceValue = ($this->getDistance($order) * 1.37);
$old_order = Order::where('customer_id' , $order->customer_id)->orderBy('id' , 'desc')->get();
$chk_ord = $old_order[0]->chk_ord_vst;
if($getDistanceValue * 1000 > 300){
if($chk_ord == 0)
{
$order->chk_ord_vst = 1;
}
elseif($chk_ord != 0){
$order->chk_ord_vst = $chk_ord + 1;
}
}
elseif($getDistanceValue * 1000 <= 300 ){
if($chk_ord >= 4){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 3){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 2){
$order->chk_ord_vst = 1;
}
elseif($chk_ord <= 1){
$order->chk_ord_vst = 0;
}
}
$order->save();
}
What I get from your question is you are using the same storeOrder function for storing and updating an order.
When you are using it for update, You need the id from $request->id or any other parameter from the front-end so that you can find that specific Order and then call update(). If you get the $id, You can just check if the order exists or not like below:
$order_exists = Order::find($request->id);
if(!isset($order_exists))
{
if($getDistanceValue * 1000 > 300){
if($chk_ord == 0)
{
$order->chk_ord_vst = 1;
}
elseif($chk_ord != 0){
$order->chk_ord_vst = $chk_ord + 1;
}
}
elseif($getDistanceValue * 1000 <= 300 ){
if($chk_ord >= 4){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 3){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 2){
$order->chk_ord_vst = 1;
}
elseif($chk_ord <= 1){
$order->chk_ord_vst = 0;
}
}
}
// then $order->save() when done
One way to go about this would be to pass a parameter through the form and check.
But if you have route names defined, you could also do something like:
if(\Illuminate\Support\Facades\Route::current()->getName() === 'orders.create'){
// logic here
}
However, I must say that I consider the later solution an anti-pattern.
I got problem with this code. I've tried so many possible solution but still no update in phpmyadmin. The code run successfully through the footer since it say "Successfully Updated" but still no changes
<?php
if ($_POST){
$con = mysql_connect("localhost", "root", "pass123");
if (!$con){die('Could not connect:' . mysql_error());}
mysql_select_db("testing", $con) or die('Error:' . mysql_error());
$entry = $_GET['entry'];
$branch_id = $_POST['branch_id'];
$outletname = $_POST['outletname'];
$date = $_POST['date'];
$q11a = $_POST['q11a'];
$q12a = $_POST['q12a'];
$q13a = $_POST['q13a'];
$q14a = $_POST['q14a'];
$q15a = $_POST['q15a'];
$q16a = $_POST['q16a'];
$q17a = $_POST['q17a'];
$q18a = $_POST['q18a'];
$q19a = $_POST['q19a'];
$q20a = $_POST['q20a'];
$q21a = $_POST['q21a'];
$q22a = $_POST['q22a'];
$q23a = $_POST['q23a'];
$q24a = $_POST['q24a'];
$q25a = $_POST['q25a'];
$q26a = $_POST['q26a'];
$q27a = $_POST['q27a'];
$q28a = $_POST['q28a'];
$q29a = $_POST['q29a'];
$q30a = $_POST['q30a'];
$q31a = $_POST['q31a'];
$q32a = $_POST['q32a'];
$q33a = $_POST['q33a'];
$q34a = $_POST['q34a'];
$q35a = $_POST['q35a'];
$q36a = $_POST['q36a'];
$q37a = $_POST['q37a'];
$q38a = $_POST['q38a'];
$q39a = $_POST['q39a'];
$q40a = $_POST['q40a'];
$q41a = $_POST['q41a'];
$q42a = $_POST['q42a'];
$q43a = $_POST['q43a'];
$q44a = $_POST['q44a'];
$q45a = $_POST['q45a'];
$q46a = $_POST['q46a'];
$q47a = $_POST['q47a'];
$q48a = $_POST['q48a'];
$q49a = $_POST['q49a'];
$q50a = $_POST['q50a'];
$q51a = $_POST['q51a'];
$q52a = $_POST['q52a'];
$q53a = $_POST['q53a'];
$q54a = $_POST['q54a'];
$q55a = $_POST['q55a'];
$q56a = $_POST['q56a'];
$q57a = $_POST['q57a'];
$q58a = $_POST['q58a'];
$q59a = $_POST['q59a'];
$q60a = $_POST['q60a'];
$q61a = $_POST['q61a'];
$q62a = $_POST['q62a'];
$q63a = $_POST['q63a'];
$q64a = $_POST['q64a'];
$q65a = $_POST['q65a'];
$q66a = $_POST['q66a'];
$q67a = $_POST['q67a'];
$q68a = $_POST['q68a'];
$q69a = $_POST['q69a'];
$q70a = $_POST['q70a'];
$q71a = $_POST['q71a'];
$q72a = $_POST['q72a'];
$q73a = $_POST['q73a'];
$q74a = $_POST['q74a'];
$q75a = $_POST['q75a'];
$q76a = $_POST['q76a'];
$q78a = $_POST['q78a'];
$q78a1 = $_POST['q78a1'];
$q79a = $_POST['q79a'];
$q79a1 = $_POST['q79a1'];
$q80a = $_POST['q80a'];
$q81a = $_POST['q81a'];
$q82a = $_POST['q82a'];
$q83a = $_POST['q83a'];
$q84a = $_POST['q84a'];
$q85a = $_POST['q85a'];
$timein = $_POST['timein'];
$HOR = $_POST['HOR'];
$MODa = $_POST['MODa'];
$KL = $_POST['KL'];
$ateambox = $_POST['ateambox'];
$box35 = $_POST['box35'];
$box36 = $_POST['box36'];
$box41 = $_POST['box41'];
$box50 = $_POST['box50'];
$box53 = $_POST['box53'];
$box54 = $_POST['box54'];
$box55 = $_POST['box55'];
$box61a = $_POST['box61a'];
$box61aa = $_POST['box61aa'];
$box61b = $_POST['box61b'];
$box61bb = $_POST['box61bb'];
$box61c = $_POST['box61c'];
$box61cc =$_POST['box61cc'];
$box61d = $_POST['box61d'];
$box61dd = $_POST['box61dd'];
$box61e = $_POST['box61e'];
$box61ee = $_POST['box61ee'];
$box73a = $_POST['box73a'];
$box73b = $_POST['box73b'];
$box73c = $_POST['box73c'];
$box74a = $_POST['box74a'];
$box74b = $_POST['box74b'];
$box74c = $_POST['box74c'];
$box74d = $_POST['box74d'];
$box74e = $_POST['box74e'];
$box74f = $_POST['box74f'];
$box74g = $_POST['box74g'];
$box74h = $_POST['box74h'];
$box74i = $_POST['box74i'];
$box74j = $_POST['box74j'];
$box75a = $_POST['box75a'];
$box75b = $_POST['box75b'];
$box75c = $_POST['box75c'];
$box75d = $_POST['box75d'];
$box75e = $_POST['box75e'];
$box75f = $_POST['box75f'];
$box75g = $_POST['box75g'];
$box75h = $_POST['box75h'];
$box75i = $_POST['box75i'];
$box75j = $_POST['box75j'];
$box75k = $_POST['box75k'];
$box75l = $_POST['box75l'];
$box75m = $_POST['box75m'];
$box75n = $_POST['box75n'];
$box75o = $_POST['box75o'];
$box75p = $_POST['box75p'];
$box75q = $_POST['box75q'];
$box75r = $_POST['box75r'];
$box78a = $_POST['box78a'];
$box78b = $_POST['box78b'];
$box78c = $_POST['box78c'];
$box78d = $_POST['box78d'];
$box78e = $_POST['box78e'];
$box78f = $_POST['box78f'];
$box78g = $_POST['box78g'];
$box78h = $_POST['box78h'];
$box78i = $_POST['box78i'];
$box78j = $_POST['box78j'];
$box78k = $_POST['box78k'];
$box78l = $_POST['box78l'];
$box78m = $_POST['box78m'];
$box79a = $_POST['box79a'];
$box79b = $_POST['box79b'];
$box79c = $_POST['box79c'];
$box79d = $_POST['box79d'];
$box91a = $_POST['box91a'];
$box91b = $_POST['box91b'];
$box91c = $_POST['box91c'];
$box92a = $_POST['box92a'];
$box92b = $_POST['box92b'];
if ($q11a == -1){
$naarrival = $naarrival + 1;
}
if ($q12a == -1){
$naarrival = $naarrival + 1;
}
if ($q14a == -1){
$naarrival = $naarrival + 1;
}
if ($q15a == -1){
$naarrival = $naarrival + 1;
}
if ($q26a == -1){
$nadining = $nadining + 1;
}
if ($q31a == -1){
$nadining = $nadining + 1;
}
if ($q32a == -1){
$nadining = $nadining + 1;
}
if ($q44a == -1){
$nadining = $nadining + 1;
}
if ($q45a == -1){
$nadining = $nadining + 1;
}
if ($q78a == -1){
$naproduct = $naproduct + 1;
}
if ($q81a == -1){
$naproduct = $naproduct + 1;
}
if ($q83a == -1){
$napayment = $napayment + 1;
}
$arrival_na1 = $naarrival;
$arrival_ppna1 = 14 - $arrival_na1;
$totalarrival = $q11a + $q12a + $q13a + $q14a + $q15a + $q16a + $q17a + $q18a;
$arrival_score1 = $totalarrival / $arrival_ppna1 *100;
$dining_na1 = $nadining;
$dining_ppna1 = 31 - $dining_na1;
$totaldining = $q19a + $q20a + $q21a + $q22a + $q23a + $q24a + $q25a + $q26a + $q27a + $q28a + $q29a + $q30a + $q31a + $q32a + $q33a + $q34a + $q35a + $q36a + $q37a + $q38a + $q39a + $q40a + $q41a + $q42a + $q43a + $q44a + $q45a + $q46a + $q47a + $q48a + $q49a;
$dining_score1 = $totaldining / $dining_ppna1 *100;
$ordering_na1 = $naordering;
$ordering_ppna1 = 28 - $ordering_na1;
$totalordering = $q50a + $q51a + $q52a + $q53a + $q54a + $q55a + $q56a + $q57a;
$ordering_score1 = $totalordering / $ordering_ppna1 *100;
$product_na1 = $naproduct;
$product_ppna1 = 47 - $product_na1;
$totalproduct = $q58a + $q59a + $q60a + $q61a + $q62a + $q63a + $q64a + $q65a + $q66a + $q67a + $q68a + $q69a + $q70a + $q71a + $q72a + $q73a + $q74a + $q75a + $q76a + $q78a + $q78a1 + $q79a + $q79a1 + $q80a + $q81a;
$product_score1 = $totalproduct / $product_ppna1 *100;
$payment_na1 = $napayment;
$payment_ppna1 = 6 - $payment_na1;
$totalpayment = $q82a + $q83a + $q84a + $q85a;
$payment_score1 = $totalpayment / $payment_ppna1 *100;
$totalattentiveness1 = ($q16a + $q18a + $q51a + $q52a + $q55a + $q57a + $q85a) / 19 * 100;
$totalaccuracy1 = ($q50a + $q54a + $q56a) / 8 * 100;
$totalspeed1 = $q53a / 8 * 100;
$totalfriendliness1 = ($q17a + $q84a) / 6 * 100;
$totalpresentation1 = ($q63a + $q64a + $q67a + $q72a) / 5 * 100;
$totaltaste1 = ($q59a + $q61a + $q70a + $q71a + $q79a + $q80a) / 14 * 100;
$totalquality1 = ($q58a + $q60a + $q62a + $q65a + $q66a + $q68a + $q69a + $q73a + $q74a + $q75a + $q76a + $q78a + $q78a1 + $q79a1 + $q81a) / 28 * 100;
$total1 = $arrival_na1 + $dining_na1 + $ordering_na1 + $product_na1 + $payment_na1;
$total2 = $arrival_ppna1 + $dining_ppna1 + $ordering_ppna1 + $product_ppna1 + $payment_ppna1;
$total3 = $totalarrival + $totaldining + $totalordering + $totalproduct + $totalpayment;
$percentage = ($total3 / $total2) * 100;
if ($percentage >= 86) {
$grade = "A";
} else if ($percentage >= 70) {
$grade = "B";
} else if ($percentage >= 55) {
$grade = "C";
} else {
$grade = "D";
}
mysql_select_db("testing", $con) or die('Error:' .mysql_error());
$insert_query = "UPDATE a_team SET
date='$date',
q11a='$q11a',
q12a='$q12a',
q13a='$q13a',
q14a='$q14a',
q15a='$q15a',
q16a='$q16a',
q17a='$q17a',
q18a='$q18a',
q19a='$q19a',
q20a='$q20a',
q21a='$q21a',
q22a='$q22a',
q23a='$q23a',
q24a='$q24a',
q25a='$q25a',
q26a='$q26a',
q27a='$q27a',
q28a='$q28a',
q29a='$q29a',
q30a='$q30a',
q31a='$q31a',
q32a='$q32a',
q33a='$q33a',
q34a='$q34a',
q35a='$q35a',
q36a='$q36a',
q37a='$q37a',
q38a='$q38a',
q39a='$q39a',
q40a='$q40a',
q41a='$q41a',
q42a='$q42a',
q43a='$q43a',
q44a='$q44a',
q45a='$q45a',
q46a='$q46a',
q47a='$q47a',
q48a='$q48a',
q49a='$q49a',
q50a='$q50a',
q51a='$q51a',
q52a='$q52a',
q53a='$q53a',
q54a='$q54a',
q55a='$q55a',
q56a='$q56a',
q57a='$q57a',
q58a='$q58a',
q59a='$q59a',
q60a='$q60a',
q61a='$q61a',
q62a='$q62a',
q63a='$q63a',
q64a='$q64a',
q65a='$q65a',
q66a='$q66a',
q67a='$q67a',
q68a='$q68a',
q69a='$q69a',
q70a='$q70a',
q71a='$q71a',
q72a='$q72a',
q73a='$q73a',
q74a='$q74a',
q75a='$q75a',
q76a='$q76a',
q78a='$q78a',
q78a1='$q78a1',
q79a='$q79a',
q79a1='$q79a1',
q80a='$q80a',
q81a='$q81a',
q82a='$q82a',
q83a='$q83a',
q84a='$q84a',
q85a='$q85a',
totalarrival='$totalarrival',
arrival_score1='$arrival_score1',
totaldining='$totaldining',
dining_score1='$dining_score1',
totalordering='$totalordering',
ordering_score1='$ordering_score1',
totalproduct='$totalproduct',
product_score1='$product_score1',
totalpayment='$totalpayment',
payment_score1='$payment_score1',
totalattentiveness1='$totalattentiveness1',
totalaccuracy1='$totalaccuracy1',
totalspeed1='$totalspeed1',
totalfriendliness1='$totalfriendliness1',
totalpresentation1='$totalpresentation1',
totaltaste1='$totaltaste1',
totalquality1='$totalquality1',
timein='$timein',
HOR='$HOR',
MODa='$MODa',
KL='$KL',
ateambox='$ateambox',
box35='$box35',
box36='$box36',
box41='$box41',
box50='$box50',
box53='$box53',
box54='$box54',
box55='$box55',
box61a='$box61a',
box61aa='$box61aa',
box61b='$box61b',
box61bb='$box61bb',
box61c='$box61c',
box61cc='$box61cc',
box61d='$box61d',
box61dd='$box61dd',
box61e='$box61e',
box61ee='$box61ee',
box73a='$box73a',
box73b='$box73b',
box73c='$box73c',
box74a='$box74a',
box74b='$box74b',
box74c='$box74c',
box74d='$box74d',
box74e='$box74e',
box74f='$box74f',
box74g='$box74g',
box74h='$box74h',
box74i='$box74i',
box74j='$box74j',
box75a='$box75a',
box75b='$box75b',
box75c='$box75c',
box75d='$box75d',
box75e='$box75e',
box75f='$box75f',
box75g='$box75g',
box75h='$box75h',
box75i='$box75i',
box75j='$box75j',
box75k='$box75k',
box75l='$box75l',
box75m='$box75m',
box75n='$box75n',
box75o='$box75o',
box75p='$box75p',
box75q='$box75q',
box75r='$box75r',
box78a='$box78a',
box78b='$box78b',
box78c='$box78c',
box78d='$box78d',
box78e='$box78e',
box78f='$box78f',
box78g='$box78g',
box78h='$box78h',
box78i='$box78i',
box78j='$box78j',
box78k='$box78k',
box78l='$box78l',
box78m='$box78m',
box79a='$box79a',
box79b='$box79b',
box79c='$box79c',
box79d='$box79d',
box91a='$box91a',
box91b='$box91b',
box91c='$box91c',
box92a='$box92a',
box92b='$box92b',
arrival_na1='$arrival_na1',
arrival_ppna1='$arrival_ppna1',
dining_na1='$dining_na1',
dining_ppna1='$dining_ppna1',
ordering_na1='$ordering_na1',
ordering_ppna1='$ordering_ppna1',
product_na1='$product_na1',
product_ppna1='$product_ppna1',
payment_na1='$payment_na1',
payment_ppna1='$payment_ppna1',
total1='$total1',
total2='$total2',
total3='$total3',
percentage='$percentage',
grade='$grade' WHERE entry='$entry'";
mysql_query($insert_query) or die('Error:' . mysql_error());
mysql_close($con);
}
?>
Check whether you insert query give the correct query or not
echo $insert_qury="update query ";
and copy the output of insert query and test manually to past on sql in table it it update correctly then you query is correct and your error may be on "mysql_query"
You have put everything inside single quote...
Try this:
$insert_query = "UPDATE a_team SET
date='".$date."',
q11a='".$q11a."',
q12a='".$q12a."',..... WHERE entry='".$entry."'";