Elven6 Posted January 9, 2010 Share Posted January 9, 2010 A script I am using has If statements in the comments form to basically tell the form what to do. Currently the form works by opening in a pop up for those who want to read/write comments. I'm changing it so that the form displays on the same page, essentially removing the need for a pop up. I have, if ($_GET['comment']) { echo "<SCRIPT LANGUAGE='JavaScript'> function smiles(which) { document.form1.text1.value = document.form1.text1.value + which; } </SCRIPT> <form name='form1' method='post' action='comments.php?load=comments&view=add'> <input type='hidden' name='aid' value='".$_GET['aid']."'> <input type='hidden' name='name' value='".$_COOKIE[$pre."username"]."'> <table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" align=\"center\"> <tr><td><b>Name</b></td><td>".$_COOKIE[$pre."username"]."</td></tr> As a snippet of some of the code. I want to know how I can make the If statement form appear on the page without removing, if ($_GET['comment']) { As it would break the script since 'comment' is needed for the form to proceed without errors. I've tried variations of echo on $_GET['comment'] but it didn't do anything. Hope that made sense, any ideas? Link to comment https://forums.phpfreaks.com/topic/187854-echoing-if-function/ Share on other sites More sharing options...
jl5501 Posted January 10, 2010 Share Posted January 10, 2010 Hi Your basic form of an if statement checking to see if the GET variable 'comment' has a value, is correct, but this needs to go in the processing after the form is submitted, which you do not show. From the code you have shown, you will only have 2 variables in $_GET. You will have $_GET['load'] which will have the value 'comments', and $_GET['view'] which will have the value 'add'. You also show to hidden form variables 'aid' and 'name' which would be in $_POST after submit. I would need to see more of the code to give you more specific help. John Link to comment https://forums.phpfreaks.com/topic/187854-echoing-if-function/#findComment-992286 Share on other sites More sharing options...
Elven6 Posted January 15, 2010 Author Share Posted January 15, 2010 Hey, Thanks for responding, sorry for the delay in getting back to you. <?php //To view the comments if ($_GET['j']) { include ("forum_functions.php"); //echo "<link rel='stylesheet' type='text/css' href='ta3.css'><table cellspacing=\"0\" cellpadding=\"1\" border=\"1\">"; $sql = mysql_query("SELECT * FROM ".$pre."comments WHERE comment = '".$_GET['j']."' ORDER BY `id` DESC"); while($r = mysql_fetch_array($sql)) { $sql2 = mysql_query("SELECT id FROM ".$pre."profile WHERE username = '".$r[name]."'"); $mr = mysql_num_rows($sql2); $ma = mysql_fetch_row($sql2); if ($mr > "0") { $user = "<a href='comments.php?load=elite&user=".$ma[0]."'>".$r[name]."</a>"; } else { $user = "Guest"; } echo "<tr><td><center><b>Profile</b></center></td><td><b>".$r[subject]."</b> posted by ".$user." at <i>".date($dformat, $r['date'])."</i></td></tr><tr><td>".comments($r[name])."</td><td><p>".bbcode(stripslashes($r[comment]))."</p>".comments3($r[name])."</td></tr>"; } echo "</table>"; } //To Post them if ($_GET['comment']) { //echo wysiwyg(); echo "<SCRIPT LANGUAGE='JavaScript'> function smiles(which) { document.form1.text1.value = document.form1.text1.value + which; } </SCRIPT> <script language='javascript'> function awindow(towhere, newwinname, properties) { window.open(towhere,newwinname,properties); } </script> <form name='form1' method='post' action='comments.php?load=comments&view=add'> <input type='hidden' name='comment' value='".$_GET['comment']."'> <input type='hidden' name='name' value='".$_COOKIE[$pre."username"]."'> <table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" align=\"center\"> <tr><td><b>Name</b></td><td>".$_COOKIE[$pre."username"]."</td></tr> <tr><td><b>E-mail</b></td><td>".$email."</td></tr> <tr><td><b>Subject</b></td><td><input type='text' name='title' width='18'></td></tr> <tr><td><b>Comments</b></td><td><textarea name=\"text1\" cols='18' rows='7'></textarea></td><td width='65'><b>Smilies</b><br>"; //echo "<br><br><a href='javascript:awindow(\"comments.php?load=comments&=smilies\", \"\", \"width=300,height=200,scroll=yes\")'>View All</a>"; echo "</td></tr><tr><td><input type='submit' value='Submit Comment'></td><td><input type='reset' name='reset' value='Reset'></td></tr></table></form>"; } echo "comments.php?load=comments&=comment"; if ($_GET['view'] == "add") { if ($_POST["name"] == "") { $name = "Guest"; } else { $name = $_COOKIE[$pre."username"]; } $comment = mysql_query("INSERT INTO ".$pre."comments VALUES ('null', '".$name."', '".$_POST["title"]."', '".addslashes($_POST["text1"])."', '".$_POST["comment"]."', '".$email."', '".time()."')") or die(mysql_error()); if ($comment == TRUE) { echo "Comment has been posted."; } } /*if ($_GET['view'] == "smilies") { echo "<SCRIPT LANGUAGE='JavaScript'> function smiles2(text) { text = '' + text + ''; opener.document.form1.text1.value += text; opener.document.form1.text1.focus(); } </SCRIPT><title>".$sitename." - Smilies :: View All</title>"; echo "<table cellpadding='1' cellspacing='0' border='0' width='198' height='100%'><tr><td width='198' align='left' valign='top'>"; if ($handle = opendir("smilies")) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $file2 = explode(".", $file); echo "<a href=\"javascript:smiles2(' :".strtolower($file2[0]).": ')\"><img src='smilies/".$file."' border='0'></a> "; } } } }*/ ?> Link to comment https://forums.phpfreaks.com/topic/187854-echoing-if-function/#findComment-995326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.