将数据插入mysql数据库

时间:2015-07-21 11:26:37

标签: php android mysql

我想将数据从android插入mysql数据库 这是PHP代码     

$connect = mysqli_connect("localhost","root","123423","jacccccttt");

if(mysqli_connect_errno($connect))
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
    echo "success";
}

$name = isset($_POST['name']) ? $_POST['name'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';

$query = mysqli_query($connect, "insert into users (name, message) values ('$name' ,'$message') ");

mysqli_close($connect);
?>

我希望android项目将名称和消息发布到我的php文件中。

1 个答案:

答案 0 :(得分:0)

    $connect = mysqli_connect("localhost","root","","DB_Name");

    if(mysqli_connect_errno($connect))
     {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
     else
     {
       echo "success";
      }


   if(isset($_POST['submit']))
   {
    $name = ($_POST['name']);
    $message = ($_POST['message']);

    $query = mysqli_query($connect, "insert into users (name, message) values ('$name' ,'$message') ");
}
   mysqli_close($connect);
?>