Home Alone with PHP, part 2: Lost in links!
Here I am, once again, trying to create an useful page with Apache, PHP, MySQL. This is SuSE 9.1 pro, so it's Apache 2.x and PHP4.
I'm trying to create a simple page: On the left you have a menu with three links: Home, Images and About. Clicking on these links, the content on the right table should change, displaying the data from the Database instead. That's exactly what does not work :( Database Code:
mysql> select * from main; PHP Code:
I can do a neat game list though :) Thanks in advance, once again! |
this looks remarkably like another register globals problem like the one we discussed in thread 214565
you cant access external variables the way you want to, if the variable is from a http post then it can be found in the $_POST array, if it is from an http get(like above) then it can be found in the $_GET array, same for cookies($_COOKIE array) so you need to use $_GET['pageid'] everywhere or at the top of your script put $pageid = $_GET['pageid']; |
why cant you just do
while($row=mysql_fetch_array($rs)) { $tmp_image =$row["image"]; $tmp_header=$row["header"]; $tmp_text =$row["text"]; echo ($tmp_header); echo ($tmp_text); i got it to work like that |
Thanks a lot kev82 (once again) and rjcrewsfor the input. I've got it to work using a bit of both ideas :). Here is how it looks like now:
PHP Code:
Thanks all again! I've been in this forum for a long time now, and the help here is like MasterCard ads: Priceless :) Cheers! |
Cool. One more question. What if I need to use more then one table in the very same database. e.g
- I have one database called "databas", which has two tables: main and news. - "main" holds the body of the page, meaning "home", "images" and "about". Like this: Code:
mysql> select * from main; Code:
mysql> select * from news; I cannot think straight how one would do making a page like this... what I want to do is kinda like a blog: - Home -> with the descriptions of the page and it's updates - Pictures -> the actual blog. Peoples are supposed to also leave messages in here - About me -> just a text description of me - Contact -> my ICQ, e-mail and stuff. Should I do one table for every link since they have different data on it? I cannot really think straight (or think at all for that matter). I could simply use a finished blog out there, but they are all bad, and I want to learn PHP too :) Thanks in advance once again! |
There are many ways...
PHP Code:
|
Thanks Cedrik!
I really appreciate it. I will give it a whirl this weekend. I was taking a different approuch though, not a very wise one, mind you. Instead of having only one file on the server called index.php which updates itseft, I've created another one called send.php which acts as a Visit Book. It works, more or less, with two bugs. One being a simple HTML bug (I've not really used HTML for at least 3 years, so I need some help :)) and another being my horrible coding skills. Here is the situation: 1 - I've create a new table into databas, called "book". This table holds four values: ID, Name, Location and Message. It looks like this: Code:
mysql> select * from book; PHP Code:
1 - It's an HTML problem that I cannot fix with all my lack of wisdom. The TD on the left (where the menu is) is wrapping, meaning that if too many posts are posted on the right (second TD), the menu gets all hippie, instead of staying on the top. the tag "nowrap=true" does not seems to work in this case... 2 - It's a PHP thing. If the user posts a message, "Message Sent" is displayed. No problems there. Problem is, the page won't update. If the refresh button is used, it will double post. The only way is to type again "send.php" on the browser... Any ideas? Thanks again, and sorry to annoy you all :). I just want to make a simple page to hear comments from friends and stuff. Well, now to the admin tools :'(. Regards! |
by Megaman X
I'm still not quite sure when or how I've to use the variables of type $_POST and $_GET, or how different they are from ordinary variables. $_POST and $_GET are associative arrays, they contain the http post and http get input respectivly, you should use them ALWAYS well actually only when you want post/get data. read about the register globals directive for examples of why you should use them. 1) not sure what you mean but the menu doesnt stay at the top because of a typo by Megaman X <TR valig="top" align="left"> note the missing n 2) i would send an http refresh header but you cant do this as you produce output before any code is run, so ive changed the order of your code, ive left it in a mess though and it could use some tidying up. PHP Code:
|
kev82, you are just amazing :). Thanks once again for the great help mate. The code now runs without a glitch ;). I need to get a PHP book and start learning this for real. It's by far the coolest thing I've ever played with, sadly, I don't quite follow a lot of things yet :(.
Nonetheless, thanks a lot mate! I simply could not make without your help. Thanks all others who answered this thread or that have simply looked at it. More questions to come :) |
Ok, resurrection of an old thread. I've just figured one thing out. If somebody visits my page and fill it it with HTML code, specially forms, it gets really, really screwed. How would be the wisest (and easiest) way of replacing HTML tags from a form? I think "< and >" would be enough?... hopefully...
Thanks in advance! |
try strip_tags(), works more or less good
PHP Code:
|
Thanks a lot Cedrik for the quick reply!. I so have to buy a PHP book :(
|
just got to www.php.net to get help with the famous function field search ;)
|
Hey thanks again mate ;). Have totally forgotten to check it's official site :)
|
All times are GMT -5. The time now is 07:32 AM. |