Jump to content

help making a basic CMS


fh8r

Recommended Posts

i think this might be my first post here. i'm shy.

<? // If someone has posted news then global variables will be set. If they are set, connect and post the info to the db //if (isset($_POST[txtNewsSubject]) && isset($_POST[txtNews])) {$con = mysql_connect ("localhost", "######", "######") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("halifaxc_csaforum");mysql_query ("INSERT INTO news (newsID, newsDate, newsSubject, newsAuthor, newsBody) VALUES ('', 'CURDATE()', '$_POST[txtNewsSubject]', 'fh8r', '$_POST[txtNews]");} ?> 

i'm just trying to post a news update to a mysql db using two $_POST variables the page doesn't really output anything so i have to keep refreshing in phpmyadmin to see if the INSERT was successful, but so far non luck.any assistance would be appreciated!edit: oh wow phpmyadmin is great for teaching you SQL while giving you an easy way to work with your database. nifty. seems like i'm now on the way to fixing the problem.

Link to comment
Share on other sites

That's cuz the $_POST variables are global arrays, so its positions must be in inverted commas:$_POST["txtNewsSubject"]$_POST["txtNews"]You might also want to assign those values to two variables:

$txtNewsSubject=$_POST["txtNewsSubject"];$txtNews=$_POST["txtNews"];

and ask for them:

if (isset($txtNewsSubject) && isset($txtNews))...

Link to comment
Share on other sites

That actually does not matter, quotation marks will speed up script execution but without them PHP only issues a notice. Try echoing mysql_error() after the mysql_query() to see whether anything went wrong.

Link to comment
Share on other sites

thanks for the suggestions, as i said phpmyadmin helped fix up the syntax a bit. inserting isn't the problem now, it's selecting and echoing the 5 most recent news postings from the table.

$result = mysql_query("SELECT *FROM `news`ORDER BY `newsID` DESCLIMIT 5 , 5");

what this does at the moment is displays 5 news articles. so far i have 11 rows in the table and it displays newsID 2-6 :) at the moment i would like to show newsID 7, 8, 9, 10, 11edit: hahah again i got it, all i did was make it say LIMIT 5 and voila! it displays the 5 most recent entries

Link to comment
Share on other sites

If you wanna echo the tables and its values in your page, you'll need another mysql function:Let's guess we have a table called users whose fields are id, name, phone:

$query="select * from users";$result=mysql_query($query);//This is the good partwhile ($k=mysql_fetch_object($result))  echo $k->id." ".$k->name." ".$k->phone;

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...