mysql select statement is not taking space in consideration [duplicate] - php

This question already has answers here:
How to set HTML value attribute (with spaces)
(6 answers)
extracting the html form option value which has spaces in bitween [duplicate]
(4 answers)
Closed last month.
I want to data in my table tbljobcategory but for example , if the return data is Infomation and Technology it is only returning Infomation...
<?php
$stmt = $pdo->prepare("select * from tbljobcategory where category_id=:catid");
$stmt -> execute(array(":catid"=>$_GET["catid"]));
$rows = $stmt ->fetch(PDO::FETCH_ASSOC);
$CategoryName = htmlspecialchars($rows["Category"]);
?>
<div class="card text-center form-add" style="width:35%;">
<div class="card-header">
Edit Job Category
</div>
<div class="card-body">
<form method="post" action="">
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Current Job Category</label>
<input class="form-control" type="text" value=<?php echo "$CategoryName " ;?> disabled readonly>
</div>
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label">New Job Category</label>
<input class="form-control" type="text" name="NCategory" placeholder="New Job Category" aria-label="default input example">
</div>
<button type="submit" name="btn-update" class="btn btn-primary">Save Changes</button>
<button type="submit" name="btn-cancel" class="btn btn-secondary">Cancel</button>
</div>
</form>

Related

PHP in a smarty tpl file $_POST doesnt work

in my where i use smarty to connect everything tpl file i have a form
<form method="post">
<div class="form-group"><label for="address"><strong>Address</strong></label><input class="border rounded-pill form-control" type="text" value='{$address}' name="address"></div>
<div class="form-row">
<div class="col">
<div class="form-group"><label for="city"><strong>City</strong></label><input class="border rounded-pill form-control" type="text" value='{$city}' name="city"></div>
</div>
<div class="col">
<div class="form-group"><label for="country"><strong>Country</strong></label><input class="border rounded-pill form-control" type="text" value='{$country}' placeholder="The Netherlands" name="country"></div>
</div>
</div>
<div class="form-group"><label for="phonenumber"><strong>Phone Number</strong></label><input class="border rounded-pill form-control" type="text" value='{$phone}' placeholder="+1 (0)1 234 56 789" name="phonenumber"></div>
</div>
<div class="card-body" style="background: #f5f5f5;">
<button class="btn btn-primary btn-sm" type="submit" name="contactsend">Save Settings</button>
</div>
</div>
</form>
But if i try to contact it in my php file
if(isset($_POST['contactsend'])) {
$inaddress = mysqli_real_escape_string($db, $_POST['address']);
$incity = mysqli_real_escape_string($db, $_POST['city']);
$insert = $db->query("UPDATE accounts SET address = ".$inaddress.", city = ". $incity ." WHERE id = ".$id_user."");
}
it wont get the contactsend button if i press it, so it also wont update the tables. can someone please help me?
that form is posting to it's own page ... is the php script in the same file as the render script? If not you need to set the action="" attribute of the form to the php script url

Can I block one table from updating?

I have two tables in my database one practitioner and the second one practitioner_specialty, both of them have fields effective_date and expiry_date. When I use the form to update both if those tables the last effective_date and expiry_date are being saved to both of the tables instead of two separate ones.
Is there a way to block one table from updating so I can update only the second one, or maybe is there a way to save it using different id/name so they will be unique ones for practitioner and practitioner_specialty?
Here are my form and controller used for updating tables.
Controller:
public function updatePractitioner(Request $request, $id)
{
$this->validate($request, [
'effective_date' => 'required',
]
);
$fields = $request->all();
$primary_key = $this->PractitionerRepository->getIdName();
$primary_key_specialty = $this->PractitionerSpecialtyRepository->getIdName();
$practitioner_specialty_id = PractitionerSpecialty::where('practitioner_id', $id)->value('practitioner_specialty_id');
$fields[$primary_key] = $id;
$this->PractitionerRepository->update($fields);
$fields[$primary_key_specialty] = $practitioner_specialty_id;
$this->PractitionerSpecialtyRepository->update($fields);
return back()->with('successUpdate', 'Practitioner has been updated!');
}
update form in blade.php :
<div class="edit-practitioner" style="display: none;">
<form style="box-shadow: none;" action="/practitioner/update/{{$practitioner->practitioner_id}}" method="post"
class="j-pro" id="update-practitioner-form">
{{ csrf_field() }}
<div class="j-content">
<div id="j-row-id" class="j-row">
<div class="row">
<div class="col-sm-12 col-lg-12 col-xl-5">
<div class=" j-unit">
<div class="j-divider-text j-gap-top-20 j-gap-bottom-45">
<span>Practitioner Information</span>
</div>
<label class="j-label">{{trans('personalData.effectiveDate')}}</label>
<div class="j-input">
<input type="date" value="{{$practitioner->effective_date}}"
name="effective_date" id="effective_date">
</div>
<label class="j-label">{{trans('personalData.expiryDate')}}</label>
<div class="j-input">
<input type="date" value="{{$practitioner->expiry_date}}"
name="expiry_date" id="expiry_date">
</div>
<label class="j-label">{{trans('personalData.phoneNumber')}}</label>
<div class="j-input">
</label>
<input type="tel" value="{{$practitioner->phone}}"
name="phone" id="phone">
</div>
<label class="j-label">{{trans('personalData.mobileNumber')}}</label>
<div class="j-input">
<input type="tel" value="{{$practitioner->mobile}}"
name="mobile" id="mobile">
</div>
<label class="j-label">{{trans('personalData.email')}}</label>
<div class="j-input">
<input type="email" value="{{$practitioner->email}}"
name="email" id="email">
</div>
</div>
</div>
<div class="col-xl-1 j-unit"></div>
<div class="col-sm-12 col-lg-12 col-xl-6">
<div class="j-divider-text j-gap-top-20 j-gap-bottom-45">
<span>{{trans('settings.specialty')}}</span>
</div>
<select name="practitioner_specialty_id_update"
id="practitioner_specialty_id_update"
class="form-control-practitioner required">
#foreach($specialties as $specialty)
<option
value="{{$specialty->specialty_id}}">{{$specialty->name}}</option>
#endforeach
</select>
<label class="j-label">{{trans('personalData.effectiveDate')}}</label>
<div class="j-input">
#isset($practitioner_specialty->practitioner_specialty_id)
<input type="date" value="{{$practitioner_specialty->effective_date}}"
name="effective_date" id="effective_date">
#endisset
#empty($practitioner_specialty->practitioner_specialty_id)
<input type="date" name="effective_date" id="effective_date">
#endempty
</div>
<label class="j-label">{{trans('personalData.expiryDate')}}</label>
<div class="j-input">
#isset($practitioner_specialty->practitioner_specialty_id)
<input type="date" value="{{$practitioner_specialty->expiry_date}}"
name="expiry_date" id="expiry_date">
#endisset
#empty($practitioner_specialty->practitioner_specialty_id)
<input type="date" name="expiry_date" id="expiry_date">
#endempty
</div>
</div>
</div>
</div>
<div class="j-divider j-gap-bottom-45 j-gap-top-10"></div>
<button type="submit"
class="btn btn-editpanel btn-success btn-round">Save changes
</button>
<!-- end /.footer -->
<button id="update-cancel-button-practitioner" href="javascript:window.location.href=window.location.href" type="button"
class="btn btn-editpanel btn-danger btn-round">Cancel
</button>
</div>
</form>
</div>
Well you use the same array for both of the tables, hence the reason to update all the fields. You can try to exclude the ones for one form and add them to the other, for example:
$practictionerFields = $request->except('expiry_date', 'effective_date');
$practictionerFields[$primary_key] = $id;
$this->PractitionerRepository->update($practictionerFields);
// and use the other $fields array for the PractitionerSpecialty model.
You can use LOCK query here.
lock is a flag associated with a table. MySQL allows a client session to explicitly acquire a table lock for preventing other sessions from accessing the same table during a specific period. A client session can acquire or release table locks only for itself. It cannot acquire or release table locks for other sessions.
You can read more here: http://mysqltutorial.org/mysql-table-locking

HTML form not passing checkbox value trough $_POST in php file

I have a form in HTML with some checkboxes and I want to send an email with the selected checkboxes in the body, the problem is that the "text" fields are passing to the PHP variables, but the checkboxes values are always set to uncheck when I test it on the PHP file:
HTML:
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control c-check" >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina
</label>
</div>
PHP:
$reservas_bicicletas = '';
if (isset($_POST['checkbox1citadina'])) {
$reservas_bicicletas .= "Citadina: checked\n";
} else {
$reservas_bicicletas .= "Citadina: unchecked\n";
}
echo $reservas_bicicletas;
$reservas_bicicletas always retrieves the else value.
Need help guys, thanks in advance.
remove c-check
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control " >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina</label>
</div>
Basically i have this (i shorted out the form because there are too many elements):
HTML:
<form name="quick_booking" id="quick_booking" method="post" action="assets/reserva-bicicletas.php">
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control " >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina</label>
</div>
<button type="submit" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square">Reservar</button>
</form>

Fatal error of PHP [duplicate]

