Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-27-2012, 09:26 PM   PM User | #1
bnorris
New Coder

 
Join Date: Jan 2012
Posts: 21
Thanks: 10
Thanked 0 Times in 0 Posts
bnorris is an unknown quantity at this point
Need some help with code

Hi,

Im trying to write to a text flat file but heres the catch. I need to be able to make a template that I can use to describe cars like this:

The (year make and model) has only (this many miles) and is in great condition.



Once I get the basic script to work I can add more stuff. Here is what I have so far, it works but I can only do one line at a time Can anybody help?

PHP Code:
<?php
include('config.php');
$user $_GET["name"];
$message $_GET["message"];
print(
"<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
$out fopen("savedinfo.php""a");
if (!
$out) {
print(
"Could not append to file");
exit;
}
fputs ($out,implode,("\n"));
fwrite($out,"<b>$user</b><br />This $message Because With");
fclose($out);
include(
'config.php');
$user $_GET["name"];
$message $_GET["message"];
print(
"<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
$out fopen("savedinfo.php""a");
if (!
$out) {
print(
"Could not append to file");
exit;
}
?>

Last edited by Inigoesdr; 02-28-2012 at 02:20 PM..
bnorris is offline   Reply With Quote
Old 02-27-2012, 09:40 PM   PM User | #2
cnoevil
New Coder

 
Join Date: May 2009
Posts: 18
Thanks: 4
Thanked 4 Times in 4 Posts
cnoevil is an unknown quantity at this point
It's not very clear what it is you mean by:
Quote:
I need to be able to make a template that I can use to describe cars like this:
Are you talking about a form for a web page or something else? Folks might find it easier to help if they knew what kind of "template" you were talking about.

mark
cnoevil is offline   Reply With Quote
Old 02-27-2012, 09:45 PM   PM User | #3
bnorris
New Coder

 
Join Date: Jan 2012
Posts: 21
Thanks: 10
Thanked 0 Times in 0 Posts
bnorris is an unknown quantity at this point
Quote:
Originally Posted by cnoevil View Post
It's not very clear what it is you mean by:


Are you talking about a form for a web page or something else? Folks might find it easier to help if they knew what kind of "template" you were talking about.

mark
I will host this on my server, What I would really like is to have text boxes lined up labeled "Year" "Make" Mode" "miles" ect. I will have the There will already be text like "this" (year make and model) "has only" (30 thousand miles) It will write to a page and I will copy the text and past it into my listings. There may many of these text areas that will fit in between the text descriptions
bnorris is offline   Reply With Quote
Old 02-28-2012, 12:47 AM   PM User | #4
cnoevil
New Coder

 
Join Date: May 2009
Posts: 18
Thanks: 4
Thanked 4 Times in 4 Posts
cnoevil is an unknown quantity at this point
You'd use a form in your web page similar to the one here:


Code:
<div id="myForm"><form method="post" action="car_script.php">
Make:  <input type="text" name="make" /><br />
Model:  <input type="text" name="model" /><br />
Year:  <input type="text" name="year" /><br />
Miles:  <input type="text" name="miles" /><br /><br />
<input type="submit" />
</form></div>
Of course you should do what ever layout or styling you need to do in your style sheets to make work for your site.

In the action element of your form tag you call the script that creates the page that you want to display after the form data is submitted. This includes sending the data back to the same script that created the page that hosts the form if you want to. Also, within that page you can process the data to save to the flat file that you were speaking at the same time if you like.


You can use the data within the page that you are displaying like this:
PHP Code:
The make of your car is: <?php echo $_POST["make"]; ?>!<br />
The model of your car is: <?php echo $_POST["model"]; ?>!<br />
etc,etc.etc....

However, it is highly recommended that you "validate" your data before doing anything with it because some clever folks could load scripts into your text inputs and make a mess of your stuff for you if you don't. Google data validation for php and see what you can come up with.

Hope this helps point you in the direction you want to go.

Mark
cnoevil is offline   Reply With Quote
Users who have thanked cnoevil for this post:
bnorris (02-28-2012)
Old 02-28-2012, 01:13 AM   PM User | #5
bnorris
New Coder

 
Join Date: Jan 2012
Posts: 21
Thanks: 10
Thanked 0 Times in 0 Posts
bnorris is an unknown quantity at this point
Quote:
Originally Posted by cnoevil View Post
You'd use a form in your web page similar to the one here:


Code:
<div id="myForm"><form method="post" action="car_script.php">
Make:  <input type="text" name="make" /><br />
Model:  <input type="text" name="model" /><br />
Year:  <input type="text" name="year" /><br />
Miles:  <input type="text" name="miles" /><br /><br />
<input type="submit" />
</form></div>
Of course you should do what ever layout or styling you need to do in your style sheets to make work for your site.

In the action element of your form tag you call the script that creates the page that you want to display after the form data is submitted. This includes sending the data back to the same script that created the page that hosts the form if you want to. Also, within that page you can process the data to save to the flat file that you were speaking at the same time if you like.


You can use the data within the page that you are displaying like this:
PHP Code:
The make of your car is: <?php echo $_POST["make"]; ?>!<br />
The model of your car is: <?php echo $_POST["model"]; ?>!<br />
etc,etc.etc....

However, it is highly recommended that you "validate" your data before doing anything with it because some clever folks could load scripts into your text inputs and make a mess of your stuff for you if you don't. Google data validation for php and see what you can come up with.

Hope this helps point you in the direction you want to go.

Mark
This would work PERFECT! Now if I could get the form Results to post to the results page This page will be private so there will be nothing to mess with. THANK YOU!
bnorris is offline   Reply With Quote
Old 02-28-2012, 01:48 AM   PM User | #6
bnorris
New Coder

 
Join Date: Jan 2012
Posts: 21
Thanks: 10
Thanked 0 Times in 0 Posts
bnorris is an unknown quantity at this point
I actually got it to post problem is two things

1 it prints on two lines ( I need continuous sentences)
2 Has a: that I cant get rid of
3 I need lead in and out sentences.

What I trying to do is make a template to describe cars that I can cut and paste. In bold would be examples of manual input. I can add more lines easy once I get the theory right

This 2009 Ford Fusion only has 29000 Miles and is in perfect condition. With features like Cruise Control and Anti Lock Brakes makes this Ford Fusion a great car


What Prints (Two Test Lines)

Form Confirmation

Thank you for submitting the following information:

This: trhh
Only has: trtrh

Return to the form.
bnorris is offline   Reply With Quote
Old 02-28-2012, 02:21 AM   PM User | #7
cnoevil
New Coder

 
Join Date: May 2009
Posts: 18
Thanks: 4
Thanked 4 Times in 4 Posts
cnoevil is an unknown quantity at this point
Ok, if you don't want things printing on 2 lines then you can remove one of the "<br />" tags. If you're not very familiar with html here's a decent reference you can go by. Also, give that whole website a good once over. There's a lot of good, direct, very basic instruction there for doing a great number of different things. I use it a lot.

Be thinking along the lines of something like this:

PHP Code:
echo "This $_POST['year'] $_POST['make'] $_POST['model'] only has $_POST['miles'] Miles and is in perfect condition. "

Edit: oops... here's the reference: http://www.w3schools.com/html5/html5_reference.asp

Hope this helps,
Mark

Last edited by cnoevil; 02-28-2012 at 02:23 AM.. Reason: left something out
cnoevil is offline   Reply With Quote
Users who have thanked cnoevil for this post:
bnorris (02-28-2012)
Old 02-28-2012, 12:27 PM   PM User | #8
bnorris
New Coder

 
Join Date: Jan 2012
Posts: 21
Thanks: 10
Thanked 0 Times in 0 Posts
bnorris is an unknown quantity at this point
Thanks you everybody for help with this. I am proud to say it worked PERFECTLY! I never thought of using forms to do this.
bnorris is offline   Reply With Quote
Old 02-28-2012, 01:44 PM   PM User | #9
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,056
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
What is the purpose of this script?
This sort of looks like homework to me.
mlseim is offline   Reply With Quote
Old 02-28-2012, 01:55 PM   PM User | #10
bnorris
New Coder

 
Join Date: Jan 2012
Posts: 21
Thanks: 10
Thanked 0 Times in 0 Posts
bnorris is an unknown quantity at this point
Quote:
Originally Posted by mlseim View Post
What is the purpose of this script?
This sort of looks like homework to me.
Custom comment generator for a car dealership. Ill put a demo up for the day then Ill move it REMOVED

Last edited by bnorris; 02-28-2012 at 05:59 PM..
bnorris is offline   Reply With Quote
Old 02-28-2012, 05:13 PM   PM User | #11
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,056
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
That's great.

I almost picture a sleazy car salesman sitting inside a computer spewing out
the pitch to the wary customer ... "this one's a beauty!" Sort of a modern
take on an old tradition.
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
bnorris (02-28-2012)
Old 02-28-2012, 05:38 PM   PM User | #12
bnorris
New Coder

 
Join Date: Jan 2012
Posts: 21
Thanks: 10
Thanked 0 Times in 0 Posts
bnorris is an unknown quantity at this point
bnorris is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 +1. The time now is 06:31 AM.


Advertisement
Log in to turn off these ads.