sql >> Database >  >> RDS >> Mysql

Veldwaarden behouden na indienen

Ja, je zou in dit geval (een soort van) een flash-sessie kunnen implementeren:

Dus bij indiening:

<?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";

}
?>

En voeg dan dit ook toe op de formulierpagina:

<?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>

Kanttekening:ik raad aan om voorbereide verklaringen te gebruiken.

<?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";

}
?>


  1. sessies gebruiken in databasebewerkingen

  2. Dynamische SQL - Controleer syntaxis en semantiek

  3. Ophalen en weergeven van BLOB-afbeeldingen uit de Mysql-database met Tkinter

  4. Fout bij ophalen uit de volgorde die tabel retourneert van Oracle-functie in C # waarbij functie dblink naar SQL Server gebruikt