function verif_update($str) { if ($str == "name") { echo "New name ? \n> "; $up = verif_name(); } else { if ($str == "age") { echo "New age ? \n> "; $up = verif_age(); } else { if ($str == "email") { echo "New email ? \n> "; $up = verif_mail(); } else { if ($str == "phone") { echo "New age ? \n> "; $up = verif_phone(); } else { echo "cannot update\n"; return 0; } } } } return $up; }
function add_student($argv) { if (!isset($argv[2])) { echo "Pas assez d'argument\n"; return 0; } if (preg_match_all("/[a-z]{1,6}_[a-z0-9]/", $argv[2], $array)) { echo "Nom ?\n> "; $name = verif_name(); echo "Age ?\n> "; $age = verif_age(); echo "Email ?\n> "; $mail = verif_mail(); echo "Numéro de téléphone ?\n> "; $phone = verif_phone(); echo "Utilisateur enregistré \n"; $connect = new MongoClient(); $db = $connect->db_etna; $collection = $db->students; $document = array("login" => $argv[2], "name" => $name, "age" => $age, "email" => $mail, "phone" => $phone); $collection->insert($document); } else { echo "Login incorrect !\n"; } }