\n"; require_once 'config.php'; // conection db $conn=require 'connect.php'; $defaultAction='add'; $defaultModCre=false; // display or not created/modified date $defaultBtnMoreLess='More'; $firstName=''; $lastName=''; $email=''; $flagAction=$defaultAction; $id=''; $modcre=$defaultModCre; $btnMoreLess=$defaultBtnMoreLess; $validEntry=true; $beforeModifiedEmail=''; ?> <?php echo $db_site_title." v".$site_version ?>

"; ?>
Add/Modify
"; try{ /* Create a prepared statement */ $stmt = $db -> prepare("SELECT email FROM ". $table .";"); /* execute the query */ $stmt -> execute(); /* fetch all results */ $res = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach($res as $row){ extract($row); //echo $email."
"; if ($emailToVerif == $email) { echo $email." found in DB
"; $returnCode=true; break; } else { //echo $email." pas trouvé
"; $returnCode=false; } } } catch (PDOExecption $e){ echo $e->getMessage(); } } else { $returnCode=false; } /*echo "Exit from DnsNameExistInDB function
";*/ return $returnCode; /* false $emailToVerif doesn't exist - true $emailToVerif exist */ } // ADD/MODIFY RECORD if (isset($_POST['send'])) { /* set var from form */ $firstName = isset($_POST['firstName']) ? trim($_POST['firstName']) : ""; //$beforeModifieFirst = isset($_POST['firstNameBeforeModified']) ? trim($_POST['firstNameBeforeModified']) : ""; $lastName = isset($_POST['lastName']) ? trim($_POST['lastName']) : ""; //$beforeModifiedLastName = isset($_POST['lastNameBeforeModified']) ? trim($_POST['lastNameBeforeModified']) : ""; $email = isset($_POST['email']) ? trim($_POST['email']) : ""; $beforeModifiedEmail = isset($_POST['emailBeforeModified']) ? trim($_POST['emailBeforeModified']) : ""; $flagAction = isset($_POST['flagAction']) ? $_POST['flagAction'] : ""; $id = isset($_POST['id']) ? $_POST['id'] : ""; /* define the format of the DNS name and ip address */ $validEmail="/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/"; /* verify correct dnsname and ip address */ //echo "Verify email
"; if ($firstName == '' || $lastName == '' || !(preg_match($validEmail, $email)) || emailExistInDB($conn, $table, $email, $beforeModifiedEmail)) { print"
One (or more) mandatory field(s) has (have) not been correctly filled in.
"; $validEntry=false; if ($firstName == ''){ print "Mandatory 'Firstname' field."; $validEntry=false; } elseif ($lastName == ''){ print "Mandatory 'Lastname' field."; $validEntry=false; } elseif ($email == ''){ print "Mandatory 'EMail' field."; $validEntry=false; } elseif (! preg_match($validEmail, $email)){ print "'".$email."' format invalid. "; $validEntry=false; } if (emailExistInDB($conn, $table, $email, $beforeModifiedEmail)){ print "'".$email."' already exist. "; $validEntry=false; } print"
"; } /* All is ok we try to add record into DB */ if ($validEntry){ /*echo "Add/Update record into DB
"; */ if ($flagAction=="add"){ $stmt = $conn -> prepare("INSERT INTO $table (firstname, lastname, email) VALUES (:firstName, :lastName, :email)"); $stmt -> bindParam(':firstName', $firstName, PDO::PARAM_STR); $stmt -> bindParam(':lastName', $lastName, PDO::PARAM_STR); $stmt -> bindParam(':email', $email, PDO::PARAM_STR); } if ($flagAction=="modify"){ //$timestamp = date("Y-m-d h:i:s"); $stmt = $conn->prepare("UPDATE $table SET firstname = :firstName, lastname = :lastName, email = :email WHERE id =:id"); $stmt -> bindParam(':id', $id, PDO::PARAM_INT); $stmt -> bindParam(':lastName', $lastName, PDO::PARAM_STR); $stmt -> bindParam(':firstName', $firstName, PDO::PARAM_STR); $stmt -> bindParam(':email', $email, PDO::PARAM_STR); } try{ /* execute the query */ $stmt -> execute(); } catch (PDOExecption $e){ //echo $e->getMessage(); //print "
". $stmt -> errorInfo()[2]. " - ".$email."
"; print "
- ".$email."
"; } } $firstName=''; $lastName=''; $email=''; $flagAction=$defaultAction; $id=''; } // DELETE IP if (isset($_POST['delete'])) { $id = isset($_POST['id']) ? $_POST['id'] : ""; try { $sql = "DELETE FROM $table WHERE id = :id"; $stmt = $conn->prepare($sql); $stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT); $stmt->execute(); /* close connection */ $db = null; } catch (PDOExecption $e){ echo $e->getMessage(); } } // MODIFIER if (isset($_POST['modify'])) { $firstName = isset($_POST['firstName']) ? $_POST['firstName'] : ""; //$beforeModifyfirstName = isset($_POST['firstName']) ? $_POST['firstName'] : ""; $lastName = isset($_POST['lastName']) ? $_POST['lastName'] : ""; //$beforeModifylastName = isset($_POST['lastName']) ? $_POST['lastName'] : ""; $email = isset($_POST['email']) ? $_POST['email'] : ""; $beforeModifiedEmail = isset($_POST['email']) ? $_POST['email'] : ""; // $description = isset($_POST['description']) ? $_POST['description'] : ""; $flagAction = isset($_POST['flagAction']) ? $_POST['flagAction'] : ""; $id = isset($_POST['id']) ? $_POST['id'] : ""; } //DISPLAY MORE if (isset($_POST['displaymore'])) { $modcre = isset($_POST['modcre']) ? $_POST['modcre'] : ""; if ($modcre){ $modcre=false; $btnMoreLess='More'; } elseif (! $modcre){ $modcre=true; $btnMoreLess='Less'; } } ?>
'. ''. ''. ''. ''. ''. ''. ''. ''; //'
Firstname Lastname EMail
  '. //' '; ?>
 

EMails list
prepare("SELECT * FROM $table ORDER BY firstname"); //$stmt = $conn -> prepare("SELECT * FROM $table where firstname like 'T%'"); /* execute the query */ $stmt -> execute(); /* fetch all results */ $res = $stmt->fetchAll(PDO::FETCH_ASSOC); echo "". "". "". "". "". ""; if ($modcre){ echo "". ""; } echo "". ""; foreach($res as $row){ extract($row); echo "". "". "". "". ""; if ($modcre){ echo "". ""; } echo ""; } echo "
IDFirstnameLastnameEMailCreatedModifiedActions
".$id."".$firstname."".$lastname."".$email."".$reg_date."".$mod_date.""; ?>
". "". "". "". "". " ". "". "
"; /* close connection */ //$db = null; } catch (PDOExecption $e){ echo $e->getMessage(); } ?>