dragonpeng200811111 2017-02-25 09:46
浏览 29
已采纳

将表单导出数据加载到php数组中

I am trying this way but it doesnt work:

  $sql = "INSERT INTO customers (userName,password,email,tel,companyName,idNumber,streetAddress,zipCode,city,coAdress) VALUES ($_POST['userName'],$_POST['password'],$_POST['email'] ,$_POST['tel'],$_POST['companyName'],$_POST['idNumber'],$_POST['streetAddress'],$_POST['zipCode'],$_POST['city'],$_POST['coAdress']);

 if ($conn->query($sql) === TRUE) {
     echo "New record created successfully";
 } else {
     echo "Error: " . $sql . "<br>" . $conn->error;
 }

I have now finally been able to see the output of:

Form.php

<form class="form" method="post" id="compReg" action="process.php">
<input type="submit">

connect.php

 <?php
 print_r($_POST);?>

The output when fields are exported is this:

Array ( [name] => Hedda Calhoun [email] => pinecozy@gmail.com [tel] => +539-48-6021045 [password] => Pa$$w0rd! [cpassword] => Pa$$w0rd! [companyName] => Underwood and Christian LLC [personalNumber] => 119 [streetAdress] => Enim officia et at numquam est voluptas placeat nulla et corporis dolorem in eum modi ratione incidunt nihil [zipCode] => 58366 [city] => Unde quis vel quam eiusmod rerum quaerat voluptatum labore provident [coAdress] => Nostrud culpa sint quis ab est in obcaecati illo consequat Ducimus nulla )

How can I load these into a php array so I can acces the and export them to the database?

  • 写回答

2条回答 默认 最新

  • douqufan9148 2017-02-25 10:37
    关注

    You can access using Key

    $_POST['name']
    $_POST['email']
    $_POST['tel']
    

    For inserting records in database

    <?php
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "myDB";
    
    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Check connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    
    $sql = "INSERT INTO USERS (name, email, tel)
    VALUES ('".$_POST['name']."', '".$_POST['email']."', '".$_POST['tel']."')";
    
    if (mysqli_query($conn, $sql)) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }
    
    mysqli_close($conn);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • duanbanfei2875 2017-02-25 10:11
    关注

    By default $_POST is an associative array of variables passed through the post method. So you can access the values of this array itself as

    $_POST['your_input_fieldname']
    

    However if you want to bind a new array you can fire a foreach loop on $_POST as

    $newarr = array();
    foreach($_POST as $key=>$val)
    {
        $newarr[$key] = $val;
    }
    print_r($newarr);
    
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab+波形匹配算法
  • ¥15 转录组分析做聚类树图时癌旁组被分到了癌组
  • ¥15 大一Python字典
  • ¥15 multisim电路设计(相关搜索:设计报告)
  • ¥15 PC-lint Plus
  • ¥15 gpl24676注释
  • ¥15 php5.3内存泄露
  • ¥15 DigSilent如何复制复合模型到自己案例?
  • ¥15 求日版华为b610s-77a 官方公版固件,有偿
  • ¥15 关于#java#的问题,请各位专家解答!(相关搜索:java程序)