Jump to content

Reply To Post ID Question


twilitegxa

Recommended Posts

I have the following page:

 

<?php

session_start();

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
    or die(mysql_error());
$db = mysql_select_db("testimonials", $conn) or die(mysql_error());

if (isset($_POST['submit'])) {

//create and issue the first query
$name=mysql_real_escape_string($_POST['comment_owner']);
$email=mysql_real_escape_string($_POST['comment_owner_email']); 
$reply=mysql_real_escape_string($_POST['reply']);
$reply_comment_id = $_GET['comment_id'];

$error='';//initialize $error to blank
  if(trim($_POST['comment_owner'])=='' ){
      $error.="Please enter your name!<br />"; //concatenate the $error Message with a line break
  }
   if(trim($_POST['comment_owner_email'])==''){
    $error.="Plese enter your e-mail address!<br />";
  }
      else {
        if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['comment_owner_email'])) {
        $error.="The e-mail you entered was not valid!<br />";
        
        }
    }
    if(trim($_POST['reply'])=='' ){
      $error.="Please enter your reply!<br />"; //concatenate the $error Message with a line break
  }
  if($error==''){
  header('Location: testimonials.php');
  
  $sql="INSERT INTO replies (reply_id, comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ('', '$reply_comment_id', '$reply', now(), '$name','$email')"; 
  
   mysql_query($sql,$conn) or die(mysql_error());
  }
    else{
       echo "<div class=error><span style=color:red>$error</span><br /></div>";
    }    
} else {

$name= '';
$email= '';
$reply= '';
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web Designs By Liz - Testimonials</title>

<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>

<script type="text/javascript">
//<![CDATA[
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
//-->
//]]>
</script>
<script type="text/javascript" language="JavaScript">
//<![CDATA[
<!--
function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function ReverseDisplay(d) {
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}
//-->
//]]>
</script>

<!-- Validation Script -->
<script type="text/javascript">
function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateUsername(theForm.comment_owner);
  reason += validateEmail(theForm.comment_owner_email);
  reason += validateEmpty(theForm.reply);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores

    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Please enter your name.\n";
    } 
    return error;
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Please enter your e-mail address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid e-mail address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "Your e-mail address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateEmpty(fld) {
    var error = "";

    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "Please enter your reply.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
</script>
<!--End Validation Script -->
</head>
<body onload="MM_preloadImages('home_selected.png','home_hover.png','resume.png','resume_hover.png','resume_selected.png','contact_selected.png','contact_hover.png','portfolio_selected.png','portfolio_hover.png')">
<script language="JavaScript" type="text/javascript">
//<![CDATA[

function doClock() { 
window.setTimeout( "doClock()", 1000 ); 
today = new Date(); 
self.status = today.toString(); 
}

doClock()
//]]>
</script>
<div class="c1" id="logo"><img src="weblogo.png" title="Web Designs By Liz Logo" alt="Web Designs By Liz Logo" /></div>
<table align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="index.html" target="_top" onclick="MM_nbGroup('down','group1','home','home_selected.png',1)" onmouseover="MM_nbGroup('over','home','home_hover.png','home_selected.png',1)" onmouseout="MM_nbGroup('out')"><img src="home.png" alt="Home Page" name="home" border="0" id="home" /></a></td>
<td><a href="resume.html" target="_top" onclick="MM_nbGroup('down','group1','resume','resume_selected.png',1)" onmouseover="MM_nbGroup('over','resume','resume_hover.png','resume_selected.png',1)" onmouseout="MM_nbGroup('out')"><img src="resume.png" alt="Resume" name="resume" border="0" id="resume" /></a></td>
<td><a href="contact.html" target="_top" onclick="MM_nbGroup('down','group1','contact','contact_selected.png',1)" onmouseover="MM_nbGroup('over','contact','contact_hover.png','contact_selected.png',1)" onmouseout="MM_nbGroup('out')"><img src="contact.png" alt="Contact Page" name="contact" border="0" id="contact" /></a></td>
<td><a href="portfolio.php" target="_top" onclick="MM_nbGroup('down','group1','portfolio','portfolio_selected.png',1)" onmouseover="MM_nbGroup('over','portfolio','portfolio_hover.png','portfolio_selected.png',1)" onmouseout="MM_nbGroup('out')"><img name="portfolio" src="portfolio.png" border="0" alt="Portfolio" /></a></td>
<td><a href="testimonials.php" target="_top" onclick="MM_nbGroup('down','group1','testimonials','testimonials_selected.png',1)" onmouseover="MM_nbGroup('over','testimonials','testimonials_hover.png','testimonials_selected.png',1)" onmouseout="MM_nbGroup('out')"><img name="testimonials" src="testimonials_selected.png" border="0" alt="Testimonials" /></a></td>
</tr>
</table>
<div id="resume_title" class="body"><div class="c1"></div>
<table width="900" align="center">
<tr>
<td class="style2" align="center">
<h1>Give Your Testimonial</h1>
</td>
</tr>
<tr>
<td class="style2">
<table class="style2" align="center">
<tr>
<td>
<form name="comment" id="comment" onsubmit="return validateFormOnSubmit(this)" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" cellspacing="0" cellpadding="5" width="662" class="style2">
<tr>
<td align="left"><label for="name"> Name:</label></td>
<td>
<div class="c2"><input type="text" name="comment_owner" id="comment_owner" size="30" value="<?php echo $name; ?>"/></div></td>
</tr>
<tr>
<td align="left"><label for="email">E-mail:</label></td>
<td>
<div class="c2"><input type="text" name="comment_owner_email" id="comment_owner_email" size="30" value="<?php echo $email; ?>"/></div></td>
</tr>
<tr>
<td align="left">
<label for="reply">Reply:</label></td>
<td>
<textarea name="reply" id="reply" rows="5" cols="30" value="<?php echo $reply; ?>"></textarea></td>
</tr>
<tr>
<td colspan="4">
<div class="c1"><input name="submit" type="submit" value="Submit" /> <input type="reset" name="reset" id="reset" value="Reset" /></div></td>
<td width="2"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div id="footer" class="style2 c1"><br />
<em>Adobe Photoshop, Illustrator, InDesign, Dreamweaver, and Flash logos<br />
are trademarks of Adobe Systems Incorporated.<br />
<br />
Copyright © 2009 Liz Kula. All rights reserved.</em>
<div id="foot-nav">
<ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/resume.html" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</body>
</html>

 

I need to send the $reply_comment_id along with the form when it inserts, but it's not inserting. It looks like it is sending it in the address when you click the reply button on a post on the previous page:

 

http://webdesignsbyliz.com/reply.php?comment_id=57

 

As you can see above, it does send the ID, but it won't insert it. Can anyone help? What am I doing wrong?

Link to comment
Share on other sites

  • Replies 57
  • Created
  • Last Reply

I am not sure if I understood your question, but the comment_id should be set on "auto increment" in the database if you are inserting into comments table.

 

tell me how many tables you have?

 

I think its something similar to a blog, so you need to have two tabels:

posts and comments or replies whatever the name you choose.

Link to comment
Share on other sites

I see you have '' in your first inserted value in your SQL insert statement.

leave it blank (don't put nothing, not even quotes or comma) and insert only to the fields that are not auto increment, the comment_id should be set to auto increment in the database.

 

good luck!

Link to comment
Share on other sites

No, I have two tables. One is for comments and one is for replies. For the replies page, which is the one in question, I need to pull the comment_id from the previous page. I send the comment_id through the link that takes the user to the reply form. For the reply page, when it inserts I have the reply_id set to auto increment, but not the comment_id because it was set to auto increment for the comment table. I hope that made sense. Here are my two tables:

 

Comment:

CREATE TABLE IF NOT EXISTS `user_comments` (
  `comment_id` int(11) NOT NULL auto_increment,
  `comment` longtext,
  `comment_create_time` datetime default NULL,
  `comment_owner` varchar(150) default NULL,
  `comment_owner_email` varchar(150) default NULL,
  `url` longtext NOT NULL,
  PRIMARY KEY  (`comment_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=58 ;

 

Replies:

CREATE TABLE IF NOT EXISTS `replies` (
  `reply_id` int(11) NOT NULL auto_increment,
  `comment_id` int(11) NOT NULL,
  `reply` longtext,
  `reply_create_time` datetime default NULL,
  `reply_owner` varchar(150) NOT NULL,
  `reply_owner_email` varchar(255) NOT NULL,
  PRIMARY KEY  (`reply_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=28 ;

 

And here is my first page that sends the comment_id when going to the reply page:

 

<?php

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
mysql_select_db("testimonials", $conn) or die(mysql_error());

//gather the comments
$get_comments = "select comment_id, comment,
date_format(comment_create_time, '%b %e, %Y at %r') as fmt_comment_create_time,
comment_owner, comment_owner_email, url from user_comments order by comment_create_time desc";
$get_comments_res = mysql_query($get_comments, $conn) or die(mysql_error());
if (mysql_num_rows($get_comments_res) < 1) {
//there are no comments, so say so
$display_block = "<p><em>No comments currently exist. Please submit your testimonial!</em></p>";
} else {
//create the display string
$display_block = "
<table cellpadding=3 cellspacing=2 border=0 width=100%>
<tr>
<th>COMMENT</th>
<th># OF REPLIES</th>
</tr>";

while ($comment_info = mysql_fetch_array($get_comments_res)) {
	$comment_id = $comment_info['comment_id'];
	$comment = stripslashes($comment_info['comment']);
	$comment_create_time = $comment_info['fmt_comment_create_time'];
	$comment_owner = stripslashes($comment_info['comment_owner']);
	$comment_owner_email = stripslashes($comment_info['comment_owner_email']);
	$url = stripslashes($comment_info['url']);

//get number of replies
$get_num_posts = "select count(reply_id) from replies where comment_id = $comment_id";
	$get_num_posts_res = mysql_query($get_num_posts, $conn)
		or die(mysql_error());
	$num_posts = mysql_result($get_num_posts_res, 0, 'count(reply_id)');

                if ($num_posts == '0') {
	$num_posts = ' ';}

//add to display
	$display_block .= "
	<tr>
	<td><b>Comment By: $comment_owner</b><br>
	<em>Created on $comment_create_time</em><br>
	URL: <a href=\"$url\" target=\"_blank\">$url</a><br><br>
	$comment
	</td>
	<td align=center valign=top>$num_posts <a href=\"reply.php?comment_id=$comment_id\">Reply</a></td>
	</tr>
                <tr>
                <td colspan=2><hr></td>
                </tr>";


//gather the replies
$get_replies = "select reply_id, comment_id, reply,
date_format(reply_create_time, '%b %e, %Y at %r') as fmt_reply_create_time,
reply_owner, reply_owner_email from replies where comment_id = $comment_id order by reply_create_time desc";
$get_replies_res = mysql_query($get_replies, $conn) or die(mysql_error());

while ($reply_info = mysql_fetch_array($get_replies_res)) {
	$reply_id = $reply_info['reply_id'];
	$reply = stripslashes($reply_info['reply']);
	$reply_create_time = $reply_info['fmt_reply_create_time'];
	$reply_owner = stripslashes($reply_info['reply_owner']);
	$reply_owner_email = stripslashes($reply_info['reply_owner_email']);

//add to display
	$display_block .= "
	<tr>
	<td><div id=reply>Reply</div><div class=reply><b>Comment By: $reply_owner</b><br>
	<em>Created on $reply_create_time</em><br><br>
	$reply</div>
	</td>
	<td> </td>
	</tr>
                <tr>
                <td colspan=2><hr>
                </td>
                </tr>";
	}
                }

	//close up the table
	$display_block .= "</table>";
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web Designs By Liz - Testimonials</title>

<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>

<script type="text/javascript">
//<![CDATA[
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
//-->
//]]>
</script>
<script type="text/javascript" language="JavaScript">
//<![CDATA[
<!--
function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function ReverseDisplay(d) {
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}
//-->
//]]>
</script>
</head>
<body onload="MM_preloadImages('home_selected.png','home_hover.png','resume.png','resume_hover.png','resume_selected.png','contact_selected.png','contact_hover.png','portfolio_selected.png','portfolio_hover.png','testimonials.png','testimonials_hover.png','testimonials_selected.png')">
<script language="JavaScript" type="text/javascript">
//<![CDATA[

function doClock() { 
window.setTimeout( "doClock()", 1000 ); 
today = new Date(); 
self.status = today.toString(); 
}
doClock()
//]]>
</script>
<div class="c1" id="logo"><img src="weblogo.png" title="Web Designs By Liz Logo" alt="Web Designs By Liz Logo" /></div>
<table align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
  <td><a href="index.html" target="_top" onclick="MM_nbGroup('down','group1','home','home_selected.png',1)" onmouseover="MM_nbGroup('over','home','home_hover.png','home_selected.png',1)" onmouseout="MM_nbGroup('out')"><img src="home.png" alt="Home Page" name="home" border="0" id="home" /></a></td>
  <td><a href="resume.html" target="_top" onclick="MM_nbGroup('down','group1','resume','resume_selected.png',1)" onmouseover="MM_nbGroup('over','resume','resume_hover.png','resume_selected.png',1)" onmouseout="MM_nbGroup('out')"><img src="resume.png" alt="Resume" name="resume" border="0" id="resume" /></a></td>
  <td><a href="contact.html" target="_top" onclick="MM_nbGroup('down','group1','contact','contact_selected.png',1)" onmouseover="MM_nbGroup('over','contact','contact_hover.png','contact_selected.png',1)" onmouseout="MM_nbGroup('out')"><img src="contact.png" alt="Contact Page" name="contact" border="0" id="contact" /></a></td>
  <td><a href="portfolio.php" target="_top" onclick="MM_nbGroup('down','group1','portfolio','portfolio_selected.png',1)" onmouseover="MM_nbGroup('over','portfolio','portfolio_hover.png','portfolio_selected.png',1)" onmouseout="MM_nbGroup('out')"><img name="portfolio" src="portfolio.png" border="0" alt="Portfolio" /></a></td>
  <td><a href="testimonials.php" target="_top" onClick="MM_nbGroup('down','group1','testimonials','testimonials_selected.png',1)" onMouseOver="MM_nbGroup('over','testimonials','testimonials_hover.png','testimonials_selected.png',1)" onMouseOut="MM_nbGroup('out')"><img name="testimonials" src="testimonials_selected.png" border="0" alt="Testimonials" onLoad="MM_nbGroup('init','group1','testimonials','testimonials.png',1)" /></a></td>
</tr>
</table>
<div id="resume_title" class="body"><div class="c1"></div>
<table width="900" align="center">
<tr>
<td class="style2" align="center">
<h1>Testimonials</h1>
<p>Post your testimonial <a href="testimonials_form.php">here</a>.</p>
</td>
</tr>
<tr>
<td class="style2">
<?php print $display_block; ?>
</td>
</tr>
</table>
</div>
<div id="footer" class="style2 c1"><br />
<em>Adobe Photoshop, Illustrator, InDesign, Dreamweaver, and Flash logos<br />
are trademarks of Adobe Systems Incorporated.<br />
<br />
Copyright © 2009 Liz Kula. All rights reserved.</em>
<div id="foot-nav">
<ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/resume.html" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</body>
</html>

 

And here is the page that submits the reply form again:

 

<?php

session_start();

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
    or die(mysql_error());
$db = mysql_select_db("testimonials", $conn) or die(mysql_error());

if (isset($_POST['submit'])) {

//create and issue the first query
$name=mysql_real_escape_string($_POST['comment_owner']);
$email=mysql_real_escape_string($_POST['comment_owner_email']); 
$reply=mysql_real_escape_string($_POST['reply']);
$reply_comment_id = $_GET['comment_id'];

$error='';//initialize $error to blank
  if(trim($_POST['comment_owner'])=='' ){
      $error.="Please enter your name!<br />"; //concatenate the $error Message with a line break
  }
   if(trim($_POST['comment_owner_email'])==''){
    $error.="Plese enter your e-mail address!<br />";
  }
      else {
        if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['comment_owner_email'])) {
        $error.="The e-mail you entered was not valid!<br />";
        
        }
    }
    if(trim($_POST['reply'])=='' ){
      $error.="Please enter your reply!<br />"; //concatenate the $error Message with a line break
  }
  if($error==''){
  header('Location: testimonials.php');
  
  $sql="INSERT INTO replies (reply_id, comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ('', '$reply_comment_id', '$reply', now(), '$name','$email')"; 
  
   mysql_query($sql,$conn) or die(mysql_error());
  }
    else{
       echo "<div class=error><span style=color:red>$error</span><br /></div>";
    }    
} else {

$name= '';
$email= '';
$reply= '';
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web Designs By Liz - Testimonials</title>

<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>

<script type="text/javascript">
//<![CDATA[
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
//-->
//]]>
</script>
<script type="text/javascript" language="JavaScript">
//<![CDATA[
<!--
function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function ReverseDisplay(d) {
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}
//-->
//]]>
</script>

<!-- Validation Script -->
<script type="text/javascript">
function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateUsername(theForm.comment_owner);
  reason += validateEmail(theForm.comment_owner_email);
  reason += validateEmpty(theForm.reply);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores

    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Please enter your name.\n";
    } 
    return error;
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Please enter your e-mail address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid e-mail address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "Your e-mail address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateEmpty(fld) {
    var error = "";

    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "Please enter your reply.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
</script>
<!--End Validation Script -->
</head>
<body onload="MM_preloadImages('home_selected.png','home_hover.png','resume.png','resume_hover.png','resume_selected.png','contact_selected.png','contact_hover.png','portfolio_selected.png','portfolio_hover.png')">
<script language="JavaScript" type="text/javascript">
//<![CDATA[

function doClock() { 
window.setTimeout( "doClock()", 1000 ); 
today = new Date(); 
self.status = today.toString(); 
}

doClock()
//]]>
</script>
<div class="c1" id="logo"><img src="weblogo.png" title="Web Designs By Liz Logo" alt="Web Designs By Liz Logo" /></div>
<table align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="index.html" target="_top" onclick="MM_nbGroup('down','group1','home','home_selected.png',1)" onmouseover="MM_nbGroup('over','home','home_hover.png','home_selected.png',1)" onmouseout="MM_nbGroup('out')"><img src="home.png" alt="Home Page" name="home" border="0" id="home" /></a></td>
<td><a href="resume.html" target="_top" onclick="MM_nbGroup('down','group1','resume','resume_selected.png',1)" onmouseover="MM_nbGroup('over','resume','resume_hover.png','resume_selected.png',1)" onmouseout="MM_nbGroup('out')"><img src="resume.png" alt="Resume" name="resume" border="0" id="resume" /></a></td>
<td><a href="contact.html" target="_top" onclick="MM_nbGroup('down','group1','contact','contact_selected.png',1)" onmouseover="MM_nbGroup('over','contact','contact_hover.png','contact_selected.png',1)" onmouseout="MM_nbGroup('out')"><img src="contact.png" alt="Contact Page" name="contact" border="0" id="contact" /></a></td>
<td><a href="portfolio.php" target="_top" onclick="MM_nbGroup('down','group1','portfolio','portfolio_selected.png',1)" onmouseover="MM_nbGroup('over','portfolio','portfolio_hover.png','portfolio_selected.png',1)" onmouseout="MM_nbGroup('out')"><img name="portfolio" src="portfolio.png" border="0" alt="Portfolio" /></a></td>
<td><a href="testimonials.php" target="_top" onclick="MM_nbGroup('down','group1','testimonials','testimonials_selected.png',1)" onmouseover="MM_nbGroup('over','testimonials','testimonials_hover.png','testimonials_selected.png',1)" onmouseout="MM_nbGroup('out')"><img name="testimonials" src="testimonials_selected.png" border="0" alt="Testimonials" /></a></td>
</tr>
</table>
<div id="resume_title" class="body"><div class="c1"></div>
<table width="900" align="center">
<tr>
<td class="style2" align="center">
<h1>Give Your Testimonial</h1>
</td>
</tr>
<tr>
<td class="style2">
<table class="style2" align="center">
<tr>
<td>
<form name="comment" id="comment" onsubmit="return validateFormOnSubmit(this)" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" cellspacing="0" cellpadding="5" width="662" class="style2">
<tr>
<td align="left"><label for="name"> Name:</label></td>
<td>
<div class="c2"><input type="text" name="comment_owner" id="comment_owner" size="30" value="<?php echo $name; ?>"/></div></td>
</tr>
<tr>
<td align="left"><label for="email">E-mail:</label></td>
<td>
<div class="c2"><input type="text" name="comment_owner_email" id="comment_owner_email" size="30" value="<?php echo $email; ?>"/></div></td>
</tr>
<tr>
<td align="left">
<label for="reply">Reply:</label></td>
<td>
<textarea name="reply" id="reply" rows="5" cols="30" value="<?php echo $reply; ?>"></textarea></td>
</tr>
<tr>
<td colspan="4">
<div class="c1"><input name="submit" type="submit" value="Submit" /> <input type="reset" name="reset" id="reset" value="Reset" /></div></td>
<td width="2"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>

<?php echo $reply_comment_id; ?>
</div>
<div id="footer" class="style2 c1"><br />
<em>Adobe Photoshop, Illustrator, InDesign, Dreamweaver, and Flash logos<br />
are trademarks of Adobe Systems Incorporated.<br />
<br />
Copyright © 2009 Liz Kula. All rights reserved.</em>
<div id="foot-nav">
<ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/resume.html" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</body>
</html>

 

So when the viewer selects a post to reply to, it should send along with it the comment_id, and then when the reply is submitted, it should insert that comment_id with the rest of the reply information. Is it because I am using the PHP_SELF in the action value? Or did I do something else wrong?

Link to comment
Share on other sites

And here is the link if you want to test it:

 

http://webdesignsbyliz.com/testimonials.php

 

You can just post a new testimonial, then post a reply, or simply post a reply to an existing testimonial and when you click the reply button, you can see that the comment_id is sent along with the link through the address.

Link to comment
Share on other sites

okay twilitegxa, your question didn't make alot of sense to me lol, but I am willing to help you.

 

Yes I see that the comment_id is sent, but you have got to name your fields better then this, its a mess lol.

 

Anyway, here is what you need to do as the first step:

Replace your SQL query with this one and tell me what you got:

 

  $sql="INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ($reply_comment_id, '$reply', now(), '$name','$email')"; 

 

its pointless to have reply_id in your SQL insert statement because its set to auto increment.

 

I thought at first that the reply is the father and the comment is the child, that's why I wanted you to show me your tables.

 

good luck!

Link to comment
Share on other sites

Yes, the reply is being inserted into the table in the database, but it isn't showing up on the display page because it displays the replies based on what comment it was replied to. When the posted data inserts, it inserts a '0' into the comment_id field instead of the actual comment_id that is sent through the web address by clicking the link. Can anyone figure out what is wrong?

 

And I tried your example, Hussam, but nothing changed. :-(

Link to comment
Share on other sites

ok twilitegxa, lets deal with it piece by piece,

 

each comment can have many replies, so far, this is correct. right?

 

Now, we need two tables which you have already, and at least having these fields:

comments ===> id, body.

replies ===> id, comment_id, body.

 

if you have a different database structure, let me know.

 

the comment_id in the second table is actually the id in the first table to be able to pull only the replies that are related to that comment, so far everything should be fine.

 

Now, are you getting the Insert part correct or not?

if not, then lets deal with that first then we discuss the display page.

 

try to print out the query and see if it worked or inserted or not using this code then see in the database if what you wanted to be inserted, was inserted.

 

$sql="INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ($reply_comment_id, '$reply', now(), '$name','$email')"; 

echo $sql;
echo '<br />';
echo mysql_query($sql,$conn) ? 'yes' : 'no';

 

 

 

Link to comment
Share on other sites

That's what I was trying to tell you. The information IS inserting, everything except for the comment_id. Every time a record inserts, the comment_id field is inserting as a '0'.

 

And when I used your last example, it printed out this:

 

INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner,reply_owner_email) VALUES ('', 'test', now(), 'BriannaCarter','brianna@aol.com')

yes 

 

For some reason, comment_id is inserting as a blank value. And I think I gave you my actual table structure earlier, so I guess I don't need to post it again, right? And yes, each comment can have many replies.

Link to comment
Share on other sites

post this code now and try to reply to different comments and tell me what your getting:

$sql="INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ($_GET[comment_id], '$reply', now(), '$name','$email')"; 

echo $sql;
echo '<br />';
echo $_GET['comment_id'];

Link to comment
Share on other sites

I got this:

 

INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner,reply_owner_email) VALUES ('', 'test', now(), 'BriannaCarter','brianna@aol.com')

 

But I had to add single quotes around the $_GET[comment_id] or else it didn't work at all.

Link to comment
Share on other sites

okay, move this line to the top of the page, right after the session_start(),

 

$reply_comment_id = $_GET['comment_id'];

 

I just want to collect the variable anyway if the form is submitted or not.

 

then try these lines as they are (I am using the old one again):

$sql="INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ($reply_comment_id, '$reply', now(), '$name','$email')"; 

echo $sql;

echo '<br />';

echo $reply_comment_id ;

 

 

 

Link to comment
Share on other sites

This is what is printed:

 

INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner,reply_owner_email) VALUES ('', 'fkfkhfmb', now(), 'test','test@aol.com')

 

I again had to put single quotes around the $reply_comment_id.

Link to comment
Share on other sites

ok, the problem now that its not collecting the variable from the array $_GET.

 

Forget about the query and comment your code and put this line:

<?php
echo '<pre>';
print_r ($_GET);
echo '</pre>';
?>

 

 

Link to comment
Share on other sites

weird, the $_GET array is blank as I thought, I think the problem is that you are redirecting before sending the query:

 

try to do it this way, redirecting after sending the query:

 

if($error==''){
  
$sql="INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ( '$reply_comment_id', '$reply', now(), '$name','$email')"; 
  
mysql_query($sql,$conn) or die(mysql_error());

header('Location: testimonials.php');

 

 

Link to comment
Share on other sites

OMG, this is overwhelming.

 

I don't think that it has any thing to do with PHP_SELF, because it will return the same page file name, I told you to put that just in case you wanted to reuse the code in a different page or rename the page, so you dont have a problem.

 

try to take if off and see what happens.

Link to comment
Share on other sites

if your using $_GET['comment_id'] to pass the comment ID from one page to another is flawed try using $_SESSION['comment_id'] instead.

 

here is how i would do it:

 

<?php

if(isset($reply_comment_id)){
$reply_comment_id= $_SESSION['comment_id'];
}else{ echo "The comment ID is not set!";
}
if($error==''){
  
$sql="INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ( '$reply_comment_id', '$reply', now(), '$name','$email')"; 
  
mysql_query($sql,$conn) or die(mysql_error());

header('Location: testimonials.php');

?>

Link to comment
Share on other sites

sorry i missed a bracket  and forgot to start the session

 

<?php
session_start()
if(isset($reply_comment_id)){
$reply_comment_id= $_SESSION['comment_id'];
}else{ echo "The comment ID is not set!";
}
if($error==''){ 
  
$sql="INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ( '$reply_comment_id', '$reply', now(), '$name','$email')"; 
  
mysql_query($sql,$conn) or die(mysql_error());

header('Location: testimonials.php');
}

?>

Link to comment
Share on other sites

oh nevermind your passing it to the same page in that case i would use

 

$_REQUEST['comment_id']

 

well, the array $_GET is a part of the array $_REQUEST, if the index doesn't exist in $_GET then it certainly doesn't exist in $_REQUEST unless its in $_POST or $_COOKIE but its not in any of them.

 

I am not sure if you can use $_SESSION in this case because she needs a way to save a certain id in the session before leaving the first page, you need to modify the code in the other page to save the id in the session then you can do it.

Link to comment
Share on other sites

Archived

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


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.