ibab Posted May 13, 2010 Share Posted May 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/ Share on other sites More sharing options...
.Stealth Posted May 13, 2010 Share Posted May 13, 2010 <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> Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057883 Share on other sites More sharing options...
ibab Posted May 13, 2010 Author Share Posted May 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057885 Share on other sites More sharing options...
.Stealth Posted May 13, 2010 Share Posted May 13, 2010 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057890 Share on other sites More sharing options...
ibab Posted May 13, 2010 Author Share Posted May 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057897 Share on other sites More sharing options...
.Stealth Posted May 13, 2010 Share Posted May 13, 2010 <?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]. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057904 Share on other sites More sharing options...
ibab Posted May 13, 2010 Author Share Posted May 13, 2010 Changing that shouldn't give it any effect, only that it searches for id which it never founds, because in MySQL its ID, not id. I think the whole script is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057907 Share on other sites More sharing options...
Maq Posted May 13, 2010 Share Posted May 13, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057909 Share on other sites More sharing options...
ibab Posted May 13, 2010 Author Share Posted May 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057923 Share on other sites More sharing options...
ibab Posted May 13, 2010 Author Share Posted May 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057934 Share on other sites More sharing options...
Maq Posted May 13, 2010 Share Posted May 13, 2010 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)? Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057951 Share on other sites More sharing options...
iblood Posted May 13, 2010 Share Posted May 13, 2010 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'" Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1057955 Share on other sites More sharing options...
ibab Posted May 14, 2010 Author Share Posted May 14, 2010 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) Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1058121 Share on other sites More sharing options...
Maq Posted May 14, 2010 Share Posted May 14, 2010 Please post the current code and the errors you're receiving. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1058283 Share on other sites More sharing options...
.Stealth Posted May 14, 2010 Share Posted May 14, 2010 Did you change this bit when i said? $ID = $_POST['ID']; It could be that as you have to $_POST being sent. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1058293 Share on other sites More sharing options...
ibab Posted May 14, 2010 Author Share Posted May 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1058356 Share on other sites More sharing options...
Maq Posted May 14, 2010 Share Posted May 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1058366 Share on other sites More sharing options...
ibab Posted May 14, 2010 Author Share Posted May 14, 2010 When I click on the link, it takes me to this site. http://localhost/news/view.php?id=2 It adds the right id there. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1058383 Share on other sites More sharing options...
Maq Posted May 14, 2010 Share Posted May 14, 2010 When I click on the link, it takes me to this site. http://localhost/news/view.php?id=2 It adds the right id there. PHP variables are case sensitive. So if your HTTP variable is 'id' then use 'id' NOT 'ID'. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1058496 Share on other sites More sharing options...
ibab Posted May 14, 2010 Author Share Posted May 14, 2010 I'm just wondering, because in PHPMyAdmin I've setted it as ID, not id. 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. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1058519 Share on other sites More sharing options...
.Stealth Posted May 14, 2010 Share Posted May 14, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1058521 Share on other sites More sharing options...
ibab Posted May 14, 2010 Author Share Posted May 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201662-my-news-system/#findComment-1058523 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.