How to insert PHP into the database. How to insert a database in PHP $ ostype $ _ POST [ostype]; $ uuuuid]; $ nowtimetime (); $ usernameXXXX; $ userpassXXXX; $ dbhostlocalhost; $ dbdatabaseXXX; how to insert a PHP connection to a database
$ Ostype =$ _ POST ['osstype'];
$ Uuid = $ _ POST ['uuid'];
$ Nowtime = time ();
$ Username = 'xxxx ';
$ Userpass = 'xxxx ';
$ Dbhost = 'localhost ';
$ Dbdatabase = 'XXX ';
// Generate a connection
$ Db_connect = mysql_connect ($ dbhost, $ username, $ userpass) or die ("Unable to connect to the MySQL! ");
$ Ret_json;
If (! $ Db_connect ){
$ Ret_json = array ('code' => 1001, 'message' => 'Database connection failed ');
}
Else {
Mysql_select_db ($ dbdatabase, $ db_connect );
$ Result = mysql_query ("insert into t_dblocal_userinformation (ID, OSTYPE, UUID, LASTDATE) VALUES (NULL, $ ostype, $ uuid, $ nowtime )");
If ($ result ){
$ Ret_json = array ('code' => 1000, 'message' => 'Database inserted successfully ');
}
Else {
$ Ret_json = array ('code' => 1002, 'message' => 'Database insertion failed ');
}
}
$ Jobj = new stdclass ();
Foreach ($ ret_json as $ key => $ value ){
$ Jobj-> $ key = $ value;
}
Echo ''. json_encode ($ jobj );
?>
Why does the database insertion fail ??
ID is the auto-increment primary key and LASTDATE is the DATE type.
------ Solution --------------------
What is the error message?
If LASTDATE is of the DATE Type $ nowtime = date ('Y-m-D ');
If LASTDATE is of the DATETIME type $ nowtime = date ('Y-m-d H: I: s ');
------ Solution --------------------
Echo mysql_error (); no error reported
------ Solution --------------------
The quotation marks are missing.
$ Result = mysql_query ("insert into t_dblocal_userinformation (ID, OSTYPE, UUID, LASTDATE) VALUES (NULL, '$ ostype', '$ uuid', '$ nowtime ')");
------ Solution --------------------
Reference:
The quotation marks are missing.
$ Result = mysql_query ("insert into t_dblocal_userinformation (ID, OSTYPE, UUID, LASTDATE) VALUES (NULL, '$ ostype', '$ uuid', '$ nowtime ')"); agree
------ Solution --------------------
The first question about the quotation marks that I want to say above
Second, your time () is the returned timestamp. if it does not match the date type, you have to convert it for processing.
Dimensions $ ostype =$ _ POST ['osstype']; $ uuid =$ _ POST ['uuid']; $ nowtime = time (); $ username = 'xxxx '; $ userpass = 'xxxx'; $ dbhost = 'localhost'; $ dbdatabase = 'XXX'; // Generate a connection...