Valhalla Legends Forums Archive | Web Development | [PHP] $_GET with MySQL

AuthorMessageTime
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);

?>[/quote]
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.
January 29, 2004, 4:11 PM
j0k3r
Another question, in the <a> tag, can I put <a href="blah.php?page=body">?
January 29, 2004, 4:15 PM
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.
January 29, 2004, 8:47 PM
Maddox
[quote author=j0k3r link=board=22;threadid=4985;start=0#msg41708 date=1075409262]
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.
[/quote]

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.
January 30, 2004, 3:26 AM
j0k3r
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]
February 6, 2004, 2:18 PM
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....
October 31, 2004, 1:19 PM
peofeoknight
[img]http://quasi-ke.servebeer.com/pics/misc11.jpg[/img]
October 31, 2004, 11:02 PM

Search