Jump to content


Photo

News Adder


  • Please log in to reply
8 replies to this topic

#1 XTTX

XTTX
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 March 2006 - 04:48 AM

OK, I'm designing my scool's Cross Country website, and was wondering what the best way to create a news updater was. I was thinking of an Admin Panel that couldl insert articles and save them into a MySQL DB. Are there other methods of doing this?

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 22 March 2006 - 12:25 AM

[!--quoteo(post=356858:date=Mar 20 2006, 11:48 PM:name=XTTX)--][div class=\'quotetop\']QUOTE(XTTX @ Mar 20 2006, 11:48 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]Admin Panel that couldl insert articles and save them into a MySQL DB.
[/quote]

You said it, my friend.

PHP Ninja

#3 XTTX

XTTX
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 March 2006 - 12:45 AM

Can anyone give an example of a code that would do this? I'm a little lost.

#4 Eddyon

Eddyon
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationEngland

Posted 28 March 2006 - 12:54 AM

What are you lost on exactly? Submitting information to the database?

#5 XTTX

XTTX
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 March 2006 - 01:08 AM

[!--quoteo(post=359099:date=Mar 27 2006, 06:54 PM:name=Eddyon)--][div class=\'quotetop\']QUOTE(Eddyon @ Mar 27 2006, 06:54 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What are you lost on exactly? Submitting information to the database?
[/quote]
Yeah, and how I should grab the information; I'm new to the MySQL DBs.
BTW, when I have a index.php file, then my web site will give me a "Page not found error," but it will work when I change it to index.htm.

#6 Eddyon

Eddyon
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationEngland

Posted 28 March 2006 - 01:25 AM

Well first you must make a table in your MySQL database called news with the following fields:
  • id (auto increment)
  • headline
  • article
Next you need to create a form to input the news into, say you have 2 fields, one called 'headline' and another called 'article'. Just for the sake of explaining we can say this file is called addnews.php, and you need to put the form action to post to insertnews.php.

On insertnews.php you first need to connect to the database (if you dont know how click [a href=\"http://www.phpfreaks.com/quickcode/Connect-to-MySQL-Server/29.php?higlight=connect+to+database\" target=\"_blank\"]here[/a]), and you then need to fetch the things you posted, so we set the as variables like this...

$headline = $_POST['headline'];

$article = $_POST['article'];

and now we just do a simple database query to insert the information.

mysql_query("INSERT INTO news (headline, article) VALUES ('$headline', '$article')") or die(mysql_error());

-------------------------------------------------

of corse this is a very basic way with no error checking or anything, but I thought best keep it simple whilst you are learning.

Im goin to bed now but will be back on tomorrow, (if someone hasn't already helped you by then) and if you get on ok with what I just said I will explain how you display it.

#7 khendar

khendar
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 28 March 2006 - 01:29 AM

You'll need to make a form which has fields for the data you want to insert. eg

<form name="news" action="script.php" method="post">
<input type="text" name="headline">
<textarea name="newsbody"></textarea>
<input type="submit" name="submit" value="Submit">
</form>

Then you have a script (eg script.php) which you have pointed your form at which accepts the data and inserts it into your database.

if(isset($_POST['submit'])
{
$headline = $_POST['headline'];
$body = $_POST['newsbody'];

$linkid = mysql_connect('dbhost', 'dbusername', 'dbpassword');
mysql_select_db('dbname', $linkid)
$query = "insert into news_table (headline, body) values ('$headline', '$body')";
$result = mysql_query($query, $linkid);
}

This is very basic without any error handling and such but should get you started.

Lol...dammit Eddyon beat me by a whole minute (or 4).

#8 Eddyon

Eddyon
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationEngland

Posted 28 March 2006 - 01:31 AM

lol sorry khendar, ill let you carry on.. Goodnight.

#9 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 28 March 2006 - 04:15 AM

You need to check with your server to make sure they have PHP support and see what can be done to add index.php to the default document list.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users