British Chinese Online Discussion Board  

Go Back   British Chinese Online Discussion Board > The Tea House > The Study

The Study For students and young people.

Reply
 
Thread Tools
Old 1st February 2010, 04:29 PM   #1
chillerkid
Member
 
chillerkid's Avatar
 
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?
chillerkid is offline   Reply With Quote
Old 7th February 2010, 06:44 AM   #2
yaustar
Member
 
yaustar's Avatar
 
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];
__________________
[Blog] [Portfolio] [Homebrew Illuminati]
yaustar is online now   Reply With Quote
Old 8th February 2010, 07:12 PM   #3
chillerkid
Member
 
chillerkid's Avatar
 
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.
chillerkid is offline   Reply With Quote
Old 8th February 2010, 09:35 PM   #4
Jack Slack
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.
Jack Slack is offline   Reply With Quote
Old 9th February 2010, 10:06 AM   #5
den
Member
 
den's Avatar
 
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"]
I'd explicitly "select account from memberLogin ...", never rely on the ordering of SQL columns as database schema's do change, and never use random indexes when you can use tagged values as you'll go insane when debugging.
den is offline   Reply With Quote
Old 9th February 2010, 10:10 PM   #6
chillerkid
Member
 
chillerkid's Avatar
 
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{

}
makes sense after you get it to work.
chillerkid is offline   Reply With Quote
Old 9th February 2010, 10:12 PM   #7
chillerkid
Member
 
chillerkid's Avatar
 
Join Date: Dec 2001
Location: East Sussex / London
Posts: 1,541
Re: PHP talent required

Quote:
Originally Posted by Jack Slack View Post
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.
my friend also told me to do it. he showed me how easily it could be hacked by didn't work for him lol. never the less, i added it in.
chillerkid is offline   Reply With Quote
Old 10th February 2010, 01:54 PM   #8
yaustar
Member
 
yaustar's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 1,688
Re: PHP talent required

Did my code still returned the whole row of data?
__________________
[Blog] [Portfolio] [Homebrew Illuminati]
yaustar is online now   Reply With Quote
Old 10th February 2010, 08:32 PM   #9
chillerkid
Member
 
chillerkid's Avatar
 
Join Date: Dec 2001
Location: East Sussex / London
Posts: 1,541
Re: PHP talent required

Quote:
Originally Posted by yaustar View Post
Did my code still returned the whole row of data?
nah.. nothing worked. what you did was similiar to what i done first time.

not sure why doesn't it doesn't put them in an array. Like jack said, i thought it was how PHP reads columns :s
chillerkid is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 09:43 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.