PDA

View Full Version : Site Login . . .


el doro
03-10-2006, 11:31 PM
I'm very much a beginner when it comes to PHP.

Just finished a new site for my band, www.fsrock.com, basically i want to add in an update function where by other users, in this case other members of the band can log in to a secure area of the site, and update the news section.

I've already managed to create my login area, but i need help in creating the update page. My original plan was to have a simple form like this (http://www.fsrock.com/admin.php) which would update the news section which is here. (http://www.fsrock.com/home.html) But i really don't know if this is possible or how i'd go about it.

I've searched the web and many script sites for something that might help me, but cant find anything, perhaps i just dont know what i'm looking for!

If anyone could offer any help, or point me in the right direction then that would be great!

Cheers

Pennimus
03-10-2006, 11:37 PM
Yes, its very possible and (relatively speaking) very easy; this is all basic PHP/MySQL stuff.

First, do you have a database set up that stores the news articles?

Although this is slightly out of date, I find myself recommending this tutorial (http://www.freewebmasterhelp.com/tutorials/phpmysql/) again and again simply because I found it so easy to follow when I was learning.

goughy000
03-11-2006, 09:37 PM
you could use cutenews... although if you use the free one it has a small notice at the bottom.. "powered by cute news"

First, do you have a database set up that stores the news articles?

example database table...

-----------------------------------------------------------
id |user | messagetitle | messagecontent | timestamp
-----------------------------------------------------------
1 |user1 | hidy ho! | this is an example | 21:30
2 |goughy| title | example 2... | 22:04

and php to get this data...

<?php
//Connect up
mysql_connect("localhost", "username", "password");
mysql_select_db("database1");

// Query Database
$result = mysql_query("SELECT * FROM table ORDER BY id DESC");

// Go through each message giving out what it reads
while($row = mysql_fetch_array($result)){
echo "<b>$row[messagetitle]</b><br />";
echo "$row[messagecontent]<br />";
echo "Posted by $row[user] @ $row[timestamp]<br /><br />";
}
?>

doni
03-12-2006, 03:12 AM
One thing to keep in mind, you should create a folder OUTSIDE of the public area on the web server.

Place a file in that folder that creates the DB connection. You don't want to have the DB username and password in the public area.

el doro
03-13-2006, 05:25 PM
Thanks for the replies, that tutorial was great, exactly what i've been looking for, it covers all the asoects im trying to incorparate, and its helping me learn what i'm actually doing, rather than copying a script onto my site.

Heres the table i'm working with



-------------------------------------------------------
id | user | title | date | article | time |
-------------------------------------------------------
1 | | | | | |
2 | | | | | |


I've set up 'id' as an auto_integer, so that each new article is assigned a new unique number.

On my form i have the three fields which will provide the data for the 'user' 'title' and 'article' fields.

But here's my question, i want the 'date' and 'time' fields to update automatically . . . how do i do that?

I've set them as date and timestamp types within the table.



Thanks

doni
03-13-2006, 05:39 PM
I assume you're looking to put the CURRENT time/date in these fields--correct?

When you set up the query, pass it 'now()' as the value.

el doro
03-13-2006, 05:57 PM
The time and date when the article is submitted.

So yes, i think, thats the value i want isn't it?

Soi would have:


$time=$_POST['now()'];
$date=$_POST['now()'];

el doro
03-13-2006, 06:25 PM
Ok Seem to be able to upload Data ok to the database, but having a problem calling it and inserting it into my page, heres the code i used:



<?php
//Connect up
mysql_connect("****", "fourstar_db", "****");
mysql_select_db("fourstar_db");

// Query Database
$result = mysql_query("SELECT * FROM table ORDER BY id DESC");

// Go through each message giving out what it reads
while($row = mysql_fetch_array($result)){
echo "<b>$row[title]</b><br />";
echo "$row[date]<br> />" ;
echo "$row[article]<br />";
echo "Posted by $row[user] @ $row[time]<br /><br />";
}
?>



And i get this message:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/home/users/21/fourstar/www/www.fsrock.com/home.php on line 158

I just used the code goughy showed me and altered it to fit, can anyone spot any problems?

el doro
03-13-2006, 08:53 PM
Sorry just realised my mistake, hadn't changed the table name! :o

el doro
03-13-2006, 10:11 PM
Now i have a problem with the 'time' value. I'm Using

$time=$_POST['now()'];

But this just keeps the value at the default of 00:00:00?

goughy000
03-14-2006, 04:34 PM
its not

$time = $_POST['now()'];


its...

$time = now();


i think

el doro
03-14-2006, 10:29 PM
hmmm that just retuns a

Fatal error: Call to undefined function: now() in /usr/home/users/21/fourstar/www/www.fsrock.com/admin.php on line 75

I'll need to have a look on the web and find the correct coding.

But here's something that has me stumped, it's probably going to have a ridiculously simple fix!

my coding

<?php
//Connect up
mysql_connect("********", "fourstar_db", "********");
mysql_select_db("fourstar_db");

// Query Database
$result = mysql_query("SELECT * FROM news ORDER BY id DESC");

// Go through each message giving out what it reads
while($row = mysql_fetch_array($result)){
echo "$row[title]<br />";
echo "$row[date]<br /><br>" ;
echo "$row[article]<br /><br>";
echo "Posted by $row[user] @ $row[time]<br />";
}
?>


Produces exactly what i want, the repeats the last line without the $user variable, so i would get something like this:

Test 2
20/20/20

Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 Test 2 .

Posted by Louis @ 00:00:00





Posted by @ 00:00:00

But i cant see why at all!!

Anybody with any ideas?

el doro
03-15-2006, 10:02 PM
Problemed solved!