Jump to content

Recommended Posts

I am getting the following error and can do not understand why:

 

 

Parse error: parse error in D:\Program Files\xampp\htdocs\PHPbook\20\replytopost.php on line 7

 

Here is the code I am using:

 

<?php

//connect to server and select database; we'll need it soon

$conn = mysql_connect("localhost", "root", "ladydee") or die(mysql_error());

mysql_select_db("brain-host,$conn)  or die(mysql_error());

 

//check to see if we're showing the form or adding the post

if ($_POST[op] != "addpost") {

// showing the form; check for required item in query string

if (!$_GET[post_id]) {

header("Location: topiclist.php");

exit;

}

 

//still have to verify topic and post

$verify = "select ft.topic_id, ft.topic_title from forum_posts as fp left join forum_topics as ft on fp.topic_id = ft.topic_id where fp.post_id = $_GET[post_id]";

 

$verify_res = mysql_query($verify, $conn) or die(mysql_error());

if (mysql_num_rows($verify_res) < 1) {

//this post or topic does not exist

header("Location: topiclist.php");

exit;

} else {

//get the topic id and title

$topic_id = mysql_result($verify_res,0,'topic_id');

$topic_title = stripslashes(mysql_result($verify_res, 0,'topic_title'));

 

echo "

<html>

<head>

<title>Post Your Reply in $topic_title</title>

</head>

<body>

<h1>Post Your Reply in $topic_title</h1>

<form method=post action=\"$_SERVER[php_SELF]\">

<p><strong>Your E-Mail Address:</strong><br>

<input type=\"text\" name=\"post_owner\" size=40 maxlength=150>

 

<P><strong>Post Text:</strong><br>

<textarea name=\"post_text\" rows=8 cols=40 wrap=virtual></textarea>

 

<input type=\"hidden\" name=\"op\" value=\"addpost\">

<input type=\"hidden\" name=\"topic_id\" value=\"$topic_id\">

 

<P><input type=\"submit\" name=\"submit\" value=\"Add Post\"></p>

 

</form>

</body>

</html>";

}

} else if ($_POST[op] == "addpost") {

//check for required items from form

if ((!$_POST[topic_id]) || (!$_POST[post_text]) || (!$_POST[post_owner])) {

header("Location: topiclist.php");

exit;

}

 

//add the post

$add_post = "insert into forum_posts values ('', '$_POST[topic_id]', '$_POST[post_text]', now(), '$_POST[post_owner]')";

mysql_query($add_post,$conn) or die(mysql_error());

 

//redirect user to topic

header("Location: showtopic.php?topic_id=$topic_id");

exit;

}

?>

 

 

Thank you for any help on this.  I think I have used this before and it worked, so I copied it from where I had used it before and changed the database name

 

Ladydee

Link to comment
https://forums.phpfreaks.com/topic/150587-parse-error/
Share on other sites

OK, I have fixed the parse error, but I get an error on this line of the file now:

 

header("Location: showtopic.php?topic_id=$topic_id");

 

which is line 87.  I know that this will happen if more then one header is called.  I there a way to redirect the header, turn if off and back on so that the page can show.  As you can see it depends on what the use wants to do on which page will show.

 

Thank you

 

 

Link to comment
https://forums.phpfreaks.com/topic/150587-parse-error/#findComment-791146
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.