Generating New Pages With PHP and MySQL?

software development

#1

For instance, on a message board script, when you start a new thread, the thread is inserted into the database and is then displayed on the message board. But, you’re able to access the thread directly with a URL that is created after the thread is up.

How do you do this with PHP and MySQL?


#2

Just about all of the basics on that can be found here: http://us2.php.net/manual/en/ref.mysql.php

Most of the function names will give you an idea of what they do, but you can click on them for more info, examples & user comments.

And here’s an example of pulling from the DB & displaying it on a page.


:stuck_out_tongue: Maximum savings promo code: MaxSavingsAtDH


#3

What are the functions you’ll need the most to achieve this? Sorry, but there were a lot of functions on that page, and none of them (at least to me) gave me any hint that they helped do what I’m wanting to do :frowning:


#4

Basically the ones that are used in that example page I linked to. That’s pretty much a working example of what you want to do.


:stuck_out_tongue: Maximum savings promo code: MaxSavingsAtDH


#5

I’m sorry, but I’m having a bad night, so I’ll need further explanations. If this is what you’re telling me how to do, then I apologize and ask for you to go a bit slower, because the stuff you’ve shown me doesn’t look like it has anything to do with what I’m trying to do (to me, that is). Anyway:

I know how to retrieve data from a database and display it on a HTML page. However, I only know how to display it on a HTML page that is already built and published on the web. Take this forum topic for example: I created a brand new topic, and a URL was assigned to it after it had been created (http://discussion.dreamhost.com/showflat.pl?Cat=&Board=forum_programming&Number=108313&page=0&view=collapsed&sb=5&o=14&part=1#Post108317 to be exact), so now I can access this topic directly with that URL. I don’t have to go to the forum homepage, enter the forum, find the topic, and click the topic link to view it, because I know the URL to the topic. It’s as if PHP and MySQL generated a new HTML web page specifically for this topic in order to display the information it contains.

Am I making sense?


#6

There’s not actually a URL assigned to it, but a page that contains code like in that example, that pulls the needed info from the URL and generates the page.

In the forum URL example you gave, the script is at http://discussion.dreamhost.com/showflat.pl – everything after that is what that script uses to display the correct thread. Other posts/threads would still be generated from that same page, but with different variables passed to it like the thread ID, etc…


:stuck_out_tongue: Maximum savings promo code: MaxSavingsAtDH


#7

You wouldn’t happen to know of any online tutorials for this, would you? I would just Google it, but to be honest, I don’t even know what to type in the search box. This looks like it’s going to be more difficult than I had originally thought.

Thanks for putting up with me :stuck_out_tongue:


#8

Actually, reading through that PHP.net manual is my favorite place for info. You can also check out sites like phpbuilder.com, zend.com, digitalpoint.com, etc… but I usually find everything I need between Google searches & php.net.

As far as searching for them goes, it just depends on what part is giving you trouble, whether it’s the PHP, MySQL or something with the HTML part of it. Generally, searching for stuff like “building dynamic sites with php & mysql” should cover the bases.

Even just PHP tutorials will usually end up touching on MySQL anyway.

You could also search for “mysql injection” for things to watch out for if you’re going to be letting users pass things along to the DB.


:stuck_out_tongue: Maximum savings promo code: MaxSavingsAtDH


#9

The part I don’t understand is you saying that, like, the threads are displayed on the same general page, but the script generates the code necessary to display the appropriate thread, and then there is a URL that you can access it with. How is there now a URL, and how do you even know what it is?

What would you do a Google search on to find that out?


#10

That’s really just a matter of passing variables to the script.

$_GET

$_POST

$_GET would be the way to go for pulling the variables from the URL, like in the forum links here.

I’m not sure what you mean by how you’d remember it, though. Like you’d remember any URL?

I noticed you had another thread asking about adding Javascript to the mix as well. I’d suggest that if any one of the bunch (HTML, PHP, MySQL, Javascript, etc…) is giving you any trouble, I’d hold off on putting them all together until you’re more comfortable with them.

Even with the POST/GET examples. I’d make sure you’re comfortable with using variables within a script & pulling info from the URL, forms, etc… before adding database interaction to the mix.

The more things you try to do at once, the harder it is to narrow it down when it doesn’t work as expected.

Plus, when you’re at a stage where you just want to get something to work, it can be easier to overlook security.

Doing searches for code injection, mysql injection, header injection, php security, mysql security, etc… can bring up some useful info to keep in mind–especially if anything will be generated from user input.

I’d also recommend reading through all of the MySQL function descriptions on the PHP site I originally linked to, even if they don’t look like something you need right away. That way, when there’s something you want to accomplish, you’ll have a better idea of where to start looking.


:stuck_out_tongue: Maximum savings promo code: MaxSavingsAtDH


#11

The JavaScript post was merely a question from me about canceling the PHP $_POST array on an email feedback form because I’m interesting in adding client-side scripting to my validation methods for email forms. It has nothing to do with this.

The reason I’m asking all these questions is because I’m trying to create my own news publisher script, so I have to have database interaction in the mix.

What I meant by how you would remember the thread URL is I don’t understand where the URL comes from all of the sudden. I understand that there is a general HTML page to display threads on, and that displaying the correct thread information is merely a matter of passing the correct variables to the script. I don’t understand how there is a URL of the sudden after the thread has been created, with which you can use to access the correct thread. I also don’t understand how you find out what that URL is after it has been created, and I don’t understand how the topics table page is updated with links to new thread posts, since I don’t understand where the URL comes from and how you even are able to know what the URL is.

:wink:


#12

The URL would just be whatever you decide to make it, depending on how you feed the info to your script.

A simple example would be if you had dosomething.php that contained nothing but this:

<?php echo $_GET['var1']; ?>

That script will always be at dosomething.php, but won’t output anything unless you tell it to.

So if you go to dosomething.php?var1=Hello you’ll now have a page that says Hello on it, even though the code of the page hasn’t changed.

That is just a simple example and isn’t safe since it just lets people enter whatever they want.

Instead of echoing stuff to the screen, you’d just pass the variables to whatever script you have that’s pulling from the database & building the page.

Keeping track of it all just depends on what you’re doing. If you were just keeping a database of links, your DB might consist of something like:

Link ID, Link URL, Link Text

So you could just pull that info with your code, then loop through it and generate the links.

In the forum example the actual file request doesn’t change for each thread… just the variables that are passed to it. The variables match what has already been inserted when a thread/post is made, so you can build a list of links by pulling the info from the DB.


:stuck_out_tongue: Maximum savings promo code: MaxSavingsAtDH


#13

Took us awhile to get here :stuck_out_tongue:

Thank you very much :slight_smile: That helps me understand a lot better :slight_smile: