Jump to content

inserting session value into DB


unsider

Recommended Posts

This query is frustrating me, mainly because I can't find a well written article explaining how it all works. I am trying to insert a session value into a DB, and retrieve it in a later script. I've tested everything in the script up till the query, therefore I know thats the error.

 

Heres the output:

 

session->username set.

Able to locate database.

post array was set.

Error adding query: Column count doesn't match value count at row 1

Warning: Cannot modify header information - headers already sent by (output started at /home/unsider/www/andy/comment_process.php:13) in /home/unsider/www/andy/comment_process.php on line 37

 

Code:

 

<?php

include("include/session.php");


if(!$session->username) {
header('main.php');
}
else
{

if($session->username) {
echo "session->username set." . "<br>";
}

if (!@mysql_select_db('mtlc?old')) {
		echo 'Unable to locate the ' . 'database.';
}

if (mysql_select_db('mtlc?old')) {
		echo 'Able to locate database.' . "<br>	";
}


if(isset($_POST['commenttext'])) {

echo "post array was set" . "<br>";

// HELP ################################################################################

$commenttext = $_POST['commenttext'];
$username = $session->$username;

$sql="INSERT INTO `comments` VALUES ( '$username','$commenttext', 'NOW()' )";

// ####################################################################################

if (!@mysql_query($sql)) {
		echo 'Error adding query: ' . mysql_error();

header('main.php');

	}
}
}
?>

 

Please help :(

Link to comment
Share on other sites

there are four columns in my table* (will be adding more later, but for now I'm trying to establish something)

 

id (int) , commenttext (text) , commentdate (datetime), username (varchar255)

 

respectively, so i guess they are not in order.

Link to comment
Share on other sites

<?php
ob_start();
include("include/session.php");


if(!$session->username) {
header('main.php');
}
else
{

if($session->username) {
echo "session->username set." . "<br>";
}

if (!@mysql_select_db('mtlc?old')) {
		echo 'Unable to locate the ' . 'database.';
}

if (mysql_select_db('mtlc?old')) {
		echo 'Able to locate database.' . "<br>	";
}


if(isset($_POST['commenttext'])) {

echo "post array was set" . "<br>";

// HELP ################################################################################

$commenttext = $_POST['commenttext'];
$username = $session->$username;
$sql="INSERT INTO `comments`('commenttext','commentdate','username')VALUES ( $commenttext', 'NOW()','$username' )";

// ####################################################################################

if (!@mysql_query($sql)) {
		echo 'Error adding query: ' . mysql_error();



header('main.php');

	}
}
}
?>

Link to comment
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.