Jump to content

Oasweaz

New Members
  • Posts

    6
  • Joined

  • Last visited

Oasweaz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. You are the right man for this struggle i am stuck with.. wow.. amazing.. you understood me exactly and knew what i intend to do.. Am going to try your methods and give you a feedback.. thanks a million times
  2. Wow.. this is the biggest eye opener have ever seen.. you took your time to write all these.. wow.. amazing.. the theory makes a million Sense.. Do you mind helping out with q practical view of the aspect of... Setting a key trap that checks for a duplicate username and email already signed up in the db. Since you made it clear that I should maintain my PDO class... I might come up with other questions.. thanks a million times
  3. This refers to an sql statement as to the actual php in context of my question.. I really appreciate your input. But a little bit more help is needed as to my question..
  4. Wow that makes sense.. i really got good headsup there with me creating two separate connections.. i was trying to set a form of indirect loop of connection that runs separate for checking and updating rows. Do you mind giving a way of giving a UNIQUE constraint on the columns and trap duplicate key errors when they occur on inserting a record.
  5. the aim of this code is to make this sign up users and check if they werr already signed up before with the code below, this is what happens. on signup, it validates email and username that are already signedup which works just fine. PROBLEM: it takes(sign's up) a new username and flags an existing email(email already exists) also, it takes in(sign's up) an new email and flags an existing username(username already exist) but also signup new emails and new usernames both. i have been trying to make this work to no avail. how do i make it check first and validate first before signing up any data first code is for is signup page second code for controller <?php require "function2.php"; $errors = array(); if($_SERVER['REQUEST_METHOD'] == "POST"){ $errors = signup($_POST); if(count($errors) == 0){ header("Location:verify.php"); // echo "Account Success!!!"; // $errors[] = "Account Success!!!"; die; } } ?> <?php require "function2.php"; $errors = array(); if($_SERVER['REQUEST_METHOD'] == "POST"){ $errors = signup($_POST); if(count($errors) == 0){ header("Location:verify.php"); // echo "Account Success!!!"; // $errors[] = "Account Success!!!"; die; } } ?> <?php session_start(); function signup($data){ $errors = array(); #validate if(!preg_match('/^[a-zA-Z]+$/', $data['username'])){ $errors[] = "Alert!!!, username must be letters with no space"; } if(!filter_var($data['email'], FILTER_VALIDATE_EMAIL)){ $errors[] = "Alert!!!, enter correct email address"; } if(strlen(trim($data['password1'])) < 5){ $errors[] = "Alert!!!, password must be more than 5 characters"; } if($data['password1'] != $data['password2']){ $errors[] = "Alert!!!, password do not match"; } //save to db if(count($errors) == 0){ $arr['username'] = $data['username']; $arr['email'] = $data['email']; $arr['password1'] = $data['password1']; $arr['date'] = date("Y-m-d H-i-m"); #check email/username does exists $con = mysqli_connect("localhost", "root", "", "stervest_db" ); if(isset($_POST['insert'])){ $email = $_POST['email']; $username = $_POST['username']; $a = "select username from user2 where username = '$username' limit 1"; $aa =mysqli_query($con, $a); if(mysqli_num_rows($aa)>0){ $errors[] = "Alert!!, username already exists"; } $b = "select email from user2 where email = '$email' limit 1"; $bb =mysqli_query($con, $b); if(mysqli_num_rows($bb)>0){ $errors[] = "Alert!!, email already exists"; } } $query ="insert into user2(username, email, password1, date) values(:username, :email, :password1, :date)"; $row = signup_push($query, $arr); } //var_dump($data); return $errors; } function signup_push($query, $vars = array()){ $string ="mysql:host=localhost;dbname=stervest_db"; $conn = new PDO($string, 'root', ''); if(!$conn){ return false; } $stm = $conn->prepare($query); $check = $stm->execute($vars); if($check){ $data = $stm->fetchAll(PDO::FETCH_OBJ); if(count($data)>0){ return $data; } } return false; } function checked_verified(){ $vars = array(); $vars['email']= $data['email']; $vars['email_verified'] = $_SESSION['USER']->email_verified; $query = "select * from user2 where email = :email && email_verified = :email_verified limit 1"; $row = signup_push($query, $vars); } <?php require "function2.php"; $errors = array(); if($_SERVER['REQUEST_METHOD'] == "POST"){ $errors = signup($_POST); if(count($errors) == 0){ header("Location:verify.php"); // echo "Account Success!!!"; // $errors[] = "Account Success!!!"; die; } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.