ok, I made a chatterbox script, and I am having a problem writing the IP's and names to a seperate table... here is the code I used to make the cb_users table:
if(isset($_GET['install'])){
head();
$connect = mysql_connect ($dbhost, $dbusername, $dbpassword); //connect
mysql_select_db ($dbname); //select the db
/* $result = mysql_query("CREATE TABLE $content_table (
name VARCHAR(50),
date VARCHAR(25),
message VARCHAR(150)
)
");
if(!$result){
echo "<br><br>CREATE TABLE ".$content_table." unsuccessful:<br /><br />".mysql_error();
} else {
echo "<br><br>Successfuly created the table '".$content_table."'!<br><br>";
}
*/
$result = mysql_query("CREATE TABLE $users_table (
name VARCHAR(50),
ip VARCHAR(25))
");
if(!$result){
echo "<br><br>CREATE TABLE ".$users_table." unsuccessful:<br /><br />".mysql_error();
} else {
echo "<br><br>Successfuly created the table '".$users_table."'!<br><br>";
}
mysql_close($connect);
foot();
}
now, here is the code I use to write the information to the cb_content table and cb_users table:
if(isset($_GET['writechatterbox'])){
$ip = $_POST['ip'];
$name = $_POST['name']; //name
$date = time(); //time
$message = $_POST['chatter']; //chatter text to post
$message = trim($message); //trim it cap'in!!!
$message = ereg_replace("([ ]{2})", "\\1", $message);
$message = eregi_replace(" +", " ", $message);
setcookie("chatter_name", $name, time()+60*60*24*29.5*12); //set the cookie to remember the user name
$connect = mysql_connect ($dbhost, $dbusername, $dbpassword); //connect
mysql_select_db ($dbname); //select the db
$result = mysql_query ("INSERT INTO $content_table (name, date, message)
VALUES ('$name', '$date', '$message')
"); //write the post to the db
if(!$result){
echo "write to database uncessfull: <br>".mysql_error();
mysql_close($connect);
} else {
$message = 1;
}
$result = mysql_query ("INSERT INTO $content_table (name, ip)
VALUES ('$name', '$ip')
");
if(!$result){
echo "write to database uncessfull: <br>".mysql_error();
mysql_close($connect);
} else {
$ip = 1;
}
if($message == 1 && $ip == 1){
header("Location: [url]http://[/url]".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/"."index.php");
exit;
} else {
echo "<br><br>There was an error!";
}
}
this is the error I get:
write to database uncessfull:
Unknown column 'ip' in 'field list'
There was an error!
the way I made the table, it should work, but the IP wont be stored in a seperate table... could you please help me?
the message will get written, but not the IP.