Warning: Header may not contain more than a single header, new line detected

But I checked and the variables and header all only use one line. Thanks

[php]

<?php session_start(); ?> <?php

require ‘connection.php’; ?>

<?php //if submit clicked if (isset($_POST['topic_submit'])) { //If topic title field or message field empty if (($_POST['topic_title'] == "") && ($_POST['topic_content'] == "")) { echo "You didn't fill in both fields"; exit(); } else { $cid = $_POST['cid']; $title = $_POST['topic_title']; $content = $_POST['topic_content']; $creator = $_SESSION['username']; //Insert the entered data into the appropriate database fields $sql = "INSERT INTO topics (category_id, topic_title, topic_creator, topic_date, topic_reply_date) VALUES ('".$cid."', '".$title."', '".$creator."', now(), now())"; //Result of above query $result = mysqli_query($DBconnect, $sql) or die(mysqli_error()); //After it inserts into topics table, will generate the auto incremented id number associated with the row and puts it into the variable $new_topic_id $new_topic_id = mysqli_insert_id($DBconnect); //Insert the post into the database $sql2 = "INSERT INTO posts (category_id, topic_id, post_creator, post_content, post_date) VALUE ('".$cid."', '".$new_topic_id."', '".$creator."', '".$content."', now())"; //Store result from above query $result2 = mysqli_query($DBconnect, $sql2) or die(mysqli_error()); //Update which category was set last (keep track of WHO POSTED LAST AND WHEN LAST POST DATE WAS, only update 1 category) $sql3 = "UPDATE categories SET last_post_date=now(), last_user_posted='".$creator."' WHERE id='".$cid."' LIMIT 1"; //result of above query $result3 = mysqli_query($DBconnect, $sql3) or die(mysqli_error()); //Check all been performed if (($result) && ($result2) &&($result3)) { header("Location: view_topic.php?cid=".$cid."&tid=".$new_topic_id); } else { echo "error"; } } } ?>

[/php]

Why are you escaping from php and then going back into php? The whole code never leaves php.

This is just a guess, based on your code.

[php]header(“Location: view_topic.php?cid=”.$cid."&tid=".$new_topic_id);[/php]

$cid and $new_topic_id are coming from user input (which is a BIG security risk), they may have character sets that you aren’t seeing. Use this,

[php]$cid = htmlspecialchars( trim( $_POST[‘cid’] ) );[/php]

I don’t know if that would solve it or not, that is an error I have not seen before.

You should be using prepared statements as well. If someone posts something like:

This is my favorite post he's the man.

It will throw an error in your database. So, not even for security in your case, but for ease of use, you should be using prepared statements.

Sponsor our Newsletter | Privacy Policy | Terms of Service