Ja, Sie könnten in diesem Fall (irgendeine Art) eine Flash-Sitzung implementieren:
Also beim Absenden:
<?php
session_start(); // don't forget
require_once('../scripts/connect.php');
$con = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME) or die('Could not connect to database server.');
if(isset($_POST['submit'])) {
$var_Email1 = mysqli_real_escape_string($con, $_POST['field_email1']);
$var_Email2 = mysqli_real_escape_string($con, $_POST['field_email2']);
if ($var_Email1 == $var_Email2){
$sql = mysqli_query($con, "SELECT * FROM membership WHERE Email = '$var_Email1' ");
if(mysqli_num_rows($sql) > 0){
// set session
$_SESSION['email_exists'] = $var_Email1;
header('Location: the_starting_php.php');
exit;
}
}
echo "not in database";
}
?>
Und dann fügen Sie auf der Formularseite auch Folgendes hinzu:
<?php
session_start();
// check if there is
$email = '';
if(isset($_SESSION['email_exists'])) {
$email = $_SESSION['email_exists'];
unset($_SESSION['email_exists']); // unset it
echo "
<script type='text/javascript'>
alert('The email address $email already exists');
</script>
";
}
?>
<form action="register_script2.php" method="POST" name="form_register" id="form_registerID" accept-charset="UTF-8">
<aside class="field_reg_form">
<input name="field_email1" type="text" required id="field_email1ID" value="<?php echo $email; ?>" />
<br /><br />
<input name="field_email2" type="text" required id="field_email2ID" value="<?php echo $email; ?>" />
<br /><br />
<input type="submit" value="submit" id="submit" name="submit" />
</aside>
</form>
Nebenbemerkung:Ich schlage vor, vorbereitete Anweisungen zu verwenden.
<?php
session_start(); // don't forget
require_once('../scripts/connect.php');
$con = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME) or die('Could not connect to database server.');
if(isset($_POST['submit'])) {
$var_Email1 = $_POST['field_email1'];
$var_Email2 = $_POST['field_email2'];
if ($var_Email1 == $var_Email2){
$sql = 'SELECT * FROM membership WHERE Email = ?';
$select = $con->prepare($sql);
$select->bind_param('s', $var_Email1);
$select->execute();
if($select->num_rows > 0){
// set session
$_SESSION['email_exists'] = $var_Email1;
header('Location: the_starting_php.php');
exit;
}
}
echo "not in database";
}
?>