This question already has answers here:
Isset expression error
(3 answers)
Closed 6 years ago.
I'm doing an admin panel and I'm doing a form for adding users. My code below:
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>Add user</legend>
<!-- Prepended text-->
<div class="form-group">
<label class="col-md-4 control-label" for="newuser">Username</label>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon">#</span>
<input id="newuser" name="newuser" class="form-control" placeholder="Username" type="text" required="">
</div>
<p class="help-block">Put the new users username here</p>
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="userpw">New user password</label>
<div class="col-md-4">
<input id="userpw" name="userpw" type="password" placeholder="Password" class="form-control input-md" required="">
<span class="help-block">Enter new user's password here!</span>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="permissions">Choose permissions</label>
<div class="col-md-4">
<select id="permissions" name="permissions" class="form-control">
<option value="1">System administrator</option>
<option value="2">Editor</option>
<option value="3">Developer</option>
<option value="4">Normal user</option>
</select>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="btn_send">Send request to server</label>
<div class="col-md-4">
<button id="btn_send" name="btn_send" class="btn btn-primary">Send it!</button>
</div>
</div>
</fieldset>
</form>
<?php
$newuser = $_GET['newuser'];
$userpw = $_GET['userpw'];
$permission = $_GET['permissions'];
if(isset($newuser and $userpw and $permission) {
$sql = "INSERT INTO users(username,userpw,permission)VALUES('$newuser', '$userpw','$permission')";
mysql_query($sql);
}
else {
echo "error";}
And I Get:
Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in C:\xampp\htdocs\lumino\usermanagement.php on line 95
I couldn't fix it anyhow, playing with this for like 5 hours.
It's doing $_GET method, so I get the url like:
mysite.com/usermanagement.php?newuser=Berkay&userpw=18042003&permissions=3&btn_send=
Using isset, you can't have multiple items inside it:
if(isset($newuser and $userpw and $permission) {
Needs to become:
if(isset($newuser) && isset($userpw) && isset($permission)) {
Or:
if(isset($newuser, $userpw, $permission)) {
You just miss a ) and a set of ,:
if(isset($newuser, $userpw, $permission)) {
$sql = "INSERT INTO users(username,userpw,permission)VALUES('$newuser', '$userpw','$permission')";
mysql_query($sql);
}

inserting different data with different id on single save button

I do have three fields which are text input which is of type number.these three data are being saved with different ids but on the same save button.i.e i am inserting data into all the field and then clicking on the save button but the my first data is being saved by different id and the same for the rest of two data.for example if i put 1 in first input,2 in second and 3 in the next since these are number type.but 1 is being saved by say by id:11,2 is being saved by say by id:12,3 is being saved by say by id:13.
my view is like below:
<form class="form">
<div class="control-group">
<label class="control-label">High Priority</label>
<div class="controls">
<input type="number"name="sval"id="sval"/>Days
</div>
</div>
<div class="control-group">
<label class="control-label ">Low Priority</label>
<div class="controls">
<input type="number"name="sval" id="sval"/>Days</div>
</div>
<div class="control-group">
<label class="control-label ">Normal</label>
<div class="controls">
<input type="number" name="sval" id="sval"/>Days </div>
</div>
<button id="btn" class="btn btn-primary insert">Save</button>
</form>
and the queries are:
var sqld:String;
sqld = "Delete from app_settings where kunnr = '"+kunnr+"' and ( skey = 'hp_days' or skey = 'np_days' or skey = 'lp_days' )";
wcisql.query(sqld,'clearRDays');
}
public function saveRDays():void{
var sqlu:String;
sqlu = "Insert into app_settings(kunnr,skey,sval) Values ('"+kunnr+"','hp_days','"+hp_days.value+"')";
wcisql.query(sqlu,'saveRDays');
sqlu = "Insert into app_settings(kunnr,skey,sval) Values ('"+kunnr+"','np_days','"+np_days.value+"')";
wcisql.query(sqlu,'saveRDays');
sqlu = "Insert into app_settings(kunnr,skey,sval) Values ('"+kunnr+"','lp_days','"+lp_days.value+"')";
wcisql.query(sqlu,'saveRDays');
$sql = "Select * from app_settings where kunnr = '$kunnr'";
}
i am adding image as well so that u can get better idea:
how to do this please suggest..
and for my view:
use Multiple Insert statement
ckeck out this referenced link:
Multiple INSERT statements vs. single INSERT with multiple VALUES
&
http://www.techonthenet.com/sql/insert.php
The problem is you can only use one ID for each HTML element.
So there are two ways to achieve this, one is dynamic the second is static.
Static Solutions:
<div class="control-group">
<label class="control-label">High Priority</label>
<div class="controls">
<input type="number"name="sval1"id="sval1"/>Days
</div>
</div>
<div class="control-group">
<label class="control-label ">Low Priority</label>
<div class="controls">
<input type="number"name="sval2" id="sval2"/>Days</div>
</div>
<div class="control-group">
<label class="control-label ">Normal</label>
<div class="controls">
<input type="number" name="sval3" id="sval3"/>Days </div>
</div>
<button id="btn" class="btn btn-primary insert">Save</button>
Dynamic Solution
<div class="control-group">
<label class="control-label">High Priority</label>
<div class="controls">
<input type="number" name="sval[]"/>Days
</div>
</div>
<div class="control-group">
<label class="control-label ">Low Priority</label>
<div class="controls">
<input type="number" name="sval[]"/>Days</div>
</div>
<div class="control-group">
<label class="control-label ">Normal</label>
<div class="controls">
<input type="number" name="sval[]"/>Days </div>
</div>
<button id="btn" class="btn btn-primary insert">Save</button>
Now when you post the form the items will come in array so you have an array
$_GET['sval'] or $_POST['sval'] contains array(1,2,3)

Categories