I made a basic website for my sons' garage band, and they want on the front page to have a box that the four of them can update with the 'latest news' - so I want it to be something they's have to log in to use, or at least enter a password to get into, and then have the 'news' they post show up on the front page of their site. Right now the page is an index.html page. I am thinking that PhP can probably do this pretty easily, but I dont know where to find a script about it, or how to configure it so that it will show the latest news articles on the home page.. Any directions or ideas?

do you have access to a database? if so then i wouldn't bother with loggin in, as that would be too much work for the sole purpose of adding latest news.
Create a new php page with a form use that has everything you want, and then just put a password field as one of the inputs, if the password isn't correct then don't update. if the password is correct then add it to the database.

woohoo, thanks!

Paradox, what you have posted is a bit beyond my current ability without some handholding - I will probably try the links in the next post, if not I may come back and ask you to hold my hand while walking through the php page!!

Database is really made for this but if you have no db, you can get pretty creative and use fopen & fwrite to write a text file to your server. The password dealy mentioned above would help as a simple authentication, nothing happens if password isn't right. So if you have a form input named mytext...

$file_name = fopen("/path/to/homedir/myfile.txt","w+");
$file = $HTTP_POST_VARS["mytext"];
fwrite($file_name,$file);
fclose($file_name);

Then your page could include the text file.
<? include 'myfile.txt'; ?>

You might make a blank file on the server to get started. Also make sure apache can write to it!!!

Good luck

I have access to mysql databases, so I could do that, but the problem is that the only database and php I know so far came from admin'ing my vbulletins and hacking them.. LOL - I don't really know how to do one from scratch. Also the main home page is an index.html file, and I need to turn it into an index.php file I think - and I am not sure how to do that... D'oh! Any more advice??

I have access to mysql databases, so I could do that, but the problem is that the only database and php I know so far came from admin'ing my vbulletins and hacking them.. LOL - I don't really know how to do one from scratch. Also the main home page is an index.html file, and I need to turn it into an index.php file I think - and I am not sure how to do that... D'oh! Any more advice??

Aha, you're in good shape then. You can just rename your page index.php and you won't know any difference until you start to add some actual php tags.

you'll need to do 2 things...

1) Put data in

As far as getting the data in, you'll need make a database table to store this data. Hopefully you have access to phpMyAdmin or a Webmin/UserMin access to MySQL. Get there, and make a table. Something simple, say name it content and have one field called text and use another as the id. You probably can do that through whatever web interface or find a place to give a SQL command of:

CREATE TABLE `content` (
`id` INT( 4 ) NOT NULL AUTO_INCREMENT ,
`text` TEXT NOT NULL ,
PRIMARY KEY ( `id` )
);

Then make a new php page on your site, say called input.php. This page will have the form and also the action part of inputting the text.

input.php would look something like this.
<?
if ($submit && ($password == "kidspassword)) {
// let me talk to the database using my mysql username and mysql password
$myconnect = mysql_connect("localhost","username","password");
mysql_select_db("databasename",$myconnect); // not tablename but db name

mysql_query("REPLACE INTO content ('id','text') VALUES ('1','$text')
or die(mysql_error());

echo "Did it!";?>
<html><body>
<form>
Input the text for the page:
<textarea name="text" cols="20" rows="5"></textarea>
Password: <INPUT type="password" name="password">
<INPUT type="submit" name="submit"></form>
</body></html>

You can add additional areas by duplicating and changing the 1 to a 2 or whatever.

2) Get data out

On index.php..

<? // again let me talk to the database
$myconnect = mysql_connect("localhost","username","password");
mysql_select_db("databasename",$myconnect); // not tablename but db name
?><html><body>

etc etc
<? // Pull text out and make purty
$my_text = mysql_result(mysql_query("SELECT text FROM content
WHERE id = '1' "),0);
echo nl2br(stripslashes($my_text));
?>
etc </body></html>

The nl2br will put <br/> tags in on each line break and the stripslashes will take out any \' or \" that find their way in.

Untested and untried but worth every penny you paid for it!

:D

Thanks barnamos - I am going to try this this weekend and see if I can get it to work!!

You bumped into a 2.5 yr old thread :) !

socialopen is from google

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.