我有一个表单提交后提交到MySQL数据库,它工作正常。我有一个名为“customer_id”这个值,我想设置三个字段的组合,其中一个是“first_name”,第二个是“last_name”,第三个是“id”,例如customer_id =(first_name + last_name + id)值(johndoe1)。 Id字段不在表单中,这只在具有自动增量的数据库中。以上述方式设置costumer_id后,我想在提交表单后显示costumer_id值和成功消息。哈哈我想要但不知道如何。 我该怎么做。MYSQL数据库插入并在网页中显示数据
PHP代码
error_reporting(-1);
//Establishing Connection with Server
$connection = mysqli_connect("host", "user", "pass","db");
// Check connection
if (!$connection) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
if(isset($_POST['was'])){
//Fetching variables of the form which travels in URL
$first_name = mysqli_real_escape_string($connection, $_POST['first_name']);
$last_name = mysqli_real_escape_string($connection, $_POST['last_name']);
$pendant_name = mysqli_real_escape_string($connection, $_POST['pendant_name']);
$desired_language = mysqli_real_escape_string($connection, $_POST['desired_language']);
$email = mysqli_real_escape_string($connection, $_POST['email']);
$phone = mysqli_real_escape_string($connection, $_POST['phone']);
$address = mysqli_real_escape_string($connection, $_POST['address']);
$country = mysqli_real_escape_string($connection, $_POST['country']);
$state = mysqli_real_escape_string($connection, $_POST['state']);
$city = mysqli_real_escape_string($connection, $_POST['city']);
$zip = mysqli_real_escape_string($connection, $_POST['zip']);
$mobile = mysqli_real_escape_string($connection, $_POST['mobile']);
$sql = mysqli_query($connection, "INSERT into order_request(customer_id, first_name, last_name, pendant_name, desired_language, email, phone, mobile, address, country, state, city, zip) VALUES ('$first_name$last_name', '$first_name', '$last_name', '$pendant_name', '$desired_language', '$email','$phone', '$mobile', '$address', '$country', '$state', '$city', '$zip')");
echo '
';
echo 'data successfully submitted!';
echo '
';
echo '
';
echo '
';
echo "
var c = document.querySelector('.close-btn');
var e = document.querySelector('.success-msg');
e.style.height = document.clientHeight+'px';
c.onclick = function(){
e.style.display = 'none';
}
";
}
mysqli_close($connection);
?>
2016-08-14
waseem
+0
所以,你要看到最后插入的ID? (自动增量列的最后一个数字/编号?) –
+0
我想为每位客户编制一个唯一的客户编号 –