Page 1 of 1
Simple but I'm stuck!
Posted: Wed Apr 05, 2006 2:24 pm
by abrusky
I developed an intranet for the company I work for and I have an admin section where the owner can acknowledge staff. I have it set up as an input field and it posts on the home page but when you leave the page and return later its gone. How do I make it stay.
Posted: Wed Apr 05, 2006 2:29 pm
by feyd
Make what stay? What was in the input field? If submitted, you can store the data into a session variable quite easily. If the page is not submitted, the server won't know about the data so you may need to use Javascript to store the data into a cookie the server can look for (although it feels like a hack.) There's also an Ajax option, but seems a bit overkill for such a basic thing.
Posted: Wed Apr 05, 2006 2:33 pm
by abrusky
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Its just a few lines of text. My goal is to not have to teach her html. Right now the form is handled by php with the print function. Now I just type in what I want hit submit and it posts the text on the homepage. I need the text to remain there untill the next time it is edited.
Code: Select all
<?php // Script 3.4 - home.php
$text2 = $_POST['text2'];
$text3 = $_POST['text3'];
$text4 = $_POST['text4'];
print " $text2 <p/>";
print " $text3 <p/>";
print " $text4 ";
?>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Wed Apr 05, 2006 2:46 pm
by feyd
For that, you could use a database, or overwrite the existing file with the submitted text.
Posted: Wed Apr 05, 2006 3:19 pm
by abrusky
Thanks. How do I code that? As I said I am new to php
Posted: Wed Apr 05, 2006 3:25 pm
by RobertGonzalez
Start by googling "PHP and MySQL tutorials". Maybe download the first four chapters of Kevin Yanks "How to build a database driven website using PHP and MySQL" from
Sitepoint. Maybe search these forums for database driven web site development or something along those lines. What you want to do is pretty common so I am sure you will find some demos and tutorials out there that will suit your needs.
Posted: Wed Apr 05, 2006 3:34 pm
by abrusky
Thanks!
Posted: Wed Apr 05, 2006 4:55 pm
by abrusky
I there no easier way to make the variables stick than create a data base? I am only working with a few lines of text.
Posted: Wed Apr 05, 2006 5:20 pm
by RobertGonzalez
Variables only "stick" if they have a place to stick to. You will either need to put them into a database or into a file. Otherwise they will only be available within the scope of the script, or the session if you are using sessions.