sineadyd Posted April 26, 2008 Share Posted April 26, 2008 Hi all, Have some code here for a forum board and was hoping anybody could take a look at my code to see if its all ok. When I test it in my browser, it just tries to open the do_addtopic.php file.Any suggestions would be very welcome. cheers! this is addtopic.html <html> <!--head--> <head> <title>Add a Topic</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="style.css" rel="stylesheet" type="text/css"> </head> <!--body--> <body> <table width="660" align="center"> <tr> <td height="45" class="heading"> <div> <p class="header">BioBot discussion board </p> </div> </td> </tr> </table> <!--add topic form--> <div align="center"> <form method="post" form action="do_addtopic.php" name="addtopic"> <tr> <td valign="top" height="165"> <table width="655" height="324" border="2" cellpadding="2" cellspacing="0" bgcolor="00CCCC" align="center"> <tr> <tr> <th width="330" height="50" align="center"><p class="header">Welcome to the BioBot discussion board.<br /> If you don't understand any of the course material,want to ask a biology question<br /> or simply just leave a comment, <br />your in the right spot!<br />Post your messages below!! </th> <tr><br/> <td height="230"><p class="form" align="center"> <p align="center" p class="form">Your E-Mail Address:<br/> <input type="text" name="topic_owner" size="40" maxlength="150"/></p> <p align="center" p class="form">Topic Title:<br/> <input type="text" name="topic_title" size="40" maxlength="150"/></p> <p align="center" p class="form">Post Text:<br/> <textarea name="post_text" rows="8" cols="40" wrap="virtual"></textarea> </p> <p align="center" p class="form"><input type="reset" name="reset" value="Reset"> <input type="submit" name="submit" value="Add Topic"> </p> </table> </form></div> <td colspan="2" align="center"><a href="../homestart.htm" class="homepage">Back to homepage</a> </td> </body> </html> This is do_addtopic.php <?php //check for required fields from the form if ((!$_POST["topic_owner"]) || (!$_POST["topic_title"]) || (!$_POST["post_text"])) { header("Location:..Forum Board/addtopic.html"); exit; } //Users Database settings $host="localhost"; $username="root"; $password=""; $db_name="forumboards"; //connect to server $mysqli = @mysqli_connect("localhost", "root", "", "forumboards")or die("connection was not successful"); // $link= @mysql_connect("$host","$username","$password") or die("connection was unsuccessful"); // @mysql_select_db($db_name,$link)or die("Database connection was unsuccessful"); //create and issue the first query $add_post_sql = "INSERT INTO forum_posts (topic_id,post_text,post_create_time,post_owner) VALUES ('".$topic_id."', '".$_POST["post_text"]."', now(), '".$_POST["topic_owner"]."')"; $add_post_res = mysqli_query($mysqli, $add_post_sql) or die(mysqli_error($mysqli)); //create and issue the second query $add_topic_sql = "INSERT INTO forum_topics (topic_title, topic_create_time,topic_owner) VALUES ('".$_POST["topic_title"]."',now(), '".$_POST["topic_owner"]."')"; $add_topic_res = mysqli_query($mysqli, $add_topic_sql) or die(mysqli_error($mysqli)); //get the id of the last query $topic_id = mysqli_insert_id($mysqli); //close connection to MySQL mysqli_close($mysqli); //create message for user $display_block = "<P>Your <strong>".$_POST["topic_title"]."</strong> message has been added.</p>"; ?> <html> <head> <title>add a topic</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <table width="660" align="center"> <tr> <td height="45" class="heading"> <div> <p class="header">BioBot discussion board </p> </div> </td> </tr> </table> <br /> <table width="655" table height="45" border="2" align="center" bgcolor="00CCCC"> <tr> <th scope="col"><div><h3>Thank You,<br /> your post has been added!!</h3> </div></th> </tr> </table> <td colspan="2"align="center"><a href="../homestart.htm" class="homepage">Back to homepage</a> </td> <?php echo $display_block; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/103078-solved-connecting-a-forum-board-to-a-database/ Share on other sites More sharing options...
sKunKbad Posted April 26, 2008 Share Posted April 26, 2008 You should test your raw sql query against your database using either the command line or phpMyAdmin. If the query is structured correctly, then I don't see a problem. Turn ON error reporting to see any details. Also, you have no validation of incoming vars and are setting yourself up to get hacked unless you validate. Quote Link to comment https://forums.phpfreaks.com/topic/103078-solved-connecting-a-forum-board-to-a-database/#findComment-527999 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.