I have such a question, I created a form for registration and then to enter. So, for registration, you need to enter your mail password, phone number and surname. Here is the code:

<?php include_once('dbcon.php'); $error = false; if(isset($_POST['buttonreg'])){ $name = $_POST['name']; $name = strip_tags($name); $name = htmlspecialchars($name); $tel = $_POST['tel']; $tel = strip_tags($tel); $tel = htmlspecialchars($tel); $email = $_POST['email']; $email = strip_tags($email); $email = htmlspecialchars($email); $password = $_POST['password']; $password = strip_tags($password); $password = htmlspecialchars($password); //encrypt password with md5 $password = md5($password); //insert data if no error if(!$error){ $sql = "insert into users(name,tel, email ,password) values('$name','$tel', '$email', '$password')"; if(mysqli_query($conn, $sql)){ header('location: index.php'); }else{ echo 'Error '.mysqli_error($conn); } } } ?> 

And you can enter using mail and password:

 <?php session_start(); include_once('dbcon.php'); $error = false; if(isset($_POST['buttonlogin'])){ $email = trim($_POST['email']); $email = htmlspecialchars(strip_tags($email)); $password = trim($_POST['password']); $password = htmlspecialchars(strip_tags($password)); if(!$error){ $password = md5($password); $sql = "select * from users where email='$email' "; $result = mysqli_query($conn, $sql); $count = mysqli_num_rows($result); $row = mysqli_fetch_assoc($result); if($count==1 && $row['password'] == $password){ $_SESSION['email'] = $row['email']; header('location: home.php'); }else{ $errorMsg = '<center><p>Doğru olmayan email/şifrə daxil etmisiniz</p></center>'; } } } ?> 

I want to, after someone has logged in there, the first name is displayed there, the phone number for example, etc. help me be blogged!

  • What is in the file home.php ? - Yaroslav Molchan
  • The same page only has the echo $ _SESSION ['email'] command. How would you say hello when someone came in with the help of someone - SportsTubers

1 answer 1

It would be better if you showed an example of home.php code, and so instead of outputting yours, you can try to sample the database by email that you have in the session and take information from the database on it and output everything you need, for example like this:

 $sql = 'select * from users where email="'.$_SESSION['email'].'"'; $result = mysqli_query($conn, $sql); $user = mysqli_fetch_assoc($result); echo 'Здраствуйте '. $user['name'] .'. Ваш телефон '. $user['name'] .', ваша почта: '.$user['email']; 

Just keep in mind that this is not a safe approach, we directly insert the data into the sql query, they need to be filtered.

  • Blogadar you! I will try it and answer you! - SportsTubers
  • You really helped me a blogger no words! What can I do for you? Just Tell Me - SportsTubers