Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1611 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Need some help

Thread title: Need some help
Closed Thread    
    Thread tools Search this thread Display Modes  
07-29-2008, 08:44 AM
#1
Caden is offline Caden
Status: Junior Member
Join date: Jul 2006
Location: Denver, Colorado
Expertise:
Software:
 
Posts: 66
iTrader: 0 / 0%
 

Caden is on a distinguished road

Send a message via AIM to Caden Send a message via MSN to Caden

  Old  Need some help

Okay I am creating this very simple content management system, and the news system in it isn't working correctly. Anyway, I need a way to show the last 5 articles submitted. So the code I have to do that is:

Code:
$query = "SELECT ID,title,article FROM news ORDER BY ID DESC LIMIT 0,5";
When I click submit, the index page won't show my first article, until I post another article after that. So if I have 4 articles, the 4th article won't show until I post a 5th one, and when I post a 5th one, it won't show until I post a 6th one.. and so on. What could be the problem? And also I don't think I save the form data in the database correctly. Here is the code, is it correct or not?

Code:
$newArticle = "INSERT INTO news (title,category,article) VALUES (".
"'".$HTTP_POST_VARS['title']."',".
"'".$HTTP_POST_VARS['category']."',".
"'".$HTTP_POST_VARS['article']."')"; 
$result = mysql_query($newArticle);
if (!$result) {
die('Could not load form: ' .mysql_error());
}

07-29-2008, 09:47 AM
#2
creativejen is offline creativejen
Status: Paladin
Join date: Jul 2006
Location: Sheffield, UK
Expertise: design, front-end markup
Software: Photoshop
 
Posts: 2,353
iTrader: 25 / 96%
 

creativejen is an unknown quantity at this point

Send a message via MSN to creativejen

  Old

LIMIT 5 instead of LIMIT 0,5

07-29-2008, 01:26 PM
#3
ThinkMinds is offline ThinkMinds
ThinkMinds's Avatar
Status: I'm new around here
Join date: Jul 2008
Location: Toronto, Canada
Expertise:
Software:
 
Posts: 19
iTrader: 0 / 0%
 

ThinkMinds is on a distinguished road

  Old

Hi there!

just on a side note, $HTTP_POST_VARS is actually replaced by $_POST in PHP5 - so you should try to use $_POST instead. I'd also assign variables to the $_POST values and rewrite the above as such:

---

$title = $_POST['title'];
$category = $_POST['category'];
$article = $_POST['article'];

$newArticle = "INSERT INTO news (title,category,article) VALUES ('$title', '$category', '$article')";

$result = mysql_query($newArticle);

if (!$result) {
die('Could not load form: ' .mysql_error());
}

---

Cheers,

Mike

07-30-2008, 08:26 AM
#4
Caden is offline Caden
Status: Junior Member
Join date: Jul 2006
Location: Denver, Colorado
Expertise:
Software:
 
Posts: 66
iTrader: 0 / 0%
 

Caden is on a distinguished road

Send a message via AIM to Caden Send a message via MSN to Caden

  Old

Oh really? I knew that method, the $_POST, I was just reading off of a tutorial on how to create a simple content management system online, so it was an old one, I didn't know they did the same thing, but now I know they do I will do it that way. Thanks a lot. And thank you also enigma.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed