Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    10
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New Coder
    Join Date
    May 2009
    Posts
    18
    Thanks
    4
    Thanked 4 Times in 4 Posts
    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

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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

  • #4
    New Coder
    Join Date
    May 2009
    Posts
    18
    Thanks
    4
    Thanked 4 Times in 4 Posts
    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

  • Users who have thanked cnoevil for this post:

    bnorris (02-28-2012)

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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!

  • #6
    New Coder
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New Coder
    Join Date
    May 2009
    Posts
    18
    Thanks
    4
    Thanked 4 Times in 4 Posts
    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

  • Users who have thanked cnoevil for this post:

    bnorris (02-28-2012)

  • #8
    New Coder
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanks you everybody for help with this. I am proud to say it worked PERFECTLY! I never thought of using forms to do this.

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    What is the purpose of this script?
    This sort of looks like homework to me.

  • #10
    New Coder
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.

  • #11
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.

  • Users who have thanked mlseim for this post:

    bnorris (02-28-2012)

  • #12
    New Coder
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    10
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •