Php data not show in output table

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 row
while($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();
?>

Please be aware that the mysql_* extension is now deprecated as of the current version of PHP and will very likely be removed from the next 5.x version and will likely not be in PHP 6.x (when it eventually is released). You should migrate over to either the mysqli_* extension or to PDO. PDO is a better choice as it doesn’t tie you down so much to a particular database server software.

Once you have migrated you should use Prepared Statements to prevent SQL Injection attacks. Have a read of this article from the PHP manual, it shows how to use prepared statements with PDO and also explains the principle.

i know but at this time i only need to correct this one…please help me

You have short tags in your display table.

<? echo $rows['id']; ?>

Use full tags.

<?php echo $rows['id']; ?>

thanks solved :slight_smile:

i created a jike table in my database but my my UPDATE query isnt working what could be the problem it keeps showing syntax error unexpected $affectedrows
<?php
try
{ $pdo = new PDO(‘mysql:host=localhost;dbname=ijdb’, ‘root’, ‘googliness’);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec(‘SET NAMES “utf8”’);
$sql = ‘ÚPDATE joke SET jokedate=“2014-05-01” WHERE joketext LIKE “%chicken%”’
$affectedRows = $pdo->exec($sql);
$ouput = “updated $affectedRows rows.”;
include ‘output.html.php’;

}
catch (PDOException $e)
{
$output = 'Error performing update: ’ . $e->getMessage();
include ‘output.html.php’;
exit();
}
$output= “updated $affectedRows rows.”;
include ‘output.html.php’;

See if this version works for you.

<?php
try
{
	$pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'root', 'googliness');
	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$pdo->exec('SET NAMES "utf8"');
	
	$jokedate = "2014-05-01";
	$joketext = "%chicken%";
	
	$sql = "ÚPDATE joke SET jokedate = :jokedate WHERE joketext LIKE :joketext";
	$query = $pdo->prepare($sql);
	$query->bindParam(":jokedate", $jokedate);
	$query->bindParam(":joketext", $joketext);
	$query->execute(); 			
	$affectedRows = $query->rowCount();	
	$ouput = "updated $affectedRows rows.";
	include 'output.html.php';

}
	catch (PDOException $e)
{
	$output = 'Error performing update: ' . $e->getMessage();
	include 'output.html.php';
	exit();
}
	$output= "updated $affectedRows rows.";
	include 'output.html.php';
?>