Noskiw Posted November 3, 2009 Share Posted November 3, 2009 blog.php <?php $title = "Blog"; $connect = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("blog", $connect) or die(mysql_error()); function bbcode($string) { if ($string) { $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]', ' ', '', ''); $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>', '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">', '</div></center>', '<img src="', '">', '<img src="http://localhost/images/P.gif" />'); $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string); return $new_string_2; } } echo "<h1>Blog</h1>\n"; $query = mysql_query("SELECT * FROM blog"); if (mysql_num_rows($query) == 0) { echo "<hr />There are no posts yet, make the first in the admin section!\n"; } else { while ($row = mysql_fetch_assoc($query)) { echo "<hr />"; $id = $row['id']; $title2 = $row['title']; $name = $row['name']; $email = $row['email']; $post = $row['post']; $date = $row['date']; $time = $row['time']; echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " . $name . "(" . $email . ") at " . $time . " on " . $date . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(substr($post,0,201), wordwrap($post, 118, "<br />", true)))); if(strlen($post) > 201){ echo "...<a href='./index.php?p=blog&p=post&id='" . $id . "'>Read More</a></td></tr></table>\n"; }else{ echo "</td></tr></table>\n"; } } } echo "<hr />\n"; echo "Are you an admin? <a href='index.php?p=blog&p=credentials'>Place a post</a>\n"; ?>[/code] I also need it to only select the post from the id that it is on. post.php <?php $title = "View Post:" . $title2; function bbcode($string) { if ($string) { $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]', ' ', '', ''); $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>', '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">', '</div></center>', '<img src="', '">', '<img src="http://localhost/images/P.gif" />'); $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string); return $new_string_2; } } $connect = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("blog", $connect) or die(mysql_error()); $q = mysql_query("SELECT * FROM blog"); while($row = mysql_fetch_assoc($q)){ $title2 = $row['title']; $name = $row['name']; $email = $row['email']; $post = $row['post']; $date = $row['date']; $time = $row['time']; echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " . $name . "(" . $email . ") at " . $time . " on " . $date . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(wordwrap($post, 118, "<br />", true)))); } ?>[/code] My main problems are: The id comes up with - http://localhost/dynamic web page/index.php?p=blog&p=post&id= The post.php shows both posts that are entered in the database Quote Link to comment https://forums.phpfreaks.com/topic/180176-solved-problem-with-getting-to-id-of-a-post/ Share on other sites More sharing options...
Noskiw Posted November 3, 2009 Author Share Posted November 3, 2009 bumpety bumpety bump.... Quote Link to comment https://forums.phpfreaks.com/topic/180176-solved-problem-with-getting-to-id-of-a-post/#findComment-950472 Share on other sites More sharing options...
Noskiw Posted November 3, 2009 Author Share Posted November 3, 2009 Please someone help me. This is becoming an increasing problem. It is escalating to the point where I'm beginning to pick up a different language entirely. Quote Link to comment https://forums.phpfreaks.com/topic/180176-solved-problem-with-getting-to-id-of-a-post/#findComment-950544 Share on other sites More sharing options...
mikesta707 Posted November 3, 2009 Share Posted November 3, 2009 it is because here echo "...<a href='./index.php?p=blog&p=post&id='" . $id . "'>Read More</a></td></tr></table>\n"; you are closing your href attribute with the following href='./index.php?p=blog&p=post&id=' you dont need to surround get values with quotes. echo "...<a href='./index.php?p=blog&p=post&id=" . $id . ">Read More</a></td></tr></table>\n"; for the record, not many people care if you change what programming language you use. Quote Link to comment https://forums.phpfreaks.com/topic/180176-solved-problem-with-getting-to-id-of-a-post/#findComment-950545 Share on other sites More sharing options...
Noskiw Posted November 3, 2009 Author Share Posted November 3, 2009 That worked. You must think i'm schizophrenic now. Could you possibly help me with the post now? I want to know how to make it only show the post that the 'id' in the address bar refers to. Quote Link to comment https://forums.phpfreaks.com/topic/180176-solved-problem-with-getting-to-id-of-a-post/#findComment-950547 Share on other sites More sharing options...
mikesta707 Posted November 3, 2009 Share Posted November 3, 2009 $id = $_GET['id']; //make sure you sanitize $id at some point $q = mysql_query("SELECT * FROM blog WHERE id='$id'" ); Quote Link to comment https://forums.phpfreaks.com/topic/180176-solved-problem-with-getting-to-id-of-a-post/#findComment-950549 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.