Jump to content

Chat program Error....


DionRodrigues

Recommended Posts

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!

Link to comment
Share on other sites

    
$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?

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.