twilitegxa Posted February 7, 2010 Author Share Posted February 7, 2010 How do I echo the sql statement? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted February 7, 2010 Share Posted February 7, 2010 look above   Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted February 7, 2010 Author Share Posted February 7, 2010 That suggestion also echos the correct comment_id, but the one i had previously did, too. It prints the correct comment id, it just won't INSERT the correct comment id. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted February 7, 2010 Share Posted February 7, 2010 Â Â lets do some error outputting then <?php if (!isset($_GET['id'])) { Â Â // id is not set, do something } elseif (!ctype_digit($_GET['id'])) { Â Â // the id is not a valid number, do something } else { Â Â $id = (int) $_GET['id']; }?> Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted February 7, 2010 Author Share Posted February 7, 2010 Finally got it figured out:  <?php $comment_id = $_GET['comment_id']; //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']); $comment_id = $_GET['comment_id']; $error='';//initialize $error to blank  if(trim($name)=='' ){    $error.="Please enter your name!<br />"; //concatenate the $error Message with a line break  }  if(trim($email)==''){   $error.="Plese enter your e-mail address!<br />";    } elseif (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) {     $error.="The e-mail you entered was not valid!<br />";       }   if(trim($reply)=='' ){    $error.="Please enter your reply!<br />"; //concatenate the $error Message with a line break  }  if($error==''){ $sql="INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ( '$comment_id', '$reply', now(), '$name','$email')";  mysql_query($sql,$conn) or die(mysql_error()); header('Location: testimonials.php');  // 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= ''; } ?> <form name="comment" id="comment" onsubmit="return validateFormOnSubmit(this)" action="reply.php?comment_id=<?php echo $comment_id; ?>" 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>  Thanks for the help with this Hussam! Quote Link to comment Share on other sites More sharing options...
Hussam Posted February 7, 2010 Share Posted February 7, 2010 okay guys, the problem is solved and everything was tested and its all working fine on the server.  I had to change the names of the fields a little bit, I like to follow the conventions. reply_id in the replies table was changed to id comment_id in the user_comments table was changed to id  both of them are auto increment and primary key's  Now the problem was: the condition on top if (isset($_POST['submit'])) this condition makes the page instantiate the values AFTER the submission not before. after the submission there is no GET values. so I added the GET value to the action attribute of the form therefore I have the GET values anyway, if the form is submitted or not. and that won't be a problem after the submission because there is redirection anyway.  the code should be like this:  <?php $comment_id = $_GET['comment_id']; // //echo $comment_id; // //exit(); //connect to server and select database $conn = mysql_connect("localhost", "webdes17_twilite", "minimoon")   or die(mysql_error()); $db = mysql_select_db("webdes17_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']); $comment_id = $_GET['comment_id']; $error='';//initialize $error to blank  if(trim($name)=='' ){    $error.="Please enter your name!<br />"; //concatenate the $error Message with a line break  }  if(trim($email)==''){   $error.="Plese enter your e-mail address!<br />";    } elseif (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) {     $error.="The e-mail you entered was not valid!<br />";       }   if(trim($reply)=='' ){    $error.="Please enter your reply!<br />"; //concatenate the $error Message with a line break  }  if($error==''){ $sql="INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ( '$comment_id', '$reply', now(), '$name','$email')";  mysql_query($sql,$conn) or die(mysql_error()); header('Location: testimonials.php');  // 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= ''; } ?> <form name="comment" id="comment" onsubmit="return validateFormOnSubmit(this)" action="reply.php?comment_id=<?php echo $comment_id; ?>" 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>  not very clean but tested and working!  good luck!   Quote Link to comment Share on other sites More sharing options...
Hussam Posted February 7, 2010 Share Posted February 7, 2010 your welcome twilitegxa, any time  cheers! Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted February 7, 2010 Author Share Posted February 7, 2010 And thank you for explaining it, too, so everyone else can understand what I was doing wrong! You are awesome! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.