Jump to content

My News System


ibab

Recommended Posts

I've visited few forums to try to figure out what is wrong and how to fix this but no help so far, so I'll give it a try here.

 

I created a news system like a year ago, but I would like to improve it a bit.

Basically, what I want it to be like, is a table with "Subject", "Poster" and "Date".

The Subjects are links to a page named view.php which should then show the text and other information related to this subject.

 

So, I created a index.php which includes the stuff to get subjects from the database and give them a link to view.php, but this seemed not to work.

 

index.php

<table border="0">
<tr><td class="subcjet"><span><b>Subject</b></span></td><td class="header"><b>Poster</b></td><td class="header"><b>Date</b></td></tr>

<?php
require("config.php");

$ID = $_POST['ID'];
$query = mysql_query('SELECT * FROM news ORDER BY ID DESC LIMIT 10');
while($row = mysql_fetch_assoc($query))

echo '<tr><td><a href="view.php" name="ID">'.$row['Subject'].'</a></td><td>'.$row['User'].'</td><td>'.$row['Date'].'</td></tr>';

?>

 

view.php

<?php
require("config.php");

$ID = $_GET['ID'];
$query = mysql_query('SELECT * FROM news WHERE ID = "$ID"') or die(mysql_error());
while($row = mysql_fetch_assoc($query))

echo '<span><strong>'.$row['Subject'].'</strong> - <font size="2">Posted by '.$row['User'].' on '.$row['Date'].'</span><br /><br></font>'.str_replace(chr(10), '<br>', $row['Text']).'<hr />';

?>

 

I don't know if thats even a bit into the right way to do something such as this.

Basically, I've tried just to make a thing to get an ID from the Subject and show the whole row for the ID.

 

Any help to get this working like I am trying to would be great and I would be thankful.

Link to comment
Share on other sites

<table border="0">
<tr><td class="subcjet"><span><b>Subject</b></span></td><td class="header"><b>Poster</b></td><td class="header"><b>Date</b></td></tr>

<?php
require("config.php");

$ID = $_POST['ID'];
$query = mysql_query('SELECT * FROM news ORDER BY ID DESC LIMIT 10');
while($row = mysql_fetch_assoc($query)){

echo '<tr><td><a href="view.php" name="ID">'.$row['Subject'].'</a></td><td>'.$row['User'].'</td><td>'.$row['Date'].'</td></tr>';
}
?>

 

<?php
require("config.php");

$ID = $_GET['ID'];
$query = mysql_query('SELECT * FROM news WHERE ID = "$ID"') or die(mysql_error());
while($row = mysql_fetch_assoc($query)){

echo '<span><strong>'.$row['Subject'].'</strong> - <font size="2">Posted by '.$row['User'].' on '.$row['Date'].'</span><br /><br></font>'.str_replace(chr(10), '<br>', $row['Text']).'<hr />';
}
?>

 

Try that.

 

Also, where is there a form being sent off? I ask because you are using the $_POST here:

 

$ID = $_POST['ID'];

 

 

And i think you have spelt "subject" wrong here, unless you meant to?

 

<tr><td class="subcjet"><span><b>Subject</b></span></td><td class="header"><b>Poster</b></td><td class="header"><b>Date</b></td></tr>

Link to comment
Share on other sites

Theres no form actually, I didn't know that the $_POST was used for only that.

But still nothing. When I click on the subject, it shows just view.php which is empty, no text at all.

 

And how you mean subject wrongly?

EDIT: Oh right, I've typoed in that part, but I think it should not have effect on the script.

Link to comment
Share on other sites

Sorry i forgot to put the ID in the link:

 


<table border="0">
<tr><td class="subcjet"><span><b>Subject</b></span></td><td class="header"><b>Poster</b></td><td class="header"><b>Date</b></td></tr>

<?php
require("config.php");

$ID = $_POST['ID'];
$query = mysql_query('SELECT * FROM news ORDER BY ID DESC LIMIT 10');
while($row = mysql_fetch_assoc($query)){

echo '<tr><td><a href="view.php?id="' . $row['id'] . '" name="ID">'.$row['Subject'].'</a></td><td>'.$row['User'].'</td><td>'.$row['Date'].'</td></tr>';
}
?> 

Link to comment
Share on other sites

There was .$row['id']. but its .$row['ID'].

