tanvirzafar Posted June 13, 2014 Share Posted June 13, 2014 i am making a simple php discussion forum.But when i intert data into database using form input the output data is not shown in output table.i verified that data is enter into database tables sucessfully.on output page the rows increas as data enter but data is not show on that rows...here is the output page code $host="localhost"; // Host name$username=""; // Mysql username$password=""; // Mysql password$db_name="itinsight"; // Database name$tbl_name="forum_question"; // Table name// Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");$sql="SELECT * FROM $tbl_name ORDER BY id DESC";// OREDER BY id DESC is order result by descending$result=mysql_query($sql);?><table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"><tr><td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td><td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td><td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td><td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td><td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td></tr><?php // Start looping table rowwhile($rows=mysql_fetch_array($result)){?><tr><td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td><td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td><td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td><td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td><td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td></tr><?php// Exit looping and close connection}mysql_close();?><tr><td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td></tr> here is the code of add new discussion <?php$host="localhost"; // Host name$username=""; // Mysql username$password=""; // Mysql password$db_name="itinsight"; // Database name$tbl_name="forum_question"; // Table name// Connect to server and select database.mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");// get data that sent from form$topic=$_POST['topic'];$detail=$_POST['detail'];$name=$_POST['name'];$email=$_POST['email'];$datetime=date("d/m/y h:i:s"); //create date time$sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')";$result=mysql_query($sql);if($result){echo "Successful<BR>";echo "<a href=forum.html>View your topic</a>";}else {echo "ERROR";}mysql_close();?> Link to comment Share on other sites More sharing options...
Don Jajo Posted June 13, 2014 Share Posted June 13, 2014 Hi, Firstly I recommend you move over to MySQLi because MySQL is depreciated in PHP - http://www.w3schools.com/php/php_ref_mysqli.asp , then about your issue. I found no error so far in your code, now I also suggest you do this to check if the error is from MySQL $result=mysql_query($sql) or die(mysql_error()); Link to comment Share on other sites More sharing options...
dsonesuk Posted June 13, 2014 Share Posted June 13, 2014 Is short open tags allowed? '<?php' compared to short open tag of '<?'. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now