
PHP free projects idea’s
PHP is a popular programming language that is commonly used for web development. It is known for its simplicity and versatility, and it can be used to create dynamic and interactive websites. Whether you are a beginner or an experienced developer, PHP is an excellent choice for creating a wide range of projects, from simple web pages to complex web applications. Here a some PHP free projects. Before you have to install PHP environment click here for guide.
List of PHP Projects:
Simple Calculator in PHP:
Copy code
<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$operation = $_POST['operation'];
if ($operation == 'add') {
$result = $num1 + $num2;
} elseif ($operation == 'subtract') {
$result = $num1 - $num2;
} elseif ($operation == 'multiply') {
$result = $num1 * $num2;
} elseif ($operation == 'divide') {
$result = $num1 / $num2;
}
echo "Result: $result";
?>
This form will display two input fields and a dropdown menu for selecting the operation. When the form is submitted, it will send the three form values (num1, num2, and operation) to the calculator.php script, which will then perform the specified operation and print the result.
Copy code
<form method="post" action="calculator.php">
<input type="text" name="num1" />
<select name="operation">
<option value="add">+</option>
<option value="subtract">-</option>
<option value="multiply">*</option>
<option value="divide">/</option>
</select>
<input type="text" name="num2" />
<input type="submit" value="Calculate" />
</form>
Send a message with our easy-to-use contact form.
To create this project, you will need to do the following:
- Create an HTML form with input fields for the user’s name, email address, and message. You can also include a submit button to send the form.
- Add some PHP code to the top of the page to process the form data and send the message. You can use the $_POST variable to retrieve the form values and the mail() function to send the message.
Here is an example of the HTML and PHP code for this project:
<form method="post">
<label>Name:</label>
<input type="text" name="name" />
<br />
<label>Email:</label>
<input type="email" name="email" />
<br />
<label>Message:</label>
<textarea name="message"></textarea>
<br />
<input type="submit" value="Send" />
</form>
<?php
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "recipient@example.com";
$subject = "Message from $name";
$headers = "From: $email\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
mail($to, $subject, $message, $headers);
echo "Your message has been sent!";
}
?>
<!-- Register form -->
<form method="post">
<label>Username:</label>
<input type="text" name="username" />
<br />
<label>Password:</label>
<input type="password" name="password" />
<br />
<label>Email:</label>
<input type="email" name="email" />
<input type="submit" value="Register" />
</form>
<?php
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$password_hash = password_hash($password, PASSWORD_DEFAULT);
// Connect to the database and insert the user data
// Replace "hostname", "username", "password", and "database" with your own credentials
$conn = new mysqli("hostname", "username", "password", "database");
$stmt = $conn->prepare("INSERT INTO users (username, password, email) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $username, $password_hash, $email);
$stmt->execute();
$stmt->close();
$conn->close();
echo "Your account has been created!";
}
?>
<!-- Login form -->
<form method="post">
<label>Username:</label>
<input type="text" name="username" />
<br />
<label>Password:</label>
<input type="password" name="password" />
<br />
<input type="submit" value="Log in" />
</form>
<?php
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
// Connect to the database and retrieve the user data
// Replace "hostname", "username", "password", and "database" with your own credentials
$conn = new mysqli("hostname", "username", "password", "database");
$stmt = $conn->prepare("SELECT password FROM users WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($password_hash);
$stmt->fetch();
$stmt->close();
$conn->close();
// Check if the password is correct
if (password_verify($password, $password_hash)) {
session_start();
$_SESSION['username'] = $username;
echo "You are now logged in!";
} else {
echo "Invalid username or password";
}
}
?>
Do subscribe on YouTube for the tutorials on PHP free projects and from more code go to my GitHub profile.