Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,182 members, 7,821,998 topics. Date: Thursday, 09 May 2024 at 12:28 AM

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 (1263 Views)

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)

(1) (Reply) (Go Down)

How Do I Add A Variable Within Mysqli Query by ANTONINEUTRON(m): 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(m): 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"

1 Like

Re: How Do I Add A Variable Within Mysqli Query by ANTONINEUTRON(m): 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)

[FREE] Encryption Tools Sha 256-512 AES 256-512-128 And Many More! / Get Paid For Writing Just HTML And Javascript Codes / Please Who Can Build A Nairaland Like Forum?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 15
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.