Parse error / any help would be great, I'm going insane

the full error is:

Parse error: syntax error, unexpected ‘>’ in C:Program Filesxampphtdocsprojectsfinaladdtopic.php on line 36

the following is the code. I need a second set of eyes. I can’t get the script to run.

[code]<?php
//check for required fields from the form
if ((!$_POST[“topic_owner”]) || (!$POST[“topic_title”]) ||
(!$POST[“post_text”])) {
header(“Location: addtopic.html”);
exit;
}

//connect to server
$mysqli = mysqli_connect(“localhost”, “joeuser”, “somepass”, “testDB”);

//create and issue the first query
$add_topic = “INSERT INTO forum_topics (topic_title, topic_create_time, topic_owner)
VALUES (’”.$POST[“topic_title”]."’,now(), ‘".$_POST[“topic_owner”]."’)";

$add_topic_res = mysqli_query($mysqli, $add_topic_sql) or die(mysqli_error($mysqli));

//get the id of the last query
$topic_id = mysqli_insert_id($mysqli);

//create and issue the second query
$add_post_sql = “INSERT INTO forum_posts (topic_id, post_text,
post_create_time, post_owner) VALUES (’”.$topic_id."’,
‘".$POST[“post_text”]."’, now(),
‘".$POST[“topic_owner”]."’);

$add_post_res = mysqli_query($mysqli, $add_post_sql)
or die(mysqli_error($mysqli));

mysqli_close($mysqli);

// THIS IS LINE 35
$display_block = “

The “.$_POST[“topic_title”].” topic has been created.

”;

?>

New Topic Added

New Topic Added

<?php echo $display_block; ?>

[/code]

the sending page is here.

<html>
<head>
<title>Add a Topic</title>
</head><body>
<h1>Add a Topic</h1>
<form method="post" action="addtopic.php">
<p><strong>Your E-mail Address:</strong><br/>
<input type="text" name="topic_owner" size="40" maxlength="150" /></p>
<input type="text" name="topic_title" size="40" maxlength="150" /></p>
<p><strong>Post Text:</strong><br/>
<textarea name="post_text" rows="8" cols="40" wrap="virtual"></textarea></p>
<p><input type="submit" name="submit" value="Add Topic"/></p>
</form>


</body>
</html>

My recommendations:

First off you should never directly insert $_Post variables directly into your database. You should always go the extra effort of putting them into variables:

$topic_owner = $_POST[‘topic_owner’]; - This way you can first do some security checks and make sure no malcious code or other bad values get put into the table. In the least it saves keystrokes when needing to use the value over and over again.

Then once you have done this insert statments are written like the following:

$in_q = “INSERT INTO mytable (field1, field2, field3) VALUES (’$value1’, ‘$value2’, ‘$value3’)”;

Also when you using $_POST use single quotes as this will save you from the problem you are having, I think! $_POST[‘var_name’]

Make those changes and let us know if you are still having problems.

Sponsor our Newsletter | Privacy Policy | Terms of Service