DionRodrigues Posted March 17, 2008 Share Posted March 17, 2008 Hello, First, I'm new here And I'm having a few problems with my PHP script..... First, I'm writing a chat program. A user enters text into a text field called "text" and then the text field and the posters username is entered into my database called chat in the from and message columns. I'm having a few problems writing the posters username into the database. First, the username, called "ID" in my sites cookie, is called as $username, and I can't get it to write into the database. It either gives me a syntax error or a blank screen depending on the way I try to insert the $username into the from column. This is my query: $insert = 'INSERT INTO chat (message) VALUES ("'.$_POST['username'].'", "'.$_POST['text'].'") '; Can anybody help? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
crashmaster Posted March 17, 2008 Share Posted March 17, 2008 $insert = 'INSERT INTO chat (username,message) VALUES ("'.$_POST['username'].'", "'.$_POST['text'].'") '; Quote Link to comment Share on other sites More sharing options...
DionRodrigues Posted March 17, 2008 Author Share Posted March 17, 2008 $insert = 'INSERT INTO chat (username,message) VALUES ("'.$_POST['username'].'", "'.$_POST['text'].'") '; It doesn't work.... its organized right and it gives me a syntax error..... (also, username has to be $username since its calling the variable out of a cookie, declared by $username = $_COOKIE['ID'] This is the syntax error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from,message) VALUES ("", "hi")' at line 1 Any ideas? Quote Link to comment Share on other sites More sharing options...
crashmaster Posted March 17, 2008 Share Posted March 17, 2008 you have to follow mySQl rules.. if you doing query like this insert into 'lol' (col1,col2,col3) VALUES (val1) - you have to enter 3 values for 3 columns.. you have to have sam count of values and columns.. right syntax is - insert into 'lol' (col1,col2,col3) VALUES (val1,val2,val3) You syntax is wrong, coz you are trying to insert into column message - 2 values - username and message.. Quote Link to comment Share on other sites More sharing options...
DionRodrigues Posted March 17, 2008 Author Share Posted March 17, 2008 you have to follow mySQl rules.. if you doing query like this insert into 'lol' (col1,col2,col3) VALUES (val1) - you have to enter 3 values for 3 columns.. you have to have sam count of values and columns.. right syntax is - insert into 'lol' (col1,col2,col3) VALUES (val1,val2,val3) You syntax is wrong, coz you are trying to insert into column message - 2 values - username and message.. I understand that. I am trying to put the values "from" (the posters username represented in the script as $username) and message (the text field) into the table "chat". It just gives me an error because I don't think I'm using the correct format to insert a value thats a value....... 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.