Simple but I'm stuck!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abrusky
Forum Newbie
Posts: 15
Joined: Wed Apr 05, 2006 2:05 pm
Location: Clearwater FL

Simple but I'm stuck!

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
abrusky
Forum Newbie
Posts: 15
Joined: Wed Apr 05, 2006 2:05 pm
Location: Clearwater FL

Post by abrusky »

feyd | Please use

Code: Select all

,

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

,

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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

For that, you could use a database, or overwrite the existing file with the submitted text.
abrusky
Forum Newbie
Posts: 15
Joined: Wed Apr 05, 2006 2:05 pm
Location: Clearwater FL

Post by abrusky »

Thanks. How do I code that? As I said I am new to php
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
abrusky
Forum Newbie
Posts: 15
Joined: Wed Apr 05, 2006 2:05 pm
Location: Clearwater FL

Post by abrusky »

Thanks!
abrusky
Forum Newbie
Posts: 15
Joined: Wed Apr 05, 2006 2:05 pm
Location: Clearwater FL

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply