What are some common PHP scripts used for creating member profiles with login capabilities?
To create member profiles with login capabilities in PHP, you can use scripts that handle user registration, login authentication, and profile management. Common PHP scripts for this purpose include creating a registration form to collect user information, storing user data in a database, implementing user authentication using sessions, and allowing users to update their profiles.
// Sample PHP script for user registration and login
// Database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$conn = new mysqli($servername, $username, $password, $dbname);
// User registration
if(isset($_POST['register'])){
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "INSERT INTO users (username, password) VALUES ('$username', '$password')";
$conn->query($sql);
}
// User login
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = $conn->query($sql);
if($result->num_rows > 0){
session_start();
$_SESSION['username'] = $username;
header('Location: profile.php');
} else {
echo "Invalid username or password";
}
}
Related Questions
- How can you effectively debug SQL queries in PHP to troubleshoot issues with data retrieval?
- What are the advantages of using phpMailer over PEAR's Mail package for sending emails in PHP?
- What resources or functions within PHP can be utilized to effectively handle file operations like reading, writing, and modifying data?