June 27, 201115 yr Notice: Undefined index: title in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186 Notice: Undefined index: message in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186 Notice: Undefined index: author in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186 <?php mysql_connect("localhost", "root", ""); mysql_select_db("test"); ?> <form action="newthread.php" method="POST"> Your Name: <input type="text" name="author"><br> Thread Title: <input type="text" name="title"><br> Thread:<br><textarea cols="60" rows="5" name="message"></textarea><br> <input type="submit" value="Post Thread"> </form> <br/> <?php mysql_connect("localhost", "root", ""); mysql_select_db("test"); $time = time(); mysql_query("INSERT INTO threads VALUES(NULL,'$_POST[title]','$_POST[message]','$_POST[author]','0','$time')"); echo "Thread Posted.<br><a href='index.php'>Return</a>"; ?>
June 27, 201115 yr Author I'm a bit lazy to doublecheck, but here it goes: mysql_query("INSERT INTO threads VALUES (NULL," . $_POST['title'] . "," . $_POST['message'] . "," . $_POS['author'] . ", 0," . $time . ")"); Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186
June 27, 201115 yr Author I think that's because of the typo I left, note the last $_POST. Try this mysql_query("INSERT INTO threads VALUES (NULL," . $_POST['title'] . "," . $_POST['message'] . "," . $_POST['author'] . ", 0," . $time . ")"); That solved that problem but its now displaying Notice: Undefined index: title in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186 Notice: Undefined index: message in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186 Notice: Undefined index: author in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186 AGAIN
June 27, 201115 yr That solved that problem but its now displaying Notice: Undefined index: title in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186 Notice: Undefined index: message in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186 Notice: Undefined index: author in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186 AGAIN ur not checking if ur variables are set before using them $title = (isset($_POST['title'])) ? mysql_real_escape_string($_POST['title']) : ''; $message = (isset($_POST['message'])) ? mysql_real_escape_string($_POST['message']) : ''; $author = (isset($_POST['author'])) ? mysql_real_escape_string($_POST['author']) : ''; mysql_query("INSERT INTO threads VALUES (NULL," . $title . "," . $message . "," . $author . ", 0," . $time . ")"); EDIT: I'd also suggest looking at using prepared statements there alot safer, and are not vulnerable to mysql injections a simple prepared statement may look like this $conn = //connection; $SQL = "INSERT INTO `table` (title,author,message) VALUES(:title,:message,:author)"; try{ $st = $conn->prepare( $SQL ); $st->bindValue(":title",$title,PDO::PARAM_STR); $st->bindValue(":message",$message,PDO::PARAM_STR); $st->bindValue(":author",$author,PDO::PARAM_STR); $st->execute(); }catch(PDOException $e){ echo "Failed PDO query " . $e->getMessage(); } Edited June 27, 201115 yr by webdesigner93
June 27, 201115 yr Can you echo the query to see what it's actually saying to the database? Then post that up, let's have a look at what it says.
June 27, 201115 yr ur not checking if ur variables are set before using them $title = (isset($_POST['title'])) ? mysql_real_escape_string($_POST['title']) : ''; $message = (isset($_POST['message'])) ? mysql_real_escape_string($_POST['message']) : ''; $author = (isset($_POST['author'])) ? mysql_real_escape_string($_POST['author']) : ''; mysql_query("INSERT INTO threads VALUES (NULL," . $title . "," . $message . "," . $author . ", 0," . $time . ")"); Yeah this. Agreed.
June 27, 201115 yr Author ur not checking if ur variables are set before using them $title = (isset($_POST['title'])) ? mysql_real_escape_string($_POST['title']) : ''; $message = (isset($_POST['message'])) ? mysql_real_escape_string($_POST['message']) : ''; $author = (isset($_POST['author'])) ? mysql_real_escape_string($_POST['author']) : ''; mysql_query("INSERT INTO threads VALUES (NULL," . $title . "," . $message . "," . $author . ", 0," . $time . ")"); All sorted now (fingers crossed) thanks! no more error codes displayed! Although wrote some more and got Notice: Use of undefined constant posted - assumed 'posted' in C:\xampp\htdocs\mywebsite\Untitled9.php on line 203 <?php // We are selecting everything from the threads section in the database and ordering them newest to oldest. $sql = mysql_query("SELECT * FROM threads ORDER BY posted DESC"); // Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r[posted]); // Now we will show the available threads echo "<h3><a href='msg.php?id=$r[id]'>$r[title]</a> ($r[replies])</h3><h4>Posted by $r[author] on $posted</h4>"; // End of Array } ?> Edited June 27, 201115 yr by louis moore
June 27, 201115 yr All sorted now (fingers crossed) thanks! no more error codes displayed! Although wrote some more and got Notice: Use of undefined constant posted - assumed 'posted' in C:\xampp\htdocs\mywebsite\Untitled9.php on line 203 <?php // We are selecting everything from the threads section in the database and ordering them newest to oldest. $sql = mysql_query("SELECT * FROM threads ORDER BY posted DESC"); // Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r[posted]); // Now we will show the available threads echo "<h3><a href='msg.php?id=$r[id]'>$r[title]</a> ($r[replies])</h3><h4>Posted by $r[author] on $posted</h4>"; // End of Array } ?> Need single quotes around posted other wise it will be classified as a constant $posted = date("jS M Y h:i",$r['posted']); Edited June 27, 201115 yr by webdesigner93
June 27, 201115 yr Author To summarize, if you want to have it all in one file, it has to be something like this: <?php if (!$_POST) : ?> <form action="newthread.php" method="POST"> Your Name: <input type="text" name="author"><br> Thread Title: <input type="text" name="title"><br> Thread:<br><textarea cols="60" rows="5" name="message"></textarea><br> <input type="submit" value="Post Thread"> </form> <br/> <?php else : mysql_connect("localhost", "root", ""); mysql_select_db("test"); $time = time(); $title = (isset($_POST['title'])) ? mysql_real_escape_string($_POST['title']) : ''; $message = (isset($_POST['message'])) ? mysql_real_escape_string($_POST['message']) : ''; $author = (isset($_POST['author'])) ? mysql_real_escape_string($_POST['author']) : ''; mysql_query("INSERT INTO threads VALUES (NULL," . $title . "," . $message . "," . $author . ", 0," . $time . ")"); echo "Thread Posted.<br><a href='index.php'>Return</a>"; endif; ?> Thanks, it removed the error code. Im just writing this to test so i will post again with problems with this when testing On a seperate to read messages im getting error Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\mywebsite\msg.php on line 8 sql = mysql_query("SELECT * FROM threads WHERE id = '$_GET[id]' Edited June 27, 201115 yr by louis moore
June 27, 201115 yr Author You forgot the quotes AGAIN. sql = mysql_query("SELECT * FROM threads WHERE id = " . $_GET['id'] . ")"); Yes i remembered this after but its still displaying the same error?
June 27, 201115 yr Author When you dump the code here, mark the number of the error line in the code at least like this: /* line 203 */ erroneous code line here <?php // Connecting to the database again mysql_connect("localhost", "root", ""); mysql_select_db("test"); // Here's a link that will allow you to go back to the index echo "<a href='Untitled9.php'>Go Back...</a>"; // This query selects the current thread using the $_GET value. /* line 8 */ sql = mysql_query("SELECT * FROM threads WHERE id = " . $_GET['id'] . ")"); Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Here is the thread title. echo "<h2>$r[title]</h2>"; // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r[posted]); // Now this shows the thread with a horizontal rule after it. echo "$r[message]<h4>Posted by $r[author] on $posted</h4><hr>"; // End of Array } echo "<h3>Replies...</h3>"; // Here we will get it to show the replies // This query selects the replies from the database where the thread ID matches the thread $_GET value. $sql = mysql_query("SELECT * FROM replies WHERE thread = '$_GET[id]'"); // Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r[posted]); // Now this shows the thread with a horizontal rule after it. echo "$r[message]<h4>Posted by $r[author] on $posted</h4><hr>"; // End of Array } ?> <form action="newreply.php" method="POST"> Your Name: <input type="text" name="author"> <input type="hidden" value="<?php echo $_GET[id]; ?>" name="thread"><br> Message:<br><textarea cols="60" rows="5" name="message"></textarea><br> <input type="submit" value="Post Reply"> </form>
June 27, 201115 yr You forgot the quotes AGAIN. You have to learn to write consistent code otherwise you always get confused and come back here every 2 minutes. sql = mysql_query("SELECT * FROM threads WHERE id = " . $_GET['id'] . ")"); Out of interest, why is it encouraged to concatenate the $(GET['id] with full stops outside of the quote marks rather than just doing sql = mysql_query("SELECT * FROM threads WHERE id = $_GET[id]"); ? Is the speed saving really worth the spaghetti of quotes and full stops that the concatenation gives you?
June 27, 201115 yr Author You see what I mean now? Learn to read the obvious, you missed the dollar sign here: $sql = mysql_query("SELECT * FROM threads WHERE id = " . $_GET['id'] . ")"); Thanks. Im following a tutorials (http://www.dalehay.com/comment/497/) and i follwed wrong/copied it wrong. Ive got 97% working now ive just got this final error (i believed) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\mywebsite\msg.php on line 11 <?php // Connecting to the database again mysql_connect("localhost", "root", ""); mysql_select_db("test"); // Here's a link that will allow you to go back to the index echo "<a href='Untitled9.php'>Go Back...</a>"; // This query selects the current thread using the $_GET value. $sql = mysql_query("SELECT * FROM threads WHERE id = " . $_GET['id'] . ")"); //Now we are getting our results and making them an array /* line 11 */while($r = mysql_fetch_array($sql)) { // Here is the thread title. echo "<h2>$r[title]</h2>"; // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r[posted]); // Now this shows the thread with a horizontal rule after it. echo "$r[message]<h4>Posted by $r[author] on $posted</h4><hr>"; // End of Array } echo "<h3>Replies...</h3>"; // Here we will get it to show the replies // This query selects the replies from the database where the thread ID matches the thread $_GET value. $sql = mysql_query("SELECT * FROM replies WHERE thread = '$_GET[id]'"); // Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r[posted]); // Now this shows the thread with a horizontal rule after it. echo "$r[message]<h4>Posted by $r[author] on $posted</h4><hr>"; // End of Array } ?> <form action="newreply.php" method="POST"> Your Name: <input type="text" name="author"> <input type="hidden" value="<?php echo $_GET[id]; ?>" name="thread"><br> Message:<br><textarea cols="60" rows="5" name="message"></textarea><br> <input type="submit" value="Post Reply"> </form>
June 27, 201115 yr That's just a habit, you can see the code coloring in IDE and that helps to avoid certain mistakes and typos, wouldn't you agree? That's a good point. I guess it's kind of six of one, half dozen of the other. Jumbled up mass of quotes, full stops etc. but with code colouring vs. much easier to read code with no code colouring. Actually - funnily enough, just checked, my IDE (Netbeans) does colour the code even when not concatenated. So - it's not actually "required" to concatenate, it's just down to personal preference, yes? Edited June 27, 201115 yr by Gibson
June 27, 201115 yr Author Are you checking that $_GET['id] is actually set? Yes the 'id' is set in the database! Also when clicking the page it shows that id withing the page ulr But is just displaying Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\mywebsite\msg.php on line 11 which means it wont show the post
June 27, 201115 yr Yes the 'id' is set in the database! Also when clicking the page it shows that id withing the page ulr But is just displaying Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\mywebsite\msg.php on line 11 which means it wont show the post Echo your query. See what it says. Of course it's a preference, like I said, I'm just trying to be consistent. SQL queries more often than not become long anyway, you gotta split 'em in lines, and that's when concatenating, hence code coloring helps a lot. Ah I'm with ya.
June 27, 201115 yr Author Echo your query. See what it says. Ah I'm with ya. How do i do this? :/ sorry
June 27, 201115 yr How do i do this? :/ sorry Do something like $query = "SELECT * FROM threads WHERE id = " . $_GET['id'] . ""; echo "The query is - " . $query; The echo statement will print exactly what your query statement is. From there you can read the query statement and work out what's wrong (hopefully). Obviously this now misses out the part where you're actually executing the query. It's useful to do it this way so you can echo queries easily for debugging purposes. If then you want to put back the bit that executes the query, do $sql = mysql_query($query); Edited June 27, 201115 yr by Gibson
June 27, 201115 yr I'll give you a hint: mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query. Your query fails, kid. He just needs to do some gentle error checking which will help locate the problem such as mysql_query("SELECT * FROM threads WHERE id = " . $_GET['id'] . ")") or die(mysql_error()); using or die(mysql_error()) at the end of each query will help u locate problems in the codes i think you people are making it more complicated then it reall is, to locate query errors Edited June 27, 201115 yr by webdesigner93
June 27, 201115 yr Author He just needs to do some gentle error checking which will help locate the problem such as mysql_query("SELECT * FROM threads WHERE id = " . $_GET['id'] . ")") or die(mysql_error()); using or die(mysql_error()) at the end of each query will help u locate problems in the codes i think you people are making it more complicated then it reall is, to locate query errors It returns... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
June 27, 201115 yr It returns... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 remove the ) should be mysql_query("SELECT * FROM threads WHERE id = " . $_GET['id'] . "") or die(mysql_error());
June 27, 201115 yr 93 got there before me again. @Gibson u actually removed the wrong closing brace should have been the inner one inside the quotes the outer one was closing mysql_query(); without it, it would of looked like mysql_query(
June 27, 201115 yr Author All sorted! I thankyou for all your time given I know how frustrating it must be when people dont properly uderstand but i am very new to this and am learning as i go Thanks
June 27, 201115 yr All sorted! I thankyou for all your time given I know how frustrating it must be when people dont properly uderstand but i am very new to this and am learning as i go Thanks Np, may i ask what tutorial ur following?
June 27, 201115 yr Author Np, may i ask what tutorial ur following? http://www.dalehay.com/comment/497/
June 27, 201115 yr @Gibson u actually removed the wrong closing brace should have been the inner one inside the quotes the outer one was closing mysql_query(); without it, it would of looked like mysql_query( Yeah realised that after I looked at it afterwards and was editing it and then saw your post with exactly what I was shooting for. This thread moves too fast!
June 27, 201115 yr http://www.dalehay.com/comment/497/ Uh yea, that guy does not need to be teaching, he has no security in place at all, that forum could be hacked by even a person who did not know much about hacking, i personally would find better resources then that
June 27, 201115 yr Author Uh yea, that guy does not need to be teaching, he has no security in place at all, that forum could be hacked by even a person who did not know much about hacking, i personally would find better resources then that Okay thanks, il remember in future. Just another quick question... is there a way that i can make it that only logged in members can post etc eg when pushing submit button, if not logged in dusplay 'please login in' in a alert box and the 'name' box is filled automatically by the users username from the session. I do have a session already created which is $_SESSION and the username is 'myusername' I hope this makes sense as im not quite sure how to explain this! Sorry! Edited June 27, 201115 yr by louis moore
June 27, 201115 yr Okay thanks, il remember in future. Just another quick question... is there a way that i can make it that only logged in members can post etc eg when pushing submit button, if not logged in dusplay 'please login in' in a alert box and the 'name' box is filled automatically by the users username from the session. I do have a session already created which is $_SESSION and the username is 'myusername' I hope this makes sense as im not quite sure how to explain this! Sorry! some simple session checking would be <?php session_start(); if(!isset($_SESSION['UserId'])){ print 'You currently are not logged in there for you may not post'; exit; } this would go at the top of any page u wanna protect
June 27, 201115 yr Author some simple session checking would be <?php session_start(); if(!isset($_SESSION['UserId'])){ print 'You currently are not logged in there for you may not post'; exit; } this would go at the top of any page u wanna protect could i add this to what i currently have? <?php session_start(); if (isset($_SESSION['myusername'])) { session_destroy(); } ?>
June 28, 201115 yr Author Also when commeting of a post i first get Reply Posted. C:\xampp\htdocs\mywebsite\msg.php on line 41 12'>Return And when i click the link it displays Go Back...You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Notice: Use of undefined constant id - assumed' at line 1 Can you help i dont understand what it is... <?php // Connecting to the database again mysql_connect("localhost", "root", ""); mysql_select_db("test"); // Here's a link that will allow you to go back to the index echo "<a href='Untitled9.php'>Go Back...</a>"; // This query selects the current thread using the $_GET value. $sql = mysql_query("SELECT * FROM threads WHERE id = " . $_GET['id'] . "") or die(mysql_error()); //Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Here is the thread title. echo "<h2>$r[title]</h2>"; // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r['posted']); // Now this shows the thread with a horizontal rule after it. echo "$r[message]<h4>Posted by $r[author] on $posted</h4><hr>"; // End of Array } echo "<h3>Replies...</h3>"; // Here we will get it to show the replies // This query selects the replies from the database where the thread ID matches the thread $_GET value. $sql = mysql_query("SELECT * FROM replies WHERE thread = '$_GET[id]'"); // Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r[posted]); // Now this shows the thread with a horizontal rule after it. echo "$r[message]<h4>Posted by $r[author] on $posted</h4><hr>"; // End of Array } ?> <form action="newreply.php" method="POST"> Your Name: <input type="text" name="author"> /* Line 41*/<input type="hidden" value="<?php echo $_GET[id]; ?>" name="thread"><br> Message:<br><textarea cols="60" rows="5" name="message"></textarea><br> <input type="submit" value="Post Reply"> </form>
June 28, 201115 yr Ok u know how i mentioned before using this $r['posted']; like this $r[posted] its gonna assume posted as a constant if it does not have single quotes around it and from what im guessing your using ID like this $_GET[id]; when it needs to be like this $_GET['id']; just get in the habbit of using the single quotes Edited June 28, 201115 yr by webdesigner93
June 29, 201115 yr Author Ok u know how i mentioned before using this $r['posted']; like this $r[posted] its gonna assume posted as a constant if it does not have single quotes around it and from what im guessing your using ID like this $_GET[id]; when it needs to be like this $_GET['id']; just get in the habbit of using the single quotes I have done this but its still displaying Reply Posted.C:\xampp\htdocs\mywebsite\msg.php on line 41 13'>Return && Go Back...You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Notice: Use of undefined constant id - assumed' at line 1 It says posted when its not. Ive checked on the webpage and in the database :/
June 29, 201115 yr I have done this but its still displaying && It says posted when its not. Ive checked on the webpage and in the database :/ did u pust single quotes around this one? <?php echo $_GET[id]; ?> needs to be <?php echo $_GET['id']; ?>
June 29, 201115 yr Author did u pust single quotes around this one? <?php echo $_GET[id]; ?> needs to be <?php echo $_GET['id']; ?> yes its exactly like this...
June 29, 201115 yr yes its exactly like this... replace all your code with this <?php // Connecting to the database again mysql_connect("localhost", "root", ""); mysql_select_db("test"); // Here's a link that will allow you to go back to the index echo "<a href='Untitled9.php'>Go Back...</a>"; // This query selects the current thread using the $_GET value. $sql = mysql_query("SELECT * FROM threads WHERE id = '" . $_GET['id'] . "'") or die(mysql_error()); //Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Here is the thread title. echo "<h2>".$r['title']."</h2>"; // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r['posted']); // Now this shows the thread with a horizontal rule after it. echo "".$r['message']."<h4>Posted by ".$r['author']." on $posted</h4><hr>"; // End of Array } echo "<h3>Replies...</h3>"; // Here we will get it to show the replies // This query selects the replies from the database where the thread ID matches the thread $_GET value. $sql = mysql_query("SELECT * FROM replies WHERE thread = '".$_GET['id']."'"); // Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r['posted']); // Now this shows the thread with a horizontal rule after it. echo "".$r['message']."<h4>Posted by ".$r['author']." on $posted</h4><hr>"; // End of Array } ?> <form action="newreply.php" method="POST"> Your Name: <input type="text" name="author"> /* Line 41*/<input type="hidden" value="<?php echo $_GET['id']; ?>" name="thread"><br> Message:<br><textarea cols="60" rows="5" name="message"></textarea><br> <input type="submit" value="Post Reply"> </form>
June 29, 201115 yr Author replace all your code with this <?php // Connecting to the database again mysql_connect("localhost", "root", ""); mysql_select_db("test"); // Here's a link that will allow you to go back to the index echo "<a href='Untitled9.php'>Go Back...</a>"; // This query selects the current thread using the $_GET value. $sql = mysql_query("SELECT * FROM threads WHERE id = '" . $_GET['id'] . "'") or die(mysql_error()); //Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Here is the thread title. echo "<h2>".$r['title']."</h2>"; // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r['posted']); // Now this shows the thread with a horizontal rule after it. echo "".$r['message']."<h4>Posted by ".$r['author']." on $posted</h4><hr>"; // End of Array } echo "<h3>Replies...</h3>"; // Here we will get it to show the replies // This query selects the replies from the database where the thread ID matches the thread $_GET value. $sql = mysql_query("SELECT * FROM replies WHERE thread = '".$_GET['id']."'"); // Now we are getting our results and making them an array while($r = mysql_fetch_array($sql)) { // Everything within the two curly brackets can read from the database using $r[] // We need to convert the UNIX Timestamp entered into the database for when a thread... // ... is posted into a readable date, using date(). $posted = date("jS M Y h:i",$r['posted']); // Now this shows the thread with a horizontal rule after it. echo "".$r['message']."<h4>Posted by ".$r['author']." on $posted</h4><hr>"; // End of Array } ?> <form action="newreply.php" method="POST"> Your Name: <input type="text" name="author"> /* Line 41*/<input type="hidden" value="<?php echo $_GET['id']; ?>" name="thread"><br> Message:<br><textarea cols="60" rows="5" name="message"></textarea><br> <input type="submit" value="Post Reply"> </form> It works thanks! Can i ask... what did you change? Edited June 29, 201115 yr by louis moore
June 29, 201115 yr It works thanks! Can i ask... what did you change? every thing that looked like this $r[posted];, you always should use single quotes like this $r['posted'] to avoid problems
Create an account or sign in to comment