How PHP Inserts a database

Source: Internet
Author: User
Tags uuid

How PHP Inserts a database

  

$ostype =$_post[' OSType '];

$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 ' => ' link database failed ');

}

else {

mysql_select_db ($dbdatabase, $db _connect);

$result = mysql_query (INSERT into T_dblocal_userinformation (ID, OSType, UUID, lastdate) VALUES (NULL, $ostype, $uuid, $n Owtime) ");

if ($result) {

$ret _json=array (' Code ' =>1000, ' message ' => ' Insert database Success ');

}

else {

$ret _json=array (' Code ' =>1002, ' message ' => ' Insert database failed ');

}

}

$jobj =new Stdclass ();

foreach ($ret _json as $key => $value) {

$jobj-> $key = $value;

}

Echo '. Json_encode ($jobj);

?>

Why did you fail to insert the database??

ID is the Lastdate primary key, and the date type is

------Solution--------------------

What does the error prompt?

If Lastdate is the date type $nowtime =date (' y-m-d ');

If Lastdate is a datetime type $nowtime=date (' y-m-d h:i:s ');

------Solution--------------------

Echo Mysql_error (); Did you report anything wrong?

------Solution--------------------

The quotes are missing.

$result = mysql_query ("INSERT into T_dblocal_userinformation (ID, OSType, UUID, lastdate) VALUES (NULL, ' $ostype ', ' $uuid ' , ' $nowtime ') ");

------Solution--------------------

Reference:

The quotes are missing.

$result = mysql_query ("INSERT into T_dblocal_userinformation (ID, OSType, UUID, lastdate) VALUES (NULL, ' $ostype ', ' $uuid ' , ' $nowtime ') ");

------Solution--------------------

The first thing to say about the quotes upstairs

The second your time () is the timestamp of the return, and the date type does not correspond to the conversion process.

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.