Valhalla Legends Archive

Programming => Web Development => Topic started by: j0k3r on January 29, 2004, 10:11 AM

Title: [PHP] $_GET with MySQL
Post by: j0k3r on January 29, 2004, 10:11 AM
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.
Title: Re:$_GET with PHP
Post by: j0k3r on January 29, 2004, 10:15 AM
Another question, in the <a> tag, can I put <a href="blah.php?page=body">?
Title: Re:[PHP] $_GET with MySQL
Post by: 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.
Title: Re:[PHP] $_GET with MySQL
Post by: Maddox on January 29, 2004, 09:26 PM
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.
Title: Re:[PHP] $_GET with MySQL
Post by: j0k3r on February 06, 2004, 08:18 AM
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]
Title: Re: [PHP] $_GET with MySQL
Post by: venox on October 31, 2004, 07:19 AM
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....
Title: Re: [PHP] $_GET with MySQL
Post by: quasi-modo on October 31, 2004, 05:02 PM
(http://quasi-ke.servebeer.com/pics/misc11.jpg)