<?php
//获取POST json 数据
$info = file_get_contents('php://input');
//解析数据
$info_array = json_decode($info, true);
if ($info_array) {
$name = $info_array['name'];
$company = $info_array['company'];
$mobile = $info_array['mobile'];
if(isset($info_array['email'])){
$email = $info_array['email'];
}
else{
$email = '';
}
//插入数据库
try {
$dbName = "mysql:host=XXXX;dbname=XXXX";
$dbUser = "XXXX";
$dbPassword = "XXXX";
$conn = new PDO($dbName, $dbUser, $dbPassword);
if ($conn) {
$sql = "insert into pujiang(name,company,mobile,email) values('$name','$company','$mobile','$email')";
if( $conn ->query($sql) == TRUE){
echo 'insert OK!';
}
}
$conn = NULL;
} catch (PDOException $e) {
$content = iconv("UTF-8", "gbk", $e->getMessage());
echo $content;
}
}
else{
echo 'data format error!';
}
?>
把以上文件保存为PHP格式,放在web根目录下执行。
如果设置了虚拟主机,则像配置其他虚拟主机一样配置即可。(目录下只有这一个文件)