GetDotted Domains

Viewing Thread:
"Argh, problem!"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Thu 24/02/05 at 18:07
Regular
Posts: 10,364
Hi there.

Yet another MYSQL problem/PHP advice thread...

Ok this is the deal.

I have a table called "keyfeatures"

In it contains 3 fields.

"KeyFID" - primary key
"AucID" - secondary key
"Keyfeature" - text

What i'm having problems with is returning all of the values that match the secondary key.

I.e. SELECT * FROM keyfeatures WHERE AucID='$theauc'

How would I return those values?

Say if I had this as sample data and $theauc == 2: -

1 2 "this is data"
2 2 "data"
3 4 "woo this is data"

The query should return the top two piece of data, correct?

What I want to do exactly is put these values into an array (I have an array which can size itself to how many rows match the query) so

$array[0] = "this is data"
$array[1] = "data"

Any advice would be appreciated.
Thu 24/02/05 at 19:04
Regular
"NULL"
Posts: 1,384
If the variable comes from a POST request or similar, it may not be escaped. Check your php.ini file to see whether the magic_quotes_gpc is on or off. If it's on, you don't need to worry, to otherwise you will need to escape your strings.

Basically, imagine an unescaped variable defined as follows:

$var = "'; DELETE * FROM table; SELECT * FROM table WHERE column='";

and entering this into the code similar to yours:

$result = mysql_query("SELECT * FROM table WHERE column='".$var."';");

This would actually give:

$result = mysql_query("SELECT * FROM table WHERE column=''; DELETE * FROM table; SELECT * FROM table WHERE column='';");

As you can see, this deletes all your data from the table. By escaping the string, you will stop characters like ' ; " etc from being processed by MySQL as command symbols, and thus prevent someone maliciously abusing your script.

You can escape many ways, the most logical of which if your version of PHP supports it is mysql_real_escape_string().

EDIT: The PHP Manual isn't a book - it's a download available from the PHP web site. You can get it in CHM format which is the same format as Windows Help files.
Thu 24/02/05 at 18:53
Regular
Posts: 10,364
Yeah I probably should of read that before posting this, but searching for the right 'terms' to use is quite annoying.

Might have to pick myself up a few PHP books to stop bothering you guys :P

EDIT: also - what do you mean by "mysql safe"
Thu 24/02/05 at 18:50
Regular
"NULL"
Posts: 1,384
*bows*

It may be of interest to you to know that the PHP manual has very good documentation for things such as this - I believe it has an example very similar to the code I have just provided.
Thu 24/02/05 at 18:48
Regular
Posts: 10,364
You, Mr Nimco, are a genius
Thu 24/02/05 at 18:25
Regular
"NULL"
Posts: 1,384

$result = mysql_query("SELECT * FROM keyfeatures WHERE AucID='".$theauc."';"); // make sure you have made $theauc mysql safe
$array = array();

while ($row = mysql_fetch_assoc($result)) {
$array[] = $row['Keyfeature'];
}
?>
Thu 24/02/05 at 18:07
Regular
Posts: 10,364
Hi there.

Yet another MYSQL problem/PHP advice thread...

Ok this is the deal.

I have a table called "keyfeatures"

In it contains 3 fields.

"KeyFID" - primary key
"AucID" - secondary key
"Keyfeature" - text

What i'm having problems with is returning all of the values that match the secondary key.

I.e. SELECT * FROM keyfeatures WHERE AucID='$theauc'

How would I return those values?

Say if I had this as sample data and $theauc == 2: -

1 2 "this is data"
2 2 "data"
3 4 "woo this is data"

The query should return the top two piece of data, correct?

What I want to do exactly is put these values into an array (I have an array which can size itself to how many rows match the query) so

$array[0] = "this is data"
$array[1] = "data"

Any advice would be appreciated.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Continue this excellent work...
Brilliant! As usual the careful and intuitive production that Freeola puts into everything it sets out to do, I am delighted.
Excellent
Excellent communication, polite and courteous staff - I was dealt with professionally. 10/10

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.