XTTX Posted March 21, 2006 Share Posted March 21, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/5395-news-adder/ Share on other sites More sharing options...
Caesar Posted March 22, 2006 Share Posted March 22, 2006 [!--quoteo(post=356858:date=Mar 20 2006, 11:48 PM:name=XTTX)--][div class=\'quotetop\']QUOTE(XTTX @ Mar 20 2006, 11:48 PM) [snapback]356858[/snapback][/div][div class=\'quotemain\'][!--quotec--]Admin Panel that couldl insert articles and save them into a MySQL DB.[/quote]You said it, my friend. Quote Link to comment https://forums.phpfreaks.com/topic/5395-news-adder/#findComment-19520 Share on other sites More sharing options...
XTTX Posted March 28, 2006 Author Share Posted March 28, 2006 Can anyone give an example of a code that would do this? I'm a little lost. Quote Link to comment https://forums.phpfreaks.com/topic/5395-news-adder/#findComment-21398 Share on other sites More sharing options...
Eddyon Posted March 28, 2006 Share Posted March 28, 2006 What are you lost on exactly? Submitting information to the database? Quote Link to comment https://forums.phpfreaks.com/topic/5395-news-adder/#findComment-21403 Share on other sites More sharing options...
XTTX Posted March 28, 2006 Author Share Posted March 28, 2006 [!--quoteo(post=359099:date=Mar 27 2006, 06:54 PM:name=Eddyon)--][div class=\'quotetop\']QUOTE(Eddyon @ Mar 27 2006, 06:54 PM) [snapback]359099[/snapback][/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. Quote Link to comment https://forums.phpfreaks.com/topic/5395-news-adder/#findComment-21410 Share on other sites More sharing options...
Eddyon Posted March 28, 2006 Share Posted March 28, 2006 Well first you must make a table in your MySQL database called news with the following fields:[list][*]id (auto increment)[*]headline[*]article[/list]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. Quote Link to comment https://forums.phpfreaks.com/topic/5395-news-adder/#findComment-21414 Share on other sites More sharing options...
khendar Posted March 28, 2006 Share Posted March 28, 2006 You'll need to make a form which has fields for the data you want to insert. eg[code]<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>[/code]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.[code]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);}[/code]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). Quote Link to comment https://forums.phpfreaks.com/topic/5395-news-adder/#findComment-21415 Share on other sites More sharing options...
Eddyon Posted March 28, 2006 Share Posted March 28, 2006 lol sorry khendar, ill let you carry on.. Goodnight. Quote Link to comment https://forums.phpfreaks.com/topic/5395-news-adder/#findComment-21416 Share on other sites More sharing options...
txmedic03 Posted March 28, 2006 Share Posted March 28, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/5395-news-adder/#findComment-21447 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.