Hi,

I got a question here.

I know the code to refresh the page is

echo "<meta http-equiv=\"refresh\" content=\"0;URL=user_dlist.php\">";

But how should i go about changing this code:

echo "<a href='view_topic.php?id=".$id."'>View your answer</a>";

Please assist! And thanks a lot!

bear

Try this:

<html>
<head>
  <script language="javascript">
  function refreshpage()
   {
      window.location.reload();
   }
  </script>
</head>
<body>
  <form action="" method="" name="" onsubmit="refreshpage();">
   <input name="submit" type="submit" value="submit">
  </form>
</body>
</html>

or

<input type="submit" value="Change Image" onclick="history.go(0)" />

"history.go(0)" takes you to the current page in IE's history, in other words, it refreshes the page.

Check this for using javascript :
http://www.grizzlyweb.com/webmaster/javascripts/refresh.asp

Hi,
But how should i go about changing this code:

echo "<a href='view_topic.php?id=".$id."'>View your answer</a>";

see this:

<A HREF="javascript:history.go(0)">Click to refresh the page</A>

Cant. It appear some error msg.
My whole code look like this

<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="root"; // Mysql password 
$db_name="advert"; // Database name 
$tbl_name="forum_answer"; // 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");

// Get value of id that sent from hidden field 
$id=$_POST['id'];

// Find highest answer number. 
$sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);

// add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 
if ($rows) {
$Max_id = $rows['Maxa_id']+1;
}
else {
$Max_id = 1;
}

// get values that sent from form 
$a_name=$_POST['a_name'];
$a_email=$_POST['a_email'];
$a_answer=$_POST['a_answer']; 

$datetime=date("d/m/y H:i:s"); // create date and time 

// Insert answer 
$sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')";
$result2=mysql_query($sql2);

if($result2){
echo "Successful<BR>";
echo "<a href='view_topic.php?id=".$id."'>View your answer</a>";

// If added new answer, add value +1 in reply column 
$tbl_name2="forum_question";
$sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'";
$result3=mysql_query($sql3);

}
else {
echo "ERROR";
}

mysql_close();
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.