Welcome, Guest |
Welcome to Makestation! We are a creative arts/indie discussion community — Your center for creative arts discussion, unleashed!
Please note that you must log in to participate in discussions on the forum. If you do not have an account, you can create one here. We hope you enjoy the forum!
|
|
Spammer here
|
|
Spammer here
|
|
Spammer here
|
|
Spammer here
|
|
Spammer here
|
View all updates
|
Forum Statistics |
» Members: 1,073
» Latest member: FeeNeedy
» Forum threads: 8,950
» Forum posts: 33,251
Full Statistics
|
Online Users |
There are currently 370 online users. » 0 Member(s) | 369 Guest(s) Google
|
|
|
PHP - Part 5 |
Posted by: Darth-Apple - August 19th, 2013 at 9:02 PM - Forum: Software
- Replies (5)
|
|
How to Program PHP
Tutorial, Part 5
Welcome to part 5 of the "how to program PHP" series! So far, we've explored a number of fundamental concepts, but we haven't really done anything interesting yet. In the last tutorial, we explored so called "conditional" statements, but we never really went anywhere with the concepts that were explained in part 4. In this tutorial, we will begin making stuff actually happen in PHP. If you do not have a server or localhost set up on your PC yet, I would very strongly recommend getting that set up now, as this tutorial, as well as the ones to follow, will be very helpful with a localhost. Remember, Windows users can simply install WAMP to get a localhost set up in a matter of minutes. So, from this point on, I will assume that you have a working server or localhost set up to work with.
In this tutorial, we will explore how to get HTML forms to work together with PHP to make something happen. I would recommend having a good understanding of HTML forms before beginning this tutorial. If you do not understand HTML forms, a simple google search yields hundreds of great resources to help you understand how HTML forms work. This tutorial will teach you how to code PHP scripts to work with HTML forms, and we'll soon be able to do some pretty neat things with that.
First, we need to go backwards a bit and set up the simple HTML form. I'm not going to do anything particularly complicated here. I'll just write a very simple HTML form, and we'll get started.
Code: <html>
<head>
</head>
<body>
<form action="t5_demo.php" method="post">
First Name: <input type="text" name="firstname"><br>
Age: <input type="text" name="age"><br>
<input type="submit">
</form>
</body>
</html>
Paste the code above into a file called "t5_demo.html" (without the quotes) and save it into a folder on your server or localhost. As you may notice, we simply have an HTML form that asks for your first name and your age. There is nothing very complicated going on at this point. I encourage you to try this simple HTML page in your browser to get a feel for what is completed so far. You won't see much, but it is a valid form, and that is all we will need at this point.
Quote:Need help with HTML forms?
These tutorials won't attempt to review HTML, but if you need to brush up on your HTML scripts, this page from w3schools is a great reference!
How will we get this form to actually do anything? What is supposed to happen when "submit" is pressed? Well that's what the PHP side of this form is going to be for. Basically, the PHP is going to "process" this data and return something based on it. First, there are a few properties of this form that we should make note of. Look at the following line of code.
Code: <form action="t5_demo.php" method="post">
Notice the action= field. This defines which file we will be sending the form data to for processing. We haven't actually created "t5_demo.php" yet, but we'll be creating that fairly soon.
Also, notice the "method=" property. Here, it is set to "post," as you can see in the code above. This property has two possible values. You can either use the "get" or the "post" method, but what is the difference?
The difference between "post" and "get" is that "get" sends data in the URL, and "post" does not. "get" is useful for defining page numbers, page IDs, and other things that you will need to assign a specific URL to. "POST" is good for passwords, etc... since, for obvious reasons, you don't want passwords showing up in the URL. If this sounds confusing, keep reading. We'll explain it in much more detail very shortly.
Anyway, this form still doesn't do anything. In order to make it functional, we need to write "t5_demo.php" to process the form's contents and we will then save it in the same folder that t5_demo.html is saved in. Remember that the "action=" property defines the URL to the PHP file that the form's data will be sent to. It is very important that the PHP file that processes the form has the same name that is found in the "action=" property of the form. Otherwise the browser won't be able to find the corresponding PHP file to send the form's data to.
We'll start with something very simple.
Code: <?php
echo "hello, ".$_POST['firstname']."!";
?>
Save that into a file and call it "t5_demo.php". Make sure that it is in the same folder that your HTML file is in, and the name has to be exact. Then go to the HTML file's URL in your browser, and fill out the form. You should see something like this when you submit the form:
Quote:Hello, Steve!
This is an extremely simple script, spanning only three lines of code. What exactly does it do?
1) First, remember that "echo" is the command used to send data to the screen in your browser.
2) $_POST is an "array" that contains the values for all of fields in a form that uses "post" as its method. (See tutorial 2 for more information on arrays)
3) Notice how we used $_POST['firstname'] in the code. Look at the HTML file, and one of the <input> tags has a name attribute, and its assigned name is "firstname". In PHP, we refer to fields of a form by those assigned names. $_POST in fact contains the data from every field in a form, and you can refer to it easily. We'll explore more about $_POST in the next scripts that we will be making.
Anyway, as you can see, the script above is pretty simple, and simply is a "hello [yourname]" script. It doesn't do much that's actually interesting at this point, but it does show that PHP can be used to process form data. I'd recommend stopping and tweaking a few things at this point to get familiar with the concept. If it all seems very confusing, keep reading for more examples.
|
|
|
Your Opinion on GNOME 3? |
Posted by: Darth-Apple - August 19th, 2013 at 4:08 PM - Forum: Technology & Hardware
- No Replies
|
|
I just reinstalled both Windows and Linux on my PC, and am now running Fedora and Gnome 3. I have to say, it is very different from what I am used to, but I like it as well, for the most part. It doesn't have the most practical way of switching between applications, and I suppose that's my main disappointment, but I'll probably be getting used to it over time, and it's honestly a lot better than Unity.
What is your opinion of gnome 3?
|
|
|
Favorite restraunt? |
Posted by: That Punk Guy - August 19th, 2013 at 4:06 PM - Forum: General Discussion
- Replies (11)
|
|
Fast food, sit down, whatever, post the one you like here!
I like Mackenzie River Pizza Company. It's a pizza place that just opened up here but they're really good. My favorite thing there is the Mack Lovin, a dessert item which is a cookie baked into a small cast iron pan, with ice cream and hot chocolate sauce over it all.
|
|
|
Dacentec |
Posted by: That Punk Guy - August 18th, 2013 at 11:25 PM - Forum: Web Design & Internet
- Replies (5)
|
|
These guys are awesome.
Dacentec is a datacenter, based in the small town of Lenoir, North Carolina, USA (which Google also happens to have a datacenter in). What's so awesome about them is they sell dedicated servers with really good specs, at a low price, that you own after 12 months of payment. I'm looking into getting one myself, but they have pretty random stock everyday. From what I understand, it's just what they have shipped to them that day.
The only dis-advantage is the rather cheap-o peering (Cogent, Hurricane Electric, and TiNet), so ping may be a bit higher for some. Plus, once you own it, you must pay for co-location or the shipping to have them send you the server, they don't cover the shipping.
http://billing.dacentec.com/hosting/
QUICK EDIT: They've been having site issues recently so don't mind if it looks ugly.
|
|
|
Hey |
Posted by: Otakumatic - August 18th, 2013 at 10:58 PM - Forum: Introductions
- Replies (1)
|
|
Hi, I usually go by Suzaku but am unable to recover my password as I do not know the e-mail and the only other place I can get a hold of DarthApple at seems inactive.
|
|
|
A forum with an odd twist as an experiment? |
Posted by: Darth-Apple - August 17th, 2013 at 8:22 PM - Forum: Web Design & Internet
- Replies (9)
|
|
Undoubtedly, social networking has become much more popular in recent times. The popularity of traditional forums seems to slowly be decreasing as a result, and I think that the market for something "new" is growing stronger.
Software options such as Xenforo have been new and innovative, but options such as discourse or oxwall seem to be redefining what forum software is. I will say, I'm not personally a fan of discourse, but I do like the innovation that's going on. Forum software today is just too complicated, and all of the extra features get in the way of pure discussion.
I was thinking about either downloading a very simple forum software solution and modifying it, or building a custom forum software solution to have only the absolute bare essentials. I think it would be interesting to see what would happen if everything about the a forum was centered around discussion, and only discussion. I'd also like to try it as an experiment as far as community management when decisions are all brought to a public petition.
Obviously, this is only an idea, but I would definitely be interested in seeing what could be done if a complete rethinking of forum software were to take place. What do you think would make such an experiment successful? In what ways could forum software today be improved for a modern world?
|
|
|
|