Roy766 Posted July 22, 2008 Share Posted July 22, 2008 Well, I decided to try and write a simple script to measure how bad I am at MySQL. Apparently, very bad. My idea is simple: You type text into a textbox, it redirects you to a different page, at which the data is sent to the database, and then all of the data is echoed on the main page. Problem is, it doesn't work, and I'm not experienced enough to determine why. All I get when I try to echo is "resource id #2". Here's my code: Main page (forum.php) <html> <head> <title>Forum thingy....</title> </head> <body> <?php mysql_connect("mysql4.freehostia.com", "*******", "******") or die(mysql_error()); mysql_select_db("aiddre_db") or die(mysql_error()); $result = mysql_query("SELECT * FROM royforum_list"); while($row = mysql_fetch_assoc($result)){ echo $result; } ?> <form name="submitcomment" method="post" action="submitcomment.php"> <input type="text" name="commentval"> <input type="submit" value="Submit"> </body> </html> Redirected page (submitcomment.php): <?php mysql_connect("mysql4.freehostia.com", "aiddre_db", "mioki766") or die(mysql_error()); mysql_select_db("aiddre_db") or die(mysql_error()); $commentvalue = $_POST['commentval']; $sql = "INSERT INTO royforum_list (comment) VALUES ('$commentvalue')"; $result = mysql_query($sql); echo "Comment posted. Please <a href='forum.php'>return to the forum-ish thing.</a>" ?> Any suggestions? Link to comment https://forums.phpfreaks.com/topic/115928-newbie-questionsimple-read-and-write/ Share on other sites More sharing options...
Xurion Posted July 22, 2008 Share Posted July 22, 2008 This part in your script take the result set it gets from the database, and places it into an array. Change the while part in your first script to the following: while($row = mysql_fetch_assoc($result)){ echo $row['column']; } Notice the $row['column'] part. The row is the current record in the loop (thanks to the while loop) and the bit in the [ ] brackets says what column from that record you want to reference. Link to comment https://forums.phpfreaks.com/topic/115928-newbie-questionsimple-read-and-write/#findComment-596330 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.