hey guys welcome back so guys
in this video we are going to learn
about how to fetch the data
by id in a text box so guys
i have created one students table where
inside that i have few records
over here so let's let's fetch this
records by
its id so let's get started with this
let's move to our editor so guys i'm
using bootstrap 5
to design this user interface and now
let's begin with
designing it so let's create a row
and column md 7
let's make it to 8 and then
column md 4 and
inside this i wanted input type
dot form control
here name is equal to which will be
student id
and in this form we are going to use
button
search the button type will be
submit and let's design this button
button button primary save
and let's see the output so you can see
guys one input with the search button
so if we click on this the data good
should search with that
so let's now let's begin with it so
let's create a form tag
form ctrl
x and end the form over here
let's give the method method
is equal to get and if we click this
button
the time this student id will be called
let's come over here refresh let's give
one
search you can see the id number one is
sent over here
let me click where the fourth data has
gone so let's fetch this
data into this input box if it is
searched means
so let's call that
it's very simple use the value where
open php and close php
type if condition with the set function
you are going to check
that the parameter of student id is
passed or not
so let us copy this parameter student id
open kali and curly braces
and let's echo this your student id
parameter
we have semicolon save and let's refresh
you can see that output so guys now let
us give two
you can see two and over here also two
so now let's
fetch the data according to this id
let's start
let's create one simple row not this
will come out of this
form so this is my form let's come out
let's create one simple row inside this
column md12
and over here form group
input dot form hyphen control
to create the input box let's
give the value is equal to null right
now we are going to fetch all the
details of your student
let's give a label where student name
will be
let's copy this and paste again class
and the phone number so let's replace
that
class for
number done so these details are nothing
but
the database column names where you can
see student class and student phone
so this is my table called student so we
are going to fetch this data let's get
back
and now guys let's type the code to
fetch the data so before fetching i want
to show you the output of this
refresh you can see that output
let's get back let's give one horizontal
row
and let's type the code so open php and
close php
where first database connection will be
given so dollar con
where mysql i underscore connect
function and localhost
where you are going to type root and the
password is
null and my database name is
php tutorials so let's copy
and paste and let's type the query
dollar query and to fetch the record
select star from my table name
student let's copy that and paste
where
id is equal to inside this single quote
you have to pass the id
so before passing any id over here you
need to check that from where you are
getting that id
so let's choose if condition to check
that parameter is set or not so what
parameter you are going to check
is nothing but your student id so let's
call the student id
and check over here so you can check
with the asset function
dollar underscore get method where you
are going to send this
if it is set then you are coming inside
this so let's give dollar
student underscore id and
get that id from this parameter called
student id
paste now your student id stored over
here
and let's run this query inside this if
condition
now you have to fetch this if it is set
your student id will fetch and now let's
run this above
query copy paste
underscore run is equal to
mysqli underscore query function so
this function will run your statement
with the help of database connection so
first call the
connection of your database and then the
statement let's paste
and now guys let us check if the record
exist or not
into this table use mysqli
number of rows function
if it is greater than 0 then only
display the record
else you can
echo no
record found
done so if the record is found use for
each loop
to print that record let's
find if the record exists as
dollar row so this row will help you to
find that
your column name inside this so row of
your
column name is nothing but the
student underscore name stud underscore
name
underscore name let's save
and refresh and check that refresh you
can get on prakash with the id number
two over here you can see id number two
that is data so let's now let us fetch
this detail into a
text box get back let's comment this
and divide this so php close and php
open now
let us just ctrl x
and paste over here
let's call this student name
let's remove inside this value
we have to fetch php open php is equal
to where close php
and this is equal to is a shortcut
method to echo the
data so let's use this
copy and paste again paste again and
change the
column name as class and
phone save and let's check the output
you can see that the data has fetched in
a text box
so let's check with the id number five
search you can get this
id number one
search you can get that with practice
data so
this is how we search if you give
non-existing record
so let us see over here you can see that
its total eight records is there
we searched with eight you can got that
okay man so now
let us search with the ninth record
where it is not
existing let's see no record found you
are getting that
so guys this is how we do that how to
fetch
the id in text box using php so guys in
this video that's it and thank you for
watching this video please subscribe
like and share