Is there any problem with this code? Why can't I create a database table?

Source: Internet
Author: User
Is there a problem with this code? Why can't I create database tables? & Lt ;? Php $ con & nbsp; = & nbsp; mysql_connect ("localhost", "root", "") & nbsp; or & nbsp; die ("connection error "); $ AB & nbsp; = & nbsp; mysql_select_db ("Is there a problem with the my_d code? Why can't I create database tables?
$ Con = mysql_connect ("localhost", "root", "") or die ("connection error ");
$ AB = mysql_select_db ("my_db", $ con );
If ($ AB ){
Echo "succeeded ";
}
$ SQL = "CREATE TABLE 'test '(
'Id' int (10) not null auto_increment,
'Uid' varchar (10) not null default '0 ',
'Regdate' date not null,
'Remark' text,
Primary key ('id ')
) ENGINE = InnoDB default charset = gbk AUTO_INCREMENT = 1;

Insert into 'test' ('id', 'uid', 'regdate', 'remark') VALUES
(1, 'Zhang San', '2017-07-02 ', 'Student '),
(2, 'Li Si', '2017-07-03 ', 'studen '),
(3, 'Wang Wu', '2017-07-02 ', 'Worker '),
(4, 'Zhao Liu', '2017-07-01 ', 'studen ');
";
$ Abc = mysql_query ($ SQL, $ con );
If ($ abc ){
Echo "created successfully ";
} Else {
Echo "failed ";
}


?>
------ Solution --------------------

$ Con = mysql_connect ("localhost", "root", "") or die ("connection error ");
$ AB = mysql_select_db ("my_db", $ con );
If ($ AB ){
Echo "succeeded ";
}
$ SQL = "CREATE TABLE 'test '(
'Id' int (10) not null auto_increment,
'Uid' varchar (10) not null default '0 ',
'Regdate' date not null,
'Remark' text,
Primary key ('id ')
) ENGINE = InnoDB default charset = gbk AUTO_INCREMENT = 1;
$ Abc = mysql_query ($ SQL, $ con );
If ($ abc ){
Echo "created successfully ";
} Else {
Echo "failed ";
}
$ Sql1 = "insert into 'test' ('id', 'uid', 'regdate', 'remark') VALUES
(1, 'Zhang San', '2017-07-02 ', 'Student ')"
$ Result = mysql_query ($ sql1 );
If ($ result ){
Echo "data inserted ";
}



------ Solution --------------------
Output the mysql error message of $ abc.

PS, 12 rows with fewer ending double quotation marks

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.