![]() |
|
|
#1 |
|
Member
Join Date: Dec 2001
Location: East Sussex / London
Posts: 1,541
|
PHP talent required
Hi all,
I'm near the end of my college and i need to hand in my final project but i am currently stuck and would like to get some get with it. This may be the wrong site but i cba to register to another forum when i'm only going to use it one time only. anyway. I want to create a way that user will have some privileges than normal register users. in my DB table i have something like this: ![]() In my PHP codes, i have: ![]() Where is says $userAccount = $query[1]; does that mean is it will find that row with a 1 in it? and also if ($userAccount == 1){ }else{ } that means that $userAccount is equal to 1 will show whatever or ELSE? |
|
|
|
|
|
#2 |
|
Member
Join Date: Aug 2005
Location: UK
Posts: 1,688
|
Re: PHP talent required
A little new to PHP here so a bit of guessing here. query is an array object so $query[1] will return whatever value is associated with key/index 1. It won't find which column has the value of 1.
What you probably want is: Code:
$account = runQuery("SELECT account FROM memberLogin WHERE username = '$user' AND id = '$id'");
$query = mysql_fetch_row($account);
$userAccount = $query[0];
|
|
|
|
|
|
#3 |
|
Member
Join Date: Dec 2001
Location: East Sussex / London
Posts: 1,541
|
Re: PHP talent required
Thanks for the reply yaustar but unfortunately for me, it didn't work.
dont worry about it, tomorrow i have a one-to-one lesson with my tutor. doesn't seem i'm getting much talk here. i guess i have to get my lazy bum in gear and register a proper php nerd website to get more help. |
|
|
|
|
|
#4 |
|
Member
Join Date: Jun 2008
Location: .
Posts: 1,110
|
Re: PHP talent required
i'm not php guru, but have done a little bit.
$query = mysql_fetch_row($account); mysql_fetch_row will only return the first row of data, FALSE otherwise. you should check for this to prevent your script from failure when it happens. assuming the columns are in the order as they are in the diagram, then $query[0] is the id. $query[1] is the username. $query[2] is the password. $query[3] is the name. $query[4] is the email. $query[5] is the account. also your code is susceptible to hacking by sql injection. use mysql_real_escape_string() function to prevent this. |
|
|
|
|
|
#5 |
|
Member
Join Date: Oct 2000
Location: the burbs
Posts: 1,325
|
Re: PHP talent required
I haven't done php for like 5 years but I would've used;
Code:
$query = mysql_fetch_assoc($account); $userAccount=$query["account"] |
|
|
|
|
|
#6 |
|
Member
Join Date: Dec 2001
Location: East Sussex / London
Posts: 1,541
|
Re: PHP talent required
Thanks for the help guys.. Yea, i did what den done.
Code:
$userAccount = $query['account']
if($userAccount == 1){
}else{
}
|
|
|
|
|
|
#7 | |
|
Member
Join Date: Dec 2001
Location: East Sussex / London
Posts: 1,541
|
Re: PHP talent required
Quote:
|
|
|
|
|
|
|
#8 |
|
Member
Join Date: Aug 2005
Location: UK
Posts: 1,688
|
Re: PHP talent required
Did my code still returned the whole row of data?
|
|
|
|
|
|
#9 |
|
Member
Join Date: Dec 2001
Location: East Sussex / London
Posts: 1,541
|
Re: PHP talent required
|
|
|
|
![]() |
| Thread Tools | |
|
|