Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using variables

From: Dynamic Dreamweaver Websites: Creating and Validating Forms

Video: Using variables

We are now going to take a look at how to display variables, not only how to display them, but how to create them initially in PHP. Every server side language, has a slightly different way to go about creating and outputting variables, so we'll take a look at the PHP version. Now once we defined and opened up a PHP page within Dreamweaver, we now have this PHP tab. If I opened a ColdFusion page, I would have a couple of tabs. If I opened an ASP page, I would have an ASP tab. So Dreamweaver recognizes the pages you're working in, and provides an extra tab in the Insert bar or two in the case of ColdFusion, to assist you in working with those server side languages.

Using variables

We are now going to take a look at how to display variables, not only how to display them, but how to create them initially in PHP. Every server side language, has a slightly different way to go about creating and outputting variables, so we'll take a look at the PHP version. Now once we defined and opened up a PHP page within Dreamweaver, we now have this PHP tab. If I opened a ColdFusion page, I would have a couple of tabs. If I opened an ASP page, I would have an ASP tab. So Dreamweaver recognizes the pages you're working in, and provides an extra tab in the Insert bar or two in the case of ColdFusion, to assist you in working with those server side languages.

So how do we create a variable, and what is it? Well let's take a look at adding PHP code in general. So, the reason I went to tab here, is because every piece of PHP must be surrounded by what's known as a PHP code block, and the easiest way to add that is in the PHP tab, it's this piece here. You can see it says code block when you hoover over it, so if you get confused about which one it is, just hoover over it, and it will say code block, and there is our code block.

I simply Clicked that and Dreamweaver added that code for me. Now personally I think it's very easy to get the order of these mixed up, or to not quite spell it correctly, and then your code would not work correctly. So, I tend to let Dreamweaver ever do that for me, I will leave that totally up to you. Now, how do we create a variable in PHP? What we do is put a dollar sign. And you can see, when I do that, these are PHP code hints. These are different types of variables available in PHP. And I'm actually not going to be using any of these, what I'm going to do is create a variable of my own.

And I'm going to type out Dollar f name, for first name, equals and in double quotes, put my name. So you go ahead and put your name, I don't think you need to take my name. And we're going to do the same thing for L name. L name representing last name. So go ahead and put your last name. Now, as I am typing, you may see some interesting things happening in the Dreamweaver interface. First of all, we had that little purple, kind of blinking so to speak. It kind of fades in and out, to test things.

If I go to type something, I'll do it again. So let's do dollar m name, equals. Now you can see as I type, there's this little red piece here, and there's information coming to me across this area. Right now I have not completed this line of code, so PHP is telling me, or actually Dreamweaver is understanding the PHP enough to tell me, that there's an error somewhere in this area. And you can see this says it's on line 13, and it's actually on line 12. So what's happening is I didn't complete this line, so PHP cannot read line 13. This is new.

This is new as of Dreamweaver CS5. Now, you don't have to have Dreamweaver CS5 or 5.5 in order to work through this course. I just want to point out some of the new features that have come out, and you'll see this one consistently as I type in code view. So just to fill you in on what that is all about, it's really handy to point out, and you can see now it says no syntax errors, to point out little errors that can occur as you're typing. So this is a great new Dreamweaver feature, as of CS5, it understands PHP and can try and assist you and point out errors.

So what have we done? We have created variables. Well, what does that mean? If you have programming experience, you understand, but I'm not assuming you do throughout this course. So what we have done is created a space in computer memory. And you can almost think of it like a big chest of drawers. So you have this dresser drawer and you open it up, there's first name is on the outside of the drawer and when you open it up, it can change.

The information inside that drawer can change. But the drawer itself is always going to be called F name. Now in our example, I would put my first name, for you, you'd put your first name. In other words the value of the variable changes which is this piece, but the name of the variable doesn't. So, basically a variable is a way to represent a value at a particular time. So we just created PHP variables. Let's take a look at our page. It doesn't matter which browser I preview in.

And we have absolutely nothing on the page, aren't you impressed with you, all of your hard work? Now what we need to do, is print it to the page. We need to tell PHP, take those values and put them on to the HTML page. And the way we print in PHP is to use the word echo. Echo tells PHP, print this to the page. And what I'm going to do, is put this into a sentence. And I'm going to say, my name is, $, f name. Now this is another new feature.

Any variables you create, you can see Dreamweaver understands it, it pops up as a code hint. And what I can do, is just Double-click it and it pops it in for me. So any variables you create, PHP will now understand. So, I'll put the L, there's my L name, and I can Double-click it, or you can type it out. Whatever is your preference. I'll put a period in that sentence. And the last piece of every PHP lines needs to be a semi colon. So you can see each one of these lines has a semi colon. So I'm telling PHP print out this sentence, but what PHP is going to do is replace the name of the variable with my first name, and the name of this variable with my last name.

So let's test it out and make sure that's the case. And there it is, your first sentence in PHP, if you haven't worked in PHP previously. Now there are different types of variables. We're going to be working mainly in these basic local variables, and to print to the page you use the word Echo. So there is how you create variables in PHP, and output them to the page.

Show transcript

This video is part of

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Dynamic Dreamweaver Websites: Creating and Validating Forms.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.