logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 06-15-2012, 12:52 AM   #1
kremo5le
kremo5le's Avatar
 
Join Date: Nov 2008
Location: San Diego, California
Posts: 112
Question Simple PHP Setup Question - Echo Function?

Hello guys,

I am starting to learn some simple PHP from scratch. I have worked for a number of years with already-written PHP and am able to change things here and there but I am not a PHP programmer. However, I want to learn some basics.

I have gone online, including the PHP website, but I am just super confused and all I am looking for to do is perhaps the most common use for PHP (along with forms, that is).

THE SITE

So I am working on a responsive site: http://m.eelio.net/. All I want to learn to do is to create PHP files that are called by the main template.

For example, I want to create a "follow_me.php" file that is called by the template. Same goes with the footer, menu, etc.

I tried the echo function, which I believe is all I need, but I was unsuccessful. I am not sure if the file "follow_me.php" should have JUST the HTML or if it should be wrapped around <?php > tags. I am not sure exactly what to write within the index.php file neither.

Ideally, I would like to keep the php files in a folder and not in the root directory (I am an organization freak, so perhaps .../php/... and robots.txt it out). But maybe there are better practices?

THANKS!
__________________
Otter Creative Studio
San Diego Web Design, SEO, & Graphic Design
kremo5le is offline   Reply With Quote
Old 06-15-2012, 01:01 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

you need to use include this will include your sections.
ie if you have a file called header.inc (or text or htm etc) it will include the contents as is so if header.inc contains
Code:
<div>
<p>This is my header</p>
</div>
you can in your web page use
Code:
<?php  include("folder/header.inc") ;?>
and that will show the contents of that file
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Old 06-15-2012, 08:31 AM   #3
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

Quick best practice note.

Use a .php extension in all php files especially when including into another file.

If a user tries to target and download a .php file then that file will be handed over and processed through php this means that what is returned to the requester is a file void of any code. If however you target an .inc file the browser will prompt to download the file in all its glory as it wont know how to render the inc file directly. Imagine having a connect.inc file which contained your database connection block which was targeted and downloaded!
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 06-20-2012, 06:07 AM   #4
kremo5le
kremo5le's Avatar
 
Join Date: Nov 2008
Location: San Diego, California
Posts: 112
Smile Basic PHP Code "Include"

That was easy! Thank you both.

I really don't know what a .inc file is so all my files are .php.
__________________
Otter Creative Studio
San Diego Web Design, SEO, & Graphic Design
kremo5le is offline   Reply With Quote
Old 06-20-2012, 06:48 AM   #5
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

no prob, old format used for non important text that will be read on web anyway. could be anything as I said including php of course
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Old 06-20-2012, 04:54 PM   #6
kremo5le
kremo5le's Avatar
 
Join Date: Nov 2008
Location: San Diego, California
Posts: 112
Cool .inc Format + PHP Form

Quote:
Originally Posted by edbr View Post
no prob, old format used for non important text that will be read on web anyway. could be anything as I said including php of course
It is all good. Old or new, you guys got me running and also interested in learning more about PHP.

NEW QUESTION

I now created a form based on a tutorial yet I stripped everything I was not interested in. http://m.eelio.net/talk.php. For example, the captcha was really simple with just a single answer (what is 2+2?). I would like to implement a more advanced captcha system: what do you recommend?

I would also want to learn how to make certain fields required. All in PHP.
__________________
Otter Creative Studio
San Diego Web Design, SEO, & Graphic Design
kremo5le is offline   Reply With Quote
Old 06-21-2012, 01:11 AM   #7
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

recaptcha is popular but there are many freebie scripts on the web yahoogle away
here is a tut that explains the nuts and bolts http://net.tutsplus.com/tutorials/ph...-contact-form/
or here http://frikk.tk

as for required it a matter of checking if the field is empty or not
simple example
if ($email == "") {
echo "<h4>You must enter an e mail address</h4>";

}
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Old 06-25-2012, 05:32 PM   #8
kremo5le
kremo5le's Avatar
 
Join Date: Nov 2008
Location: San Diego, California
Posts: 112
Question Empty Field PHP Form Validation

Quote:
Originally Posted by edbr View Post

as for required it a matter of checking if the field is empty or not
simple example
if ($email == "") {
echo "<h4>You must enter an e mail address</h4>";

}
I think I will do reCAPTCHA. Thanks!

Regarding the empty field code, I added this but it did not work as it continued showing that new line added constantly and I still could send emails. :O/

PHP Code:
<?php
                    $name 
$_POST['name'];
                    
$email $_POST['email'];
                    
$message $_POST['message'];
                    
$from 'From: my website'
                    
$to 'my@website.net'
                    
$subject 'Hello';
                            
                    
$body "From: $name\n E-Mail: $email\n Message:\n $message";
                                
                    if (
$_POST['submit']) {
                        if (
mail ($to$subject$body$from)) { 
                            echo 
'<h4>Your message has been sent!</h4>';
                        } else { 
                            echo 
'<h4>Something went wrong, go back and try again!</h4>'
                        }
                    }
                    
                    if (
$email == "") {
                        echo 
"<h4>You must enter an e mail address</h4>";
                        
                        }
                    
                    
?>
__________________
Otter Creative Studio
San Diego Web Design, SEO, & Graphic Design
kremo5le is offline   Reply With Quote
Old 06-26-2012, 01:03 AM   #9
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

Code:
<?php
                    $name = $_POST['name'];
                    $email = $_POST['email'];
                    $message = $_POST['message'];
                    $from = 'From: my website'; 
                    $to = 'my@website.net'; 
                    $subject = 'Hello';
                            
                    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
                        if ($email == "") {
                        echo "<h4>You must enter an e mail address</h4>";
                        
                        }            
                    if ($_POST['submit']) {
                        if (mail ($to, $subject, $body, $from)) { 
                            echo '<h4>Your message has been sent!</h4>';
                        } else { 
                            echo '<h4>Something went wrong, go back and try again!</h4>'; 
                        }
                    }
                    
                
                    
                    ?>
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Old 06-28-2012, 03:41 AM   #10
kremo5le
kremo5le's Avatar
 
Join Date: Nov 2008
Location: San Diego, California
Posts: 112
Default PHP Validation Form

Now it always shows:

"You must enter an e-mail address"

http://m.eelio.net/talk.php

CAPTCHA

I also added the script to show reCAPTCHA as you see. However, I am not even sure what to do next (which is to hook up the validation) based on these instructions: https://developers.google.com/recaptcha/docs/verify

By the way, thanks for your help!
__________________
Otter Creative Studio
San Diego Web Design, SEO, & Graphic Design

Last edited by kremo5le; 06-28-2012 at 04:06 AM..
kremo5le is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:22 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com