Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6994713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:55:38+00:00 2026-05-27T19:55:38+00:00

I am trying to create a PM system on my website however the sending

  • 0

I am trying to create a PM system on my website however the sending does not work…

Here is my code:

<?php
$from = $_POST['from'];
$to = $_POST['to'];
$content = $_POST['content'];
$date = date("Y-n-j H:i:s");
$id = rand(0000,9999);

include('sql_connect.php');
mysql_query("INSERT INTO pm (`from`, `to`, `content`, `date`, `id`) VALUES ('".$from."', '".$to."', '".$content."', '".$date."', '".$id."')");
mysql_close($con);
header('Location: members.php?sent');
?>

Can someone tell me why it doesn’t work?

EDIT: I added backtits but the result is this:

NULL 
Warning: Cannot modify header information - headers already sent by (output started at /home/quebecen/public_html/new/do_pm.php:10) in /home/quebecen/public_html/new/do_pm.php on line 15

EDIT 2: I added $result before que mysql_query() (I forgot it) and now I have this code:

<?php
$from = $_POST['from'];
$to = $_POST['to'];
$content = $_POST['content'];
$date = date("Y-n-j H:i:s");
$id = rand(0000,9999);

include('sql_connect.php');
$result = mysql_query("INSERT INTO pm (`from`, `to`, `content`, `date`, `id`) VALUES ('".$from."', '".$to."', '".$content."', '".$date."', '".$id."')", $con);

var_dump($result);

if(!$result) {
    echo mysql_error();
}

mysql_close($con);
header('Location: members.php?sent');
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:55:38+00:00Added an answer on May 27, 2026 at 7:55 pm

    The error your getting is because your outputting the buffer & then trying to add a header; (This can be a single space or a carriage return or the error message its self, but in your case its the var_dump) . Also You have sql injections vulnerabilities from not escaping
    the post variables, I do suggest you forget about the mysql_* family of functions and move to PDO prepared statements:

    <?php
    //Start a session to hold the status
    session_start();
    try {
        $dbh = new PDO("mysql:host=localhost;dbname=yourDB", 'dbUser', 'dbPass');
    
        /*** set the error reporting attribute ***/
        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
        /*** some variables ***/
        $from = $_POST['from'];
        $to = $_POST['to'];
        $content = $_POST['content'];
        $date = date("Y-n-j H:i:s");
    
        $id = rand(0000,9999); //? This is wrongly implemented if you want a uniqie id, you should be using the AUTO INCREMENT value
    
        /*** prepare the SQL statement ***/
        $stmt = $dbh->prepare("INSERT INTO pm (`from`, `to`, `content`, `date`, `id`)VALUES(:from, :to, :content, :date, :id)");
    
        /*** bind the paramaters ***/
        $stmt->bindParam(':id', $id, PDO::PARAM_INT);
        $stmt->bindParam(':from', $from, PDO::PARAM_STR, strlen($from));
        $stmt->bindParam(':to', $to, PDO::PARAM_STR, strlen($to));
        $stmt->bindParam(':content', $content, PDO::PARAM_STR, strlen($content));
        $stmt->bindParam(':date', $date, PDO::PARAM_STR, strlen($date));
    
    
        /*** execute the prepared statement ***/
        $stmt->execute();
        /*** close the database connection ***/
        $dbh = null;
    
        //Set as sent, redirect to members cleanly and then check session var is true
        $_SESSION['sent']=true;
        header('Location: ./members.php');
    }
    catch(PDOException $e)
    {
        //Something went wrong
        $_SESSION['sent']=false;
        //You should log this error, and not output any internal errors to the user, just advise them something went wrong.
        error_log("FATAL MSG ERROR:".$e->getMessage(), 3, "/home/quebecen/logs/my-errors.log");
    
        header('Location: ./members.php');
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a safe user authentication system. The code is from http://net.tutsplus.com/tutorials/php/simple-techniques-to-lock-down-your-website/
so I'm trying to create a ranking system for my website, however as a
I am trying to create a dynamic pagination system for my website and I've
I'm trying to create system users with a php script securely, In that, I'd
I'm trying to create an access control system. Here's a stripped down example of
I am trying to create a views system on my books website. I have
I'm trying to create a private messaging system for my website, and I am
I was trying to create a notifications system for a website with the following
I'm a beginner in PHP trying implementing a simple registration system for a website.
I'm trying to create a basic system that will allow only specific users to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.