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);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改