...

View Full Version : stupid echo question



wayne3503
07-30-2007, 02:09 AM
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.

<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'];
}
?>

_Aerospace_Eng_
07-30-2007, 03:16 AM
Make a page called company.php and put this it it

<?php
if (isset($_POST['submit'])) {
echo $_POST['description'];
}
?>
Then change the form action of page 1 to company.php.

wayne3503
07-30-2007, 04:39 AM
Thank you for the help. Got it all figured out now :D

wayne3503
07-30-2007, 05:42 PM
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

JohnDubya
07-30-2007, 06:56 PM
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:


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:



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

JohnDubya
07-30-2007, 06:59 PM
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.

wayne3503
07-30-2007, 08:36 PM
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?

JohnDubya
07-30-2007, 09:16 PM
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:



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


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.

wayne3503
07-30-2007, 09:56 PM
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
//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

JohnDubya
07-30-2007, 10:41 PM
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:



$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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum