₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,326,945 members, 8,428,754 topics. Date: Wednesday, 17 June 2026 at 10:27 PM

Toggle theme

How Do I Add A Variable Within Mysqli Query - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingHow Do I Add A Variable Within Mysqli Query (1391 Views)

1 Reply (Go Down)

How Do I Add A Variable Within Mysqli Query by ANTONINEUTRON(op): 1:58pm On Sep 26, 2016
Pls Guys

I ave hit a stumbling block and i need ur help.

Here Is D Query

$res = "SELECT * FROM `user` WHERE `userid` = '$userid'"

$result = mysqli_query($conn,$res);


Now D Problem Is If i loop through $result to get d row result(d user information),
I Get Notin.

And NB: 1. $userid Is Gotten Thru Global Variable $Post[] Where User Input Thier Id.


2. If I Use Let Say '12' In Place Of $userid It Return D Info.
Re: How Do I Add A Variable Within Mysqli Query by Dangujba1111: 2:08pm On Sep 26, 2016
ANTONINEUTRON:
Pls Guys

I ave hit a stumbling block and i need ur help.

Here Is D Query

$res = "SELECT * FROM `user` WHERE `userid` = '$userid'"

$result = mysqli_query($conn,$res);


Now D Problem Is If i loop through $result to get d row result(d user information),
I Get Notin.

And NB: 1. $userid Is Gotten Thru Global Variable $Post[] Where User Input Thier Id.


2. If I Use Let Say '12' In Place Of $userid It Return D Info.
i dont Really understand your question but i think this will solve your problem
$result = mysqli_fetch_array($res);
$nameyourvariable = $result["yourrow"];
Re: How Do I Add A Variable Within Mysqli Query by ANTONINEUTRON(op): 2:14pm On Sep 26, 2016
Dangujba1111:
i dont Really understand your question but i think this will solve your problem
$result = mysqli_fetch_array($res);
$nameyourvariable = $result["yourrow"];
It Is Not Displaying D Query(converting It To And Array) That Is D Problem, D Problem Is D Query Isn't Returning Any Result/Info That Will Be Display
Re: How Do I Add A Variable Within Mysqli Query by Dangujba1111: 5:42pm On Sep 26, 2016
ANTONINEUTRON:
It Is Not Displaying D Query(converting It To And Array) That Is D Problem, D Problem Is D Query Isn't Returning Any Result/Info That Will Be Display
firstly, you have check if the id exists or not using $check = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM user WHERE userid = '$userid'"wink);
if($check < 1){
echo "No ID exists";
}
Re: How Do I Add A Variable Within Mysqli Query by noordean(m): 6:43pm On Sep 26, 2016
ANTONINEUTRON:
Pls Guys

I ave hit a stumbling block and i need ur help.

Here Is D Query

$res = "SELECT * FROM `user` WHERE `userid` = '$userid'"

$result = mysqli_query($conn,$res);


Now D Problem Is If i loop through $result to get d row result(d user information),
I Get Notin.

And NB: 1. $userid Is Gotten Thru Global Variable $Post[] Where User Input Thier Id.


2. If I Use Let Say '12' In Place Of $userid It Return D Info.
1. Why are you putting the database table and table field userid in quote?
They would be seen as strings that way.
2. Your $userid variable shouldn't have quote , it represents integer values.

So i think your query should look like this:

$res="SELECT * FROM user WHERE userid=$userid"
Re: How Do I Add A Variable Within Mysqli Query by ANTONINEUTRON(op): 9:37pm On Sep 26, 2016
noordean:
1. Why are you putting the database table and table field userid in quote? They would be seen as strings that way. 2. Your $userid variable shouldn't have quote , it represents integer values.
So i think your query should look like this:
$res="SELECT * FROM user WHERE userid=$userid"
Thanks I'll Try It Right Away
Re: How Do I Add A Variable Within Mysqli Query by Fulaman198(m): 1:19pm On Jul 14, 2017
Please let me know if you are still having any problems.
1 Reply

Java Programmers - How Do I Pass Variable Value From A Classa To Another ClassbWhat The Difference In Local, Global, Static Variable DeclearationAdd A Dictionary To A Grid234

A Chat Bot In Memory Of My Late DadGood Programmer Is NeededHow Do I Start My Own Cybersecurity Firm