Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 错误:使用PHP在Android应用程序中连接MySQL数据库_Java_Php_Android_Mysql - Fatal编程技术网

Java 错误:使用PHP在Android应用程序中连接MySQL数据库

Java 错误:使用PHP在Android应用程序中连接MySQL数据库,java,php,android,mysql,Java,Php,Android,Mysql,我一直在尝试使用android应用程序中的php连接MySQL数据库。我不知道下面的代码有什么问题。谁能告诉我需要做什么 这是我的密码: sql查询 CREATE TABLE user_detail ( name varchar(30), age int(2), email varchar(30) ); 2.getdata.phpclass <?php $con=mysql_connect('localhost','root',''); mysql_select_db('hellod

我一直在尝试使用android应用程序中的php连接MySQL数据库。我不知道下面的代码有什么问题。谁能告诉我需要做什么

这是我的密码:

  • sql查询

    CREATE TABLE user_detail
    (
    name varchar(30),
    age int(2),
    email varchar(30)
    );
    
  • 2.getdata.phpclass

    <?php
    
    $con=mysql_connect('localhost','root','');
    mysql_select_db('hellodb',$con); 
    
    $name = $_POST['name'];
    $age = $_POST['age'];
    $email = $_POST['email'];
    
    $mysql_query("insert into user_detail(name,age,email) values('{$name}','{$age}','{$email}')");
    
    ?>
    
    <EditText
        android:id="@+id/etname"
        android:hint="Enter Your Name"
        android:textAlignment="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    
    <EditText
        android:id="@+id/etage"
        android:hint="Enter Your Age"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/etemail"
        android:hint="Enter Your Email"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    
    <Button
        android:layout_width="169dp"
        android:layout_height="wrap_content"
        android:text="Insert"
        android:id="@+id/ibutton"
        android:layout_gravity="center_horizontal" />
    
    查找有关PDO的更多信息


    从$mysql_queryAdd错误报告中删除$mysql\u打开
    yes后立即将错误报告到文件顶部如果您使用的是最新的php版本,则不应使用mysql函数。让我发布答案。android部分与这个问题无关。
    
    <EditText
        android:id="@+id/etname"
        android:hint="Enter Your Name"
        android:textAlignment="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    
    <EditText
        android:id="@+id/etage"
        android:hint="Enter Your Age"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/etemail"
        android:hint="Enter Your Email"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    
    <Button
        android:layout_width="169dp"
        android:layout_height="wrap_content"
        android:text="Insert"
        android:id="@+id/ibutton"
        android:layout_gravity="center_horizontal" />
    
    $dbtype     = "mysql";
    $dbhost     = "localhost";
    $dbname     = "hellodb";
    $dbuser     = "root";
    $dbpass     = "";
    
    $name  = $_POST['name'];
    $age   = $_POST['age'];
    $email = $_POST['email'];
    
    // database connection
    $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
    
    $sql = "INSERT INTO user_detail(name,age,email) VALUES (:name,:age,:email)";
    
    $q = $conn->prepare($sql);
    
    $q->execute(array(':name'=>$name,
                      ':age'=>$age,
                      ':email'=>$email));