• Welcome to Valhalla Legends Archive.
 

[PHP] $_GET with MySQL

Started by j0k3r, January 29, 2004, 10:11 AM

Previous topic - Next topic

j0k3r

I'm having a difficult time with this, and for some reason I assumed it would be easy... I'm trying to make a page that loads the column 'content' from the table it get's with the $_GET method.
Quote<?php

include "somepagewithdatabasestuff.php";

$page = $_GET['page'];

$query = "SELECT `content` FROM `$page`";

$result = mysql_query($query) or die("Query failed : " . mysql_error());

$line = mysql_fetch_array($result, MYSQL_ASSOC);

echo $line['content'];

mysql_close($somedatabasehandle);

?>
I try to make it work by going to "www.myurl.com/thispage.php?page=body" but it prints an error that says "Could not select table `". I've double checked, and $page doesn't even have a value. I think it could either be...
1. The page is cached(?) and loads from there
2. I'm doing something wrong

Any help is appreciated.
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

j0k3r

Another question, in the <a> tag, can I put <a href="blah.php?page=body">?
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

j0k3r

Storm helped me to realize the problem, and pointed out something interesting over AIM...

I had the file embedded into a frame, so whatever I put in the URL wasn't picked up, however when I put it in links it worked fine.
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

Maddox

#3
Quote from: j0k3r on January 29, 2004, 02:47 PM
Storm helped me to realize the problem, and pointed out something interesting over AIM...

I had the file embedded into a frame, so whatever I put in the URL wasn't picked up, however when I put it in links it worked fine.

You dont need those ` marks in your query. That might save you 2 minutes of your life. Oh, and you probably already know this but your script is probably as insecure as it gets.
asdf.

j0k3r

#4
Storm pointed out somet things, I'll update what I've done when I get home.

It didn't work without the ``, I don't know why.

[edit]After I do that, mind telling me how wrong I am again? Can use whatever hints I can get, really just learning PHP[/edit]
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

venox

if you are going to do this sort of thing, id recomment making one generic "pages" table that has something like pageid, pagename, pagecontent in it, then just "SELECT pagecontent FROM pages WHERE pagename = '$page'";

rather than having a seperate table for every page....

quasi-modo

WAR EAGLE!
Quote(00:04:08) zdv17: yeah i quit doing that stuff cause it jacked up the power bill too much
(00:04:19) nick is a turtle: Right now im not paying the power bill though
(00:04:33) nick is a turtle: if i had to pay the electric bill
(00:04:47) nick is a turtle: id hibernate when i go to class
(00:04:57) nick is a turtle: or at least when i go to sleep
(00:08:50) zdv17: hibernating in class is cool.. esp. when you leave a drool puddle