Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Beginner Question Regarding PhP
Old 09-06-2007, 04:11 PM Beginner Question Regarding PhP
Novice Talker

Posts: 9
Trades: 0
Well; I'm currently taking a PhP/MySQL programming class, and I'm curious if I've done an assignment correctly:

"Create a php script that will process and print a form. The form will take as input a person's first and last name, and an e-mail address. The form (when the submit button is pressed) will then output the persons name and a message that will state that e-mail has been sent to them. You are not sending e-mail of course, this is just a practice for later projects."

Now; this is what I created for this assignment:

HTML Code:
Code:
<html>
<head>
<title>E-mail Submission</title>
</head>
<body>
<center>
<form method = "post"
      action = "mainPHP.php">
Please type your first name:
<input type = "text"
       name = "firstName">
<br>
<br>

Please type your last name:
<input type = "text"
       name = "lastName">
<br>
<br>

Pleast type you E-mail Address:
<input type = "text"
       name = "email">
<br>
<br>
<input type = "submit" />
</center>
</form>
</body>
</html>
^^ I used above as merely a simple HTML script obviously, the following is the PhP script:

Code:
<?php

$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];

echo "Hello $firstName $lastName, the E-mail was sent to $email. ";

?>
The code works as I want it to, however, the assignment is for one PHP script, and from what I've read in the book, it only explains using two files to complete this type of project.

The question is, can I create the same thing, with only one PHP code?
Evelath is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-06-2007, 04:34 PM Re: Beginner Question Regarding PhP
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
yes you can .....
Code:
<?php 

if ($_POST['submit']) {
.... the php script .... or 
include ( 'mainphp.php' )
} else {
echo html form or 
include ('html_form.php')
}
?>

this method ( single file ) is usefull when you check the form and return an error ... with the form fields already filled with what he wrote in the form.
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 09-06-2007, 07:27 PM Re: Beginner Question Regarding PhP
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
This code would do it all in the same page. Notice that I've changed the action on the form.

PHP Code:
<?php

if(isset($_POST['firstname']))
{
    echo 
//your string here.
}
else
{
    echo 
'<html>
<head>
<title>E-mail Submission</title>
</head>
<body>
<center>
<form method = "post"
      action = "thispage.php">
Please type your first name:
<input type = "text"
       name = "firstName">
<br>
<br>

Please type your last name:
<input type = "text"
       name = "lastName">
<br>
<br>

Pleast type you E-mail Address:
<input type = "text"
       name = "email">
<br>
<br>
<input type = "submit" />
</center>
</form>
</body>
</html>'
;
}
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-07-2007, 04:03 AM Re: Beginner Question Regarding PhP
Novice Talker

Posts: 9
Trades: 0
Thanks for the assistance thus far; however both of those come up with errors. (Even when I insert in the selected/needed files.) Could an example be provided of how one would look if the files were listed? I believe both center around having an error in Line 6 or so.
Evelath is offline
Reply With Quote
View Public Profile
 
Old 09-07-2007, 01:41 PM Re: Beginner Question Regarding PhP
Novice Talker

Posts: 9
Trades: 0
I suppose a better question would be to ask if there is a way to accomplish this without using Include or using another file?
Evelath is offline
Reply With Quote
View Public Profile
 
Old 09-07-2007, 02:20 PM Re: Beginner Question Regarding PhP
Extreme Talker

Posts: 238
Location: United States
Trades: 0
Quote:
Originally Posted by Evelath View Post
I suppose a better question would be to ask if there is a way to accomplish this without using Include or using another file?
NullPointer's post does pretty much what you just said. It doesn't require any includes or other files. Just change the echo //your string here. line (which is causing the error if you did not change it) to echo a string of your choosing, e.g., echo 'Thank you for your submission';. Also, make sure you end the PHP script with a ?>.
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
frost is offline
Reply With Quote
View Public Profile
 
Old 09-07-2007, 04:23 PM Re: Beginner Question Regarding PhP
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
on the form action you can put $_SERVER['PHP_SELF'] and that makes the script work no matter the file's name
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Reply     « Reply to Beginner Question Regarding PhP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24656 seconds with 12 queries