Jump to content

getting the data to databases error


nielcleo

Recommended Posts

Hi there,i have my little problem sorry im new in php and im expanding my knowledge in to this.i have a simple add data to the database and get it to show the result. my problem is the data was stored in the database but when i will show the resultonly the table was added but the content is not posted/showed.please anyone help me again thank you very much

Link to comment
Share on other sites

here's the code for add.php

<?php$host="localhost";$username="testdb";$password="123"; $db_name="test"; $tbl_name="content";mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");$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=main_forum.php>View your topic</a>";}else {echo "ERROR";}mysql_close();?>

and this is the code to show the result result.php

<?php$host="localhost";$username="testdb";$password="123";$db_name="test";$tbl_name="content";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><?phpwhile($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}mysql_close();?><tr><td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td></tr></table>

Link to comment
Share on other sites

so is the problem that the data is being added (and that you can verify it with phpMyAdmin) but it just's not being displayed? Have you verified it with phpMyAdmin? Does your add script show the success message?

Link to comment
Share on other sites

so is the problem that the data is being added (and that you can verify it with phpMyAdmin) but it just's not being displayed? Have you verified it with phpMyAdmin? Does your add script show the success message?
yup it has and some input added to the phpmyadmin i verified that but the output is not showed. but the table is added every time i do a new input. my problem is the text is not displayed.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...