PDA

View Full Version : PHP Help!


rbren90
12-12-2007, 07:56 PM
Hi,

I am currently making a system but I am slightly stuck - im a bit of a rookie at php developmet. Any help would be great!

Basically I am using PHP to pull information from a database based on url info - i.e GET function. So i want to pull information from the DB where group = 1 - easy enuff so far, with the URL saying group.php?group=1

but now i want it to pull from the DB where group = 1 AND 3, but i cant seem to get this to work, iv tried group.php?group=1,2 group.php?group=1&2 but none of this is working..

any help is greatly appreciated!
thanks
Ryan

richardh
12-12-2007, 08:03 PM
Hi Ryan.

My advice to you would be to read up on some beginner PHP tutorials or purchase a book on it. If you're running into problems at this stage, then things are only going to get worse (for you and your clients).

That said:-

script.php?groups[]=1&groups[]=2

<?php
$groups = $_GET['groups'];
var_dump($groups);
?>


Make sure you're using something like mysql_real_escape_string() on the user input.

bluecube
12-12-2007, 08:06 PM
Originally posted by richardh

Make sure you're using something like mysql_real_escape_string() on the user input.

Spoil sport... :)

RichardJohn
12-12-2007, 08:06 PM
Is this being used on a production site?
I wouldn't advise it... if you're running into problems with GET variables, there's likely to be exploits in the script.

richardh
12-12-2007, 08:09 PM
Originally posted by bluecm
Spoil sport... :)

Haha :P

rbren90
12-12-2007, 08:12 PM
Thanks a lot, thats perfect..

and yeh im using mysql_escape_string

i probably should have taken off the zinkdesign sig, im only really designing for clients not coding at the minute.. im only 17 and still learnin btw:

If you're running into problems at this stage, then things are only going to get worse (for you and your clients).


!!

thanks for the advice

ryan

richardh
12-12-2007, 08:13 PM
Another option Ryan:-

script.php?groups=1,2,3

<?php
$groups = explode(",", $_GET['groups']);
var_dump($groups);
?>

rbren90
12-12-2007, 08:14 PM
@RichardJohn

listen, enough with the givin off about my capabilities, its a personal project and i am aware of exploits etc. so thanks for the advice but theres really no need for the patronising

appreciate the help richardh :)

bluecube
12-12-2007, 08:17 PM
Originally posted by rbren90
im only 17 and still learnin btw:


Not a problem, just stick at it, you could do with getting your hands on a good book though and working through it just to give you a foundation to build on.

Then there are several online resources you can use for further reference

i.e. - http://www.php.net

Hope this helps

bluecube
12-12-2007, 08:18 PM
Originally posted by rbren90
@RichardJohn

listen, enough with the givin off about my capabilities, its a personal project and i am aware of exploits etc. so thanks for the advice but theres really no need for the patronising

appreciate the help richardh :)

I dont think he was havin a go mate I think he was just trying to give some friendly advice :)

HTH

Nathan

rbren90
12-12-2007, 08:18 PM
thanks, iv been thinkin about investing in a book so i think ill have to have a look on amazon soon!

thats fair enuff, i kinda jst got annoyed over nuthin there lol

apologies, its just been a busy week

cheers again for all ur advice
ryan

RichardJohn
12-12-2007, 08:21 PM
I wasn't being patronising, I was just advising against using code on production sites whilst you're still learning!

rbren90
12-12-2007, 08:24 PM
thats cool, apologies im jst a bit touchy lol. my age seems to make my credibility go wayy down a lot when im designing etc. so just a little edgy with it.. i didnt mean to snap lol

you're right tho, iv kinda jumped in the deep end, i need to start at the beginning :)

cheers
ryan

awebapart
12-12-2007, 08:28 PM
Originally posted by rbren90
i want it to pull from the DB where group = 1 AND 3There are a number of ways of doing this but you might also need to read up on SQL or mySQL:

select *
from tablename
where groupid = 1

is OK

select *
from tablename
where groupid = 1 AND 3

is really saying

select *
from tablename
where groupid = 1
and 3

where 3 is a boolean expression which is always true (because it is non zero), so it is redundant. What you are really after is something ilke:

select *
from tablename
where groupid = 1
or groupid = 3

or maybe

select *
from tablename
where groupid in ( 1, 3 )

gnu
14-12-2007, 03:35 PM
Originally posted by rbren90

but now i want it to pull from the DB where group = 1 AND 3, but i cant seem to get this to work, iv tried group.php?group=1,2 group.php?group=1&2 but none of this is working..

Ryan

If you are passing parameters in the URL you need:

group.php?group=1&group2=2&group3=3

If it is the database query you are struggling with then have a read of:

http://www.w3schools.com/sql/default.asp

Also, get a copy of phpMyAdmin installed on your host / or pc, with that you can execute queries directly in the database and get them working in SQL... then build the same statement in your code...