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条)

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