Jump to content

[SOLVED] Unknown Column


neex1233

Recommended Posts

Hi, I made a comment script:

 

<?php
$con = mysql_connect("localhost","Username","Password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DB_Name", $con);

$username = mysql_real_escape_string($_SESSION["username"]);
$sql = "
   SELECT *
   FROM `users` 
   WHERE username = '$username' 
   LIMIT 0, 30
"; 
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$userlevel =  $row['userlevel'];
$userlevel =  $row['name'];
}

if ( $userlevel == 5 ) {
$table = "comments";
$em = "Hello there admin $name! Your comment has been posted!";
}

if ( $userlevel == 4 ) {
$table = "comments";
$em = "Hello, $username. Your comment has been posted and will not need to be approved by an admin.";
}

if ( $userlevel == 3 ) {
$table = "ucomments";
$em = "Hi $username! Your comment will need to be approved by an admin before getting shown on the site.";
}

if ( $userlevel == 2 ) {
$table = "ucomments";
$em = "Ooooh, $name, you just made it! If you were one userlevel lower, you wouldn't be able to post comments! Your comment must be approved though...";
}

if ( $userlevel == 1 ) {
echo "Sorry $name. Your userlevel is too low or you have been banned from posting comments.";
die();
}

$poster = mysql_real_escape_string($_SESSION["username"]);
$text = mysql_real_escape_string($_POST["text"]);
$userlevel = $_SESSION['userlevel'];

putenv("TZ=America/Los_Angeles");
$time = date("g:i A");
$date = date("M/j/Y");
$for = mysql_real_escape_string($_POST["for"]);

function doSmily($msg)
{
\\ Word filter. Not showing...
return $msg;
}
$input = "$text";
$ntext = doSmily($input);
$stext = mysql_real_escape_string($ntext);

$sql="INSERT INTO $table (poster,text,time,date)
VALUES
('$poster','$stext','$time','$date')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "<strong><center>$em</center></strong>";
mysql_close($con);
?>

 

And I get this error:

 

Error: Unknown column 'poster' in 'field list'

 

I've googled it and everything, but I still can't figure out what's wrong. Could anybody help me? Thanks!

Link to comment
Share on other sites

the simple answer is exactly what the computer is telling you: 'poster' doesn't exist in the table you're trying to run the INSERT query on. are you sure it exists in both the 'comments' and the 'ucomments' tables?

Link to comment
Share on other sites

then my guess is you're trying to run the INSERT with a user whose userlevel is 1. in that case, no $table is defined, and the INSERT query will obviously fail. if that isn't the case, it might be worth making sure that you didn't make any typos when defining the table's fields.

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.