[英]How Do I Customize My Own Status Messages for PHP? [on hold]
当我在其他网站上创建新帐户时,我会看到一个警报样式对话框,告诉我我的信息是否已成功发送,同时停留在我创建帐户的同一网页上。 该对话框有一个指向 select 的“确定”按钮,用于关闭对话框并将 HTML 表单重置为空字段。
我想在我的网站上这样做。 目前,我有一个 HTML 表单,它捕获 email 地址。 When I click SUBMIT, the PHP file takes the email address, verifies the email, uploads it into mysql, then opens a new browser window echoing the status of the PHP processes that were just run.
我不希望 PHP 打开浏览器 window 显示进程状态。 我只是想在表单所在的同一网页中打开一个对话框,说明 email 地址已成功上传,或未成功上传,或者 email 地址无效。 无论哪种方式,都不会打开第二个 window 和一个警报样式对话框,该对话框显示状态,带有“确定”按钮以关闭对话框,并使用空白字段重置表单。
我花了 2 天时间在互联网上搜索各种措辞,并在这里探索了图书馆,但我找不到这方面的帮助。
我认为我的问题有一个标准解决方案,因为这是大多数网站在开设帐户时的工作方式。 我可能在搜索时使用了不正确的术语。 这是我的 php 代码,用于将 HTML 表单数据上传到 mysql:
<?php
//MySQL/MariaDB connection block with the server location (localhost), the database name, and the database username and password.
$email_a = $_POST['emailDesktop'];
$email_b = $_POST['emailVerifyDesktop'];
if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
echo "Email address '$email_a' is considered valid.\n";
}
if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
echo "Email address '$email_b' is considered valid.\n";
} else {
echo "Email address '$email_b' is considered invalid.\n";
}
$hostname = "xxxxxxxxxxxxxx";
$username = "xxxxxxxxxxxxxx";
$password = "xxxxxxxxxxxxxx";
$db = "xxxxxxxxxxxxxx";
//Then we add a section to connect to the database, and give an error if the connection fails:
$dbconnect=mysqli_connect($hostname,$username,$password,$db);
if ($dbconnect->connect_error) {
die("Database connection failed:" .$dbconnect->connect_error);
}
//Next, we "translate" the data from the HTML form into PHP variables:
if(isset($_POST['submit'])) {
$emailDesktop=$_POST['emailDesktop'];
//Then insert this information into the database:
$query = "INSERT INTO members (emailDesktop)
VALUES ('$emailDesktop')";
//Add a nested if statement which will give an error message if the process fails, or thank the user for their review if it succeeds:
if (!mysqli_query($dbconnect, $query)) {
echo 'An error occurred when submitting.';
} else {
echo 'Upload successful.';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.