为存储在数据库中的HTML表单创建insert语句时。我是否必须创建多个插入脚本来处理多个表单,或者是否有更好的方法来使用一个脚本处理数据。
<?php
include 'includes/mysqli_connect.php';
$title = $_POST ['title'];
$fname =$_POST ['first_name' ];
$lname =$_POST ['last_name'];
$c_status = $_POST ['customer_status'];
$addr1 = $_POST ['address_line1'];
$addr2 = $_POST ['address_line2'];
$town = $_POST ['address_town'];
$county = $_POST ['address_county'];
$post_code = $_POST ['post_code'];
$mob_tel = $_POST ['mobile_tel'];
$hom_tel = $_POST ['home_tel'];
$email = $_POST ['email'];
$date_join = $_POST ['date_joined'];
$q = "INSERT INTO customer (title, first_name, last_name, customer_status, address_line1, address_line2, address_town,
address_county, post_code, mobile_tel, home_tel, email, date_joined) VALUES ('$title', '$fname', '$lname', '$c_status',
'$addr1', '$addr2', '$town', '$county', '$post_code', '$mob_tel', '$hom_tel', '$email', '$date_join')";
$r = @mysqli_query ($dbc,$q); // NB result $r = true if insert worked.
if ($r) echo "<p>A new customer has been added to the database</p>\n";
else { // There's been an error
$sqlerr = mysqli_error($dbc); // Retrieves error message
echo '<p class="error">Error - failed to insert record. <br />'.
'Error reported by MySQL is '.$sqlerr.'<br />Query = '.$q."</p>\n";
}
?>
我的查询是使用相同脚本处理多个表单的更好方法。是否只是为每个表单重复插入语句的情况,或者我应该为每个表单创建一个新的脚本。