...

View Full Version : Need some help with code



bnorris
02-27-2012, 09:26 PM
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
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;
}
?>

cnoevil
02-27-2012, 09:40 PM
It's not very clear what it is you mean by:

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

bnorris
02-27-2012, 09:45 PM
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

cnoevil
02-28-2012, 12:47 AM
You'd use a form in your web page similar to the one here:



<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:

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

bnorris
02-28-2012, 01:13 AM
You'd use a form in your web page similar to the one here:



<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:

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
02-28-2012, 01:48 AM
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.

cnoevil
02-28-2012, 02:21 AM
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:


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

bnorris
02-28-2012, 12:27 PM
Thanks you everybody for help with this. I am proud to say it worked PERFECTLY! I never thought of using forms to do this. :thumbsup:

mlseim
02-28-2012, 01:44 PM
What is the purpose of this script?
This sort of looks like homework to me.

bnorris
02-28-2012, 01:55 PM
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

mlseim
02-28-2012, 05:13 PM
:D 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.

bnorris
02-28-2012, 05:38 PM
;) :D :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum