neex1233 Posted July 15, 2009 Share Posted July 15, 2009 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! Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 15, 2009 Share Posted July 15, 2009 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? Quote Link to comment Share on other sites More sharing options...
neex1233 Posted July 15, 2009 Author Share Posted July 15, 2009 It's on both tables. Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 15, 2009 Share Posted July 15, 2009 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. Quote Link to comment Share on other sites More sharing options...
neex1233 Posted July 16, 2009 Author Share Posted July 16, 2009 It's none of those. Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 16, 2009 Share Posted July 16, 2009 ... okay? if it's solved, care to share with the rest of the class what the problem was? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.