Oh well, still nothing. It does add this "view.php?id=" but it haven't helped yet.

I don't know, but somewhy it doesn't get the id for the post into the url like it probably should, right?

 

EDIT: Well, I took from the link the one " which was not supposed to be there, and now it gets the post ID into the link.

view.php?id=2

 

But it still shows just a blank site.

Link to comment
Share on other sites

<?php
require("config.php");

$ID = $_GET['id'];
$query = mysql_query('SELECT * FROM news WHERE ID = "$ID"') or die(mysql_error());
while($row = mysql_fetch_assoc($query)){

echo '<span><strong>'.$row['Subject'].'</strong> - <font size="2">Posted by '.$row['User'].' on '.$row['Date'].'</span><br /><br></font>'.str_replace(chr(10), '<br>', $row['Text']).'<hr />';
}
?>

 

Try that, i've changed the $_GET[iD] to $_get[id].

Link to comment
Share on other sites

There was .$row['id']. but its .$row['ID'].

Oh well, still nothing. It does add this "view.php?id=" but it haven't helped yet.

I don't know, but somewhy it doesn't get the id for the post into the url like it probably should, right?

 

EDIT: Well, I took from the link the one " which was not supposed to be there, and now it gets the post ID into the link.

view.php?id=2

 

But it still shows just a blank site.

 

A blank page usually indicates a fatal error.  Try putting these two lines directly after your opening PHP tag:

 

ini_set ("display_errors", "1"); 
error_reporting(E_ALL);

Link to comment
Share on other sites

Sorry for the double post, but the edit button just was not appearing in my newest post.

I just found this one from the "Beta Testing" section of this forum.

What I am trying to do, is something like this.

 

http://www.hssz.net/sz/?catId=7

 

Its not exactly like it, but a bit editing would probably make it to be what I am trying to do.

Basically, it has the Subject which is link to the main content related to the Subject.

Link to comment
Share on other sites

I added those and it gave error of those $_GET and $_POST, I took them off and it didn't give error anymore, but the site was still blank.

 

Instead of just removing them why don't you try to fix the error?  What were the error(s)?

Link to comment
Share on other sites

on your query on view.php you used (

'SELECT * FROM news WHERE ID = "$ID"'

) <- single quote..So I guess the script searches for the value '$ID' literally, and not the value of $ID,

Have you tried using double quotes?

"SELECT * FROM news WHERE ID = '$ID'"

Link to comment
Share on other sites

It says this about the $_GET['ID'].

Notice: Undefined index: ID in C:\WWW\xampp\htdocs\news\view.php  on line 7

 

When I took it off and edited it to look like this.

"SELECT * FROM news WHERE ID = '$ID'"

 

It gave the same error.

Notice: Undefined index: ID in C:\WWW\xampp\htdocs\news\view.php  on line 7 (Here its the same line because the $_GET['ID'] is right on top of the SELECT thingy)

 

Link to comment
Share on other sites

Currently only errors I get is in view.php.

Notice: Undefined variable: ID in C:\WWW\xampp\htdocs\news\view.php  on line 7

 

Stealth, yes, I tried changing it, still the same.

 

Your link in index.php doesn't pass a variable 'ID'.  The result of this is the error above, when you try to retrieve it and assign $ID to it again.  What does your link look like when you get to view.php?  Echo out your variables and query statements to ensure they are correct.

Link to comment
Share on other sites

I'm just wondering, because in PHPMyAdmin I've setted it as ID, not id.

21lpfyo.png

So basically, it should be view.php?ID=2, right?

 

EDIT: Finally! I just changed the view.php?id= to view.php?ID= and it worked.

Thank you for everyone who helped me, especially .Stealth and Maq.

Link to comment
Share on other sites

The ID in the database and the ID in the query string (in the url) have no relation to the database. It just sets the name you call it by, it could be anything you want.

 

In your script you must have changed $_GET to a value of ID somewhere, I'm sure it was lower case before. Still, its working now!

Link to comment
Share on other sites

The ID in the database and the ID in the query string (in the url) have no relation to the database. It just sets the name you call it by, it could be anything you want.

 

In your script you must have changed $_GET to a value of ID somewhere, I'm sure it was lower case before. Still, its working now!

It always was ID, never id, well, only when you told me to try out that, but after that I changed it back to ID.

And yeah, its working now and thats the main thing.

Thanks a lot.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.