1

I have a simple table:

describe chat_public_messageboard ;

    +--------------+---------------+------+-----+---------+----------------+
    | Field        | Type          | Null | Key | Default | Extra          |
    +--------------+---------------+------+-----+---------+----------------+
    | message_id   | int(100)      | NO   | PRI | NULL    | auto_increment |
    | message_from | varchar(255)  | NO   |     | NULL    |                |
    | message_to   | varchar(20)   | NO   |     | NULL    |                |
    | message_body | tinytext      | NO   |     | NULL    |                |
    | message_time | varchar(50)   | NO   |     | NULL    |                |
    | welcome_msg  | enum('0','1') | NO   |     | 0       |                |
    +--------------+---------------+------+-----+---------+----------------+

When I do an insert from the terminal, it works fine: select * 314 | sweety_margs | daffy | what did you say?

INSERT INTO chat_public_messageboard ( message_from , message_body , message_time , message_to , welcome_msg ) VALUES ( 'pdz' , 'what did you say?\n' , '1260948972' , 'pdz2' , 1 ) "

But when I send this exact query through the mysql db->query() function, the question mark turns to NULL

$query = $querystring = "INSERT INTO chat_public_messageboard ( message_from , message_body , message_time , message_to , welcome_msg ) VALUES ( 'pdz' , 'what did you say?\n' , '1260948972' , 'pdz2' , 1 ) " ;
db->query($querystring);

-

select *
    314 | sweety_margs  | daffy          | what did you sayNULL  

Thanks.

Amber
  • 507,862
  • 82
  • 626
  • 550
peter
  • 21
  • 2
  • Why are you putting newline characters at the end of the messages? – pavium Dec 16 '09 at 07:59
  • With or without newline made no difference. This is running through osDate's database layer. You guys were all right on: The string had to be sent as a parameter due to having the ? because there was no way to escape that character. – peter Dec 16 '09 at 21:03

3 Answers3

3

The ? is typically used as a placeholder for parametrized arguments in the PHP interface to various SQL. Thus, it's probably thinking it's a placeholder that you never specified a value for (and thus is NULL).

Amber
  • 507,862
  • 82
  • 626
  • 550
1

What PHP framework are you using? I'm suspecting that the framework is using '?' to bind parameters into your SQL statement and since you didn't provide the parameter it defaults to NULL.

Lukman
  • 18,462
  • 6
  • 56
  • 66
1

It looks like it thinks you are trying to add a parameter to that query. What is the question mark's significance in MySQL at "WHERE column = ?"?

Community
  • 1
  • 1
fredrik
  • 13,282
  • 4
  • 35
  • 52