Why do I use PHP code to insert data into MySQL displayed as empty

Source: Internet
Author: User
Why do I use PHP code to insert data into a MySQL field where some fields appear to be empty and the inserted values can appear my code is as follows


Include ("conn.php");

if ($_post[' submit ']) {

$sql = "INSERT into message (id,user,title,content,lastdate)".
"Value (' ', ' $_post[user] ', ' $_post[title] ', ' $_post[content] ', now ())";
mysql_query ($sql);
echo "Publishing Success";
}
?>



The contents of the phpMyAdmin.
ID User Title Content lastdate
1 One of my titles for my PHP 2012-04-15
2 _ My content for your PHP 2012-04-15




Reply to discussion (solution)

mysql_query ($sql) or Die (Mysql_error ());
Come up with the results!
Maybe you don't know what's going on.

Echo $sql; Output what results. Also paste your table structure.


$conn = @mysql_connect ("localhost", "root", "") or Die ("Connection unsuccessful");
mysql_select_db ("BBS", $conn);
mysql_query ("Set names ' GBK '");
?>

This is the PHP code that connects the database.


CREATE TABLE ' message ' (
' id ' tinyint (1) not NULL auto_increment,
' User ' varchar (+) not NULL,
' title ' varchar (not NULL),
' Content ' Tinytext not NULL,
' Lastdate ' date not NULL,
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT CHARSET=GBK auto_increment=1;

This is the SQL statement that inserts the table

echo $sql; The result of the output is this
INSERT into message (id,user,title,content,lastdate) value (', ', ' Test title ', ' ', Now () ')

Echo $sql; Output what results. Also paste your table structure.



$conn = @mysql_connect ("localhost", "root", "") or Die ("Connection unsuccessful");
mysql_select_db ("BBS", $conn);
mysql_query ("Set names ' GBK '");
?>

This is the PHP code that connects the database.


CREATE TABLE ' message ' (
' id ' tinyint (1) not NULL auto_increment,
' User ' varchar (+) not NULL,
' title ' varchar (not NULL),
' Content ' Tinytext not NULL,
' Lastdate ' date not NULL,
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT CHARSET=GBK auto_increment=1;

This is the SQL statement that inserts the table

No problem. I don't know what you're talking about. What field does the field have no value?

No problem. I don't know what you're talking about. What field does the field have no value?


echo $sql; The result of the output is this
INSERT into message (id,user,title,content,lastdate) value (', ', ' Test title ', ' ', Now () ')

Do you have any questions about values?

Do you have any questions about values?


After I changed value to values

Echo $sql;
INSERT into message (id,user,title,content,lastdate) VALUES (",", ' Sub-ha ', ', Now ())
Inserted user and content contents or empty puzzling ah will not be MySQL and the table encoding is not the same I installed the Xamp integration environment I set this default-character-set=gbk in the MySQL config file under [Client] in [ MYSQLD] Set the DEFAULT-CHARACTER-SET=GBK

I already told you.

mysql_query ($sql) or Die (Mysql_error ());
Come up with the results!

Some fields appear empty and the inserted values can appear

The INSERT statement above you a lot of values are "" what strange?

Some fields appear empty and the inserted values can appear

The INSERT statement above you a lot of values are "" what strange?


I did a lot of stuff when I inserted it, but the Echo statement came out as if it were empty. The contents of the field are empty and the user and content are blank but the title is not empty. Can insert

mysql_query ($sql) or Die (Mysql_error ());
Come up with the results!
Maybe you don't know what's going on.


This statement has been added without any hint that the insert content is successful

if ($_post[' submit ']) {
Print_r ($_post); Post the results. See if there is a value

Some fields appear empty and the inserted values can appear

The INSERT statement above you a lot of values are "" what strange?


Not the null value I inserted I inserted the same field contents into 3 fields both user and content are displayed empty only the title field shows what I inserted

User:

Text is wrong.


$_post[Content]

Did you see it?

Problem solved no, landlord? I've had the same problem.

Excuse me, is this problem solved?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.