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
https://forums.phpfreaks.com/topic/166129-solved-unknown-column/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.