₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,345,532 members, 8,518,095 topics. Date: Friday, 13 November 2026 at 02:00 PM

Toggle theme

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

Nairaland Forum › Science/Technology › Programming › How Do I Add A Variable Within Mysqli Query (1432 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 Classb • What The Difference In Local, Global, Static Variable Declearation • Add A Dictionary To A Grid • 2 • 3 • 4

Mark Zuckerberg Introduced His New Artificial Intelligence Named JARVIS • 10 Concept Every Software Developers Should Know Before 2018 • What Is Programming And Why Should I Learn It?