如何在wampserver的phpadmin中将这个数据数组插入mysql

v1l68za4  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(366)
$register_data2 = array(
    'first_name'        => $_POST["fname"][$j],
    'last_name'         => $_POST["lname"][$j],
    'passport'          => $_POST["passport"][$j],
    'visa'              => $_POST["visa"][$j],
    'address1'          => $_POST["address1"][$j],
    'address2'          => $_POST["address2"][$j],
    'email'             => $_POST["email"][$j],
    'contact'           => $_POST["contact"][$j],
    'pin'               => $_POST["pin"][$j],
    'leaving_from'      => $pieces[0],
    'going_to'          => $pieces[2],
    'depart_date'       => $pieces[7],
    'depart_time'       => $pieces[12],
    'arrival_time'      => $pieces[17],
    'grand_fare'        => $pieces[22],
    'returning_from'    => $pieces1[0],
    'returning_to'      => $pieces1[2],
    'returning_date'    => $pieces1[7],
    'returning_time'    => $pieces1[11],
    'reaching_time'     => $pieces1[16],
    'fare'              => $pieces1[21]
    );

如何在wampserver的phpadmin中将这个数据数组插入mysql数据库请帮助。

6za6bjd0

6za6bjd01#

我想这个例子应该按照你的数组来工作。

$register_data2 = array(
    'first_name'        => 1,
    'last_name'         => 2,
    'passport'          => 3,
    'visa'              => 4,
    'address1'          => 5,
    'address2'          => 6,
    'email'             => 7,
    'contact'           => 8,
    'pin'               => 9,
    'leaving_from'      => 1
    );

$query = "INSERT INTO TABLE_NAME SET ";

foreach($register_data2 as $column_name => $value){
   $query .= $column_name . " = '" . $value . "' , ";
}

echo $final_query = rtrim($query,", ");

相关问题