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 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts

    stupid echo question

    Ok this is kind of a lame question but I am having some trouble with it. I have a page that willhave a textarea that will be used to edit content and then saved anto another page. How do I echo the text from the textarea of "page1" and get echoed and saved onto "page2" dont know if I need a db table set up for this or not but this is what I have as of now and it only echos to itself. I need it to echo to a page called "company.php" How would I do this, and whats the best way to do it?
    Thanks for the help.
    PHP Code:
    <style>
        fieldset {
         width: 400px;
         }
    </style>
    <fieldset>
    <div align="center">
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <textarea name="description" cols="40" rows="10"></textarea>
    <input type="submit" name="submit" value="Submit" /></div>
    </fieldset>
    <?php
    if (isset($_POST['submit'])) { 
    echo 
    $_POST['description'];
    }
    ?>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Make a page called company.php and put this it it
    PHP Code:
    <?php
    if (isset($_POST['submit'])) { 
    echo 
    $_POST['description'];
    }
    ?>
    Then change the form action of page 1 to company.php.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Thank you for the help. Got it all figured out now

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Well I have toyed with this for a little while, that does work but the text doesnt actualy "stick" to the page. Im trying to find a way to edit the content and make it perminent. Im assuming I would need to do some db stuff to accomplish this so I have set up to do this so I have a table called "content" with 2 columns. One called con_id and the other called con_desc. So how would I accomplish the rest of this?

    Thanks for your help

  • #5
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    You could use a $_SESSION variable. It would stay available until the user closed his browser.

    At the top of the company.php page, put:

    PHP Code:
    session_start(); 
    Keep your pages set up the same way, but on the company.php page, use this code instead of the other snippet that was given:

    PHP Code:
    if (isset($_POST['submit'])) { 
       
    $_SESSION['description'] = $_POST['description'];

    Then, you can use $_SESSION['description'] anywhere on your site for as long as the user has the browser open. Let us know if you have more issues. Good luck!

  • #6
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by wayne3503 View Post
    Im trying to find a way to edit the content and make it perminent. Im assuming I would need to do some db stuff to accomplish this so I have set up to do this...
    If this is the case, then yes, you will need to use something like a DB or an editable text file or something. If you have those DB fields created, just do a query to get what is currently in that row and echo it in the text area. Allow the user to change that and have the form POST to the next page. On the next page, have it look to see if the POST isset...if so, do a query to UPDATE the row with the new description. That's a VERY brief overview, but will get you started.

  • #7
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    So just to make sure im on the same page with you this is what yor saying I should do...
    Form page should have something like this...

    $d = $_POST['description'];
    if ($d) {
    require_once ('db.php');
    $query = "INSERT INTO content (description) VALUES ('value', NOW())";
    $result = @mysql_query ($query);
    echo '<textarea name="description"></textarea>';
    }
    What would "value" be?

    Then company.php should have...
    if (isset($_POST['submit'])) {

    UPDATE content
    SET con_desc = con_desc
    WHERE description = '$con_desc
    }

    Ok I have a feeling im way off, I still have some learning of sql yet...am I at all close?

  • #8
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by wayne3503 View Post
    So just to make sure im on the same page with you this is what yor saying I should do...
    Form page should have something like this...

    $d = $_POST['description'];
    if ($d) {
    require_once ('db.php');
    $query = "INSERT INTO content (description) VALUES ('value', NOW())";
    $result = @mysql_query ($query);
    echo '<textarea name="description"></textarea>';
    }
    What would "value" be?
    Ok, I'm not for sure what you're trying to do here. If you're trying to pull the description from the DB (the description is already in there), then you'll need to do a SELECT like this:

    PHP Code:
    $query mysql_query("SELECT description FROM content WHERE con_id = '$the_contents_id'");

    //Then, get the result from that query into a variable we can use
    $results mysql_fetch_array($query);

    //Next, set the variable $description to whatever the description is in the DB for the result of the query
    $description $results['description']; 
    Then just do a shortcut echo statement in the textarea:

    <textarea name="description"><?=$description?></textarea>


    As for the company.php page, try this:

    PHP Code:
    if (isset($_POST['submit'])) { 
       
    $description $_POST['description'];
       
    $query mysql_query("UPDATE content
           SET con_desc = '$description' 
           WHERE con_id = '$con_id'"
    );
    }

    //You'll need to get the con_id from the previous form page or something.  You can put it in a hidden input field, and it will post to this page as well. 

  • #9
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Ok im sorry if I am causing any confusion so Ill try to explain it the best I can. On my site, members will have their own page and on this page is a description of there business in a div. There is a page they can access when they log in, to make edits to their page one of them being the "description". The page they can do this from is just a text area which I will post the code for. So what I want to do is from the page with the textarea (edit_content.php) let them write in a description of there company, hit submit, then that text will be perminetly get added to their page (company.php). Much like if you had a profile somewhere and wanted to give a description of yourself or something.

    edit_content.php
    PHP Code:
    <?php
    //This page displays the files uploaded to the server

    //Set the page title and include the header
    $page_title 'Edit Content';
    include_once (
    'header.php');
    include_once (
    'db.php');
    ?>
    <style>
        fieldset {
         width: 400px;
         }
    </style>


    <div align="center">
    <fieldset>
    <form action="../company.php" method="post">
    <textarea name="description" cols="40" rows="10"></textarea>
    <input type="submit" name="submit" value="Submit" />
    </fieldset>
    </div>

    <?
    include_once ('footer.php'); //require the footer
    ?>
    Sorry for any confusion and thanks agin for all the help

  • #10
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    In that case, since you must already have a DB table for your members (login, name, etc.), just add a field to that table called "business_description" or something like that. And since you'll be using hopefully a unique user ID number for each member, that will be there to allow you to easily access each member's business description. So really, the code I gave you will work fine...you'll just need to change the con_id and all to reflect how your DB is laid out. For instance:

    PHP Code:
    $query mysql_query("SELECT business_description FROM users WHERE user_id = '$the_current_users_id'"); 

    //Then, get the result from that query into a variable we can use 
    $results mysql_fetch_array($query); 

    //Next, set the variable $description to whatever the description is in the DB for the result of the query
    $description $results['description'];



    //company.php

    if (isset($_POST['submit'])) {  
       
    $description $_POST['description'];

       
    $query mysql_query("UPDATE users SET business_description = '$description' WHERE user_id = '$the_current_users_id'"); 

    Does that help you get started? Try some stuff out and see if it works. If you get really stuck, explain away again, but that should at least help guide you.


  •  

    Posting Permissions

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