View Full Version : click here to go back

06-03-2011, 10:36 PM
hello my senior men, i would you to help me with this code. with dreamweaver, i made this query string which works fine on a page by name replies.php

$maxRows_posts = 20;
$pageNum_posts = 0;
if (isset($_GET['pageNum_posts'])) {
$pageNum_posts = $_GET['pageNum_posts'];
$startRow_posts = $pageNum_posts * $maxRows_posts;

$colname_posts = "-1";
if (isset($_GET['post_title'])) {
$colname_posts = $_GET['post_title'];
$colname_posts = "-1";
if (isset($_GET['post_title'])) {
$colname_posts = (get_magic_quotes_gpc()) ? $_GET['post_title'] : addslashes($_GET['post_title']);
mysql_select_db($database_urbanmayor, $urbanmayor);
$query_posts = sprintf("SELECT * FROM forum_posts WHERE post_id = %s", $colname_posts);
$posts = mysql_query($query_posts, $urbanmayor) or die(mysql_error());
$row_posts = mysql_fetch_assoc($posts);
$totalRows_posts = mysql_num_rows($posts);

i later added this code to another page (add_ans.php) to send data to a database and that works too but the link (click here to go back) which should you to the replies.php page does not display any thing when it is clicked. that is the line in asterisks. below is the code.

$host = 'localhost';
$username = 'root';
$password = '';
$db_name = 'urbansystems';
$tbl_name = 'forum_replies';
$tbl_name2 = 'forum_posts';

mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());

// Escape these to protect from SQL injection, for example intval() for integer values and mysql_real_escape_string() for strings, though you can have more elaborate protection
$sub_id = $_POST['sub_id'];
$posts_id = $_POST['posts_id'];
$rep_by = $_POST['rep_by'];
$details = $_POST['details'];
$rep_id = $_POST['rep_id'];
$rep_mail = $_POST['rep_mail'];

// There are SQL function for getting the date
$datetime = date("d/m/y");

$sql2 = "SELECT MAX(reply_id) AS Maxa_id FROM $tbl_name WHERE forum_post_id=$posts_id";
$result2 = mysql_query($sql2) or die(mysql_error());
$rows2 = mysql_fetch_array($result2) or die(mysql_error());

$Max_id = 1;
if(mysql_num_rows($result2) > 0) {
$Max_id += $rows2['Maxa_id'];
// You don't need apostrophes around integer values in SQL queries
$sql = "INSERT INTO $tbl_name (sub_cat_id, forum_post_id, reply_by, reply_details, rep_by_id, rep_by_mail, datetime) VALUES ('$sub_id', '$posts_id','$rep_by','$details', '$rep_id', '$rep_mail', '$datetime')";
$result = mysql_query($sql) or die(mysql_error());

if($result) {
echo '<h2>Successful posting</h2>';
* echo "<a href='replies.php?post_id=".$posts_id."'>Click here to go back</a>"; *

$sql3 = "UPDATE $tbl_name2 SET replies='$Max_id' WHERE post_id='$posts_id'";
mysql_query($sql3) or die(mysql_error());