June 30, 200818 yr Trying to pass variables into a form and having some probs, thought this would work : <form id="forumpost" method="post" action="transact-post.php"> <h3><?php echo $edit_mode ?"Edit Post" :"$forumname: $topicname"; ?> </h3> <p> <?php echo $title; ?> <br> <input type="text" class="subject" name="subject" maxlength="255" value="<?php echo $subject; ?>"> </p> <p> <?php echo $secline; ?> <br> <textarea class="body" name="body" rows="10" cols="60"><?php echo $body; ?></textarea> </p> <p> But having trouble getting it to work, any opinions?
July 1, 200818 yr I'm not a php expert as I haven't had the chance to delve too much into php yet. Now maybe i'm just being a n00b, but don't you need to actually define the variables first before you echo them? for example, if you were to add something like this to the top of your script: <?php $forumname = "Some forum"; $topicname = "Some Topic"; $title = "This is a title!"; $subject = "Test Subject"; $body = "Test Message"; ?> The echoing further on in the script would then be able to relate to the variables set and thus be able to display the data, right..? Or alternatively, if you're trying to pass variables after something has been submitted, I believe you would use the $_GET variable. In the format of $_GET[fieldname] with 'fieldname' replacing the name id of the field you're grabbing the data from. Again, maybe i'm just being a n00b and have totally missed the point. If so it'd probably be helpful if you provide some more information so maybe others will be able to help some more.
July 1, 200818 yr Author I'm not a php expert as I haven't had the chance to delve too much into php yet. Now maybe i'm just being a n00b, but don't you need to actually define the variables first before you echo them? for example, if you were to add something like this to the top of your script: <?php $forumname = "Some forum"; $topicname = "Some Topic"; $title = "This is a title!"; $subject = "Test Subject"; $body = "Test Message"; ?> The echoing further on in the script would then be able to relate to the variables set and thus be able to display the data, right..? Or alternatively, if you're trying to pass variables after something has been submitted, I believe you would use the $_GET variable. In the format of $_GET[fieldname] with 'fieldname' replacing the name id of the field you're grabbing the data from. Again, maybe i'm just being a n00b and have totally missed the point. If so it'd probably be helpful if you provide some more information so maybe others will be able to help some more. I appreciate your input but I had only put up the form part of the code the declaring of variables is done before this in the code, thanks anyway.
July 1, 200818 yr Author The form is fine, I tested it this morning on a page of it's own. But I still get an error when trying to access the php file. The error I get is : Parse error: syntax error, unexpected $end in /home/compose.php on line 141 and my full code is : <?php require_once 'conn.php'; require_once 'functions.php'; require_once 'header.php'; $subject = ''; if (isset($_GET['topicid'])) { $topicid = $_GET['topicid']; } else { $topicid = ""; } if (isset($_GET['forumid'])) { $forumid = $_GET['forumid']; } else { $forumid = ""; } if (isset($_GET['reid'])) { $reid = $_GET['reid']; } $body = ''; $post = ''; $authorid = $_SESSION['user_id']; $edit_mode = FALSE; if (isset($_GET['a']) and $_GET['a'] == 'edit' and isset($_GET['post']) and $_GET['post']) { $edit_mode = TRUE; } require_once 'header.php'; if (!isset($_SESSION['user_id'])) { echo "<div class=\"notice\">" . "You must be logged in to post. Please <a href=\"" . "login.php\">Log in</a> before posting a message." . "</div>"; } elseif ($edit_mode and $_SESSION['user_id'] != $authorid) { echo "<div class=\"noauth\">" . "You are not authorized to edit this post. Please contact " . "your administrator.</div>"; } else { if ($edit_mode) { $sql = "SELECT * FROM forum_posts p, forum_forum f " . "WHERE p.id = " . $_GET['post'] . " AND p.forum_id = f.id"; $result = mysql_query($sql,$conn) or die('Could not retrieve post data; ' . mysql_error()); $row = mysql_fetch_array($result); $subject = $row['subject']; $topicid = $row['topic_id']; $forumid = $row['forum_id']; $body = $row['body']; $post = $_GET['post']; $authorid = $row['author_id']; } else { if ($topicid == "") { $topicid = 0; $topamt = 0; $topicname = "New Topic"; } else { $topamt = 1; if ($reid != "") { $sql = "SELECT subject FROM forum_posts WHERE id = " . $reid; $result = mysql_query($sql, $conn) or die('Could not retrieve topic; ' . mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result); $re = preg_replace("/(re: )/i","",$row['subject']); } } $sql = "SELECT subject FROM forum_posts WHERE id = "; $sql .= $topicid . " AND topic_id = 0 AND forum_id = $forumid"; $result = mysql_query($sql,$conn) or die('Could not retrieve topic; ' . mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result); $topicname = "Reply to <em>" . $row['subject'] . "</em>\n"; $subject = ($re == ""?"":"Re: " . $re); } else { $topicname = "Reply"; $topicid = 0; } } } if ($forumid == "" or $forumid == 0) $forumid = 1; $sql = "SELECT forum_name FROM forum_forum " . "WHERE id = '" . $forumid . "'"; $result = mysql_query($sql, $conn) or die('Could not retrieve forum name; ' . mysql_error()); $row = mysql_fetch_array($result); $forumname = $row['forum_name']; if($topamt == 0) { $title = "Title of offer"; $secline = "Description"; }else { $title = "Title"; $secline = "Reply"; } ?> <form id="forumpost" method="post" action="transact-post.php"> <h3><?php echo $edit_mode ?"Edit Post" :"$forumname: $topicname"; ?> </h3> <p> <?php echo $title; ?> <br> <input type="text" class="subject" name="subject" maxlength="255" value="<?php echo $subject; ?>"> </p> <p> <?php echo $secline; ?> <br> <textarea class="body" name="body" rows="10" cols="60"><?php echo $body; ?></textarea> </p> <p> <?php if ($edit_mode) { echo '<input type="submit" class="submit" name="action" ' . "value=\"Save Changes\">\n"; } else { echo '<input type="submit" class="submit" name="action" ' . "value=\"Submit New Post\">\n"; ?> </p> <?php echo "<input type=\"hidden\" name=\"post\" " . "value=\"$post\">\n"; echo "<input type=\"hidden\" name=\"topic_id\" " . "value=\"$topicid\">\n"; echo "<input type=\"hidden\" name=\"forum_id\" " . "value=\"$forumid\">\n"; echo "<input type=\"hidden\" name=\"author_id\" " . "value=\"$authorid\">\n"; echo "</form>\n"; } require_once 'footer.php'; ?> Any ideas whats wrong there?
July 1, 200818 yr I think you have problem with "{" or "}." The error says, that the function closes too soon / early. So check your {'s and }'s I'd suggest you to use only php for the form. I mean echo();. It makes your script much more simple.
July 1, 200818 yr Author I think you have problem with "{" or "}." The error says, that the function closes too soon / early. So check your {'s and }'s I'd suggest you to use only php for the form. I mean echo();. It makes your script much more simple. I don't see a problem there myself. I had the script working with just a simple form at the bottom where the variables were replaced with plain html text, it worked fine but I want the first poster to be given different output than the proceeding posters. It was only when I introduced the variables $title and $secline that the problem occured. I naturally thought it was the form but after testing that it was nothing there so must be something that I am over looking regarding the new variables.
July 1, 200818 yr It has already been said but you are missing a } in your code somewhere, but it is hard to tell in that formatting.
Create an account or sign in to comment