使用json将数据插入数据库

时间:2017-10-10 06:32:14

标签: php mysql json

尝试使用json插入数据。执行代码并且每个案例都会插入一个空白行,而不是将特定的给定值插入到表中..帮我纠正这个..代码如下所示。

   <?php
   header('Content-Type: application/json');
   include('dbconnect.php');
   $json = isset($_POST['submit']) ? $_POST['submit'] : "";
   $new = json_decode($json, true);
   $sql="INSERT INTO emp(name,address,vicechancellor)
   values
   ('".$new['name']."','".$new['address']."','".$new['vicechancellor']."')";
   $res = mysqli_query($con,$sql); 
   if($res)
   {
      echo "created ";
   } 
   else
   {
      echo "Error: " . $sql . "<br>" . mysqli_error($con);
   }    
   ?>

0 个答案:

没有答案