PHP Ut2 QB
PHP Ut2 QB
1] <?php
class emp
private $fname;
private $lname;
$this->fname=$fname;
$this->lname=$lname;
$S = new emp("raj","patil");
$S->showname();
?>
Output :
2] multipleform.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<label for="name">Name:</label>
<br>
<label for="email">Email:</label>
<br>
</form>
<label for="message">Message:</label>
<br>
</form>
</body>
</html>
Multipleform.php :
<?php
// Form 1
if(isset($_POST['form1_submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
// Form 2
if(isset($_POST['form2_submit'])) {
$message = $_POST['message'];
echo "<p><b>Thank you for submitting Form 2, your message is: $message</b></p>";
?>
Output :
3] multiplebutton.html:
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
</head>
<body>
</body>
</html>
Multiplebutton.php:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
if(isset($_POST['add'])){
elseif(isset($_POST['sub'])){
?>
Output :
4] validation.html:
<html>
<head>
<title>email validation</title>
</head>
<body>
</form>
</body>
</html>
Validation.php :
<?php
if($_SERVER['REQUEST_METHOD']==='POST'){
if($_SERVER ['REQUEST_METHOD']==='POST'){
if(empty($_POST['name']))
if(is_numeric($_POST['number']))
$pattern="/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/";
if(preg_match($pattern,$_POST['email']))
echo "sucessfull<br>";
else{
?>
Output:
5] <?php
// Create a cookie
$cookie_name = "user";
$cookie_value = "admin123@";
$cookie_expiration = time() + (86400 * 30); // 30 days
setcookie($cookie_name, $cookie_value, $cookie_expiration, "/"); // The last parameter "/" means that the
cookie is available in the entire website
echo "cookie name :$cookie_name <br>";
echo "cookie value :$cookie_value <br>";
// Modify a cookie
if(isset($_COOKIE[$cookie_name])){
$cookie_value = "admin456@";
setcookie($cookie_name, $cookie_value, $cookie_expiration, "/");
echo "modifying cookie : <br> ";
echo "cookie name : $cookie_name <br>";
echo "cookie value : $cookie_value <br>";
}
// Delete a cookie
if(isset($_COOKIE[$cookie_name])){
setcookie($cookie_name, "", time() - 3600, "/");
echo "The cookie " . $cookie_name . " has been deleted.";
}
?>
Output :
6] <?php
// Start the session
session_start();
7] updating records:
<?php
// Connecting to the Database
$servername = "localhost";
$username = "root";
$password = "abc6263@";
$database = "student";
// Create a connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Die if connection was not successful
if (!$conn){
die("Sorry we failed to connect: ". mysqli_connect_error());
}
else{
echo "Connection was successful<br>";
}
8] fetch data :
<?php
$host='localhost';
$user='root';
$pass='abc6263@';
$dbname='employee_db';
$conn=mysqli_connect($host,$user,$pass,$dbname);
if(!$conn){
die('could not connect:'.mysqli_connect_error());
}
echo "connected sucessfully..";
$sql='select *from employee';
$retval=mysqli_query($conn,$sql);
if(mysqli_num_rows($retval) > 0){
while($row=mysqli_fetch_assoc($retval)){
echo "name:{$row['NAME']}<BR>";
echo "age:{$row['AGE']}<BR>";
echo "salary:{$row['SALARY']}<BR>";
echo"-------------------------<br>";
}
}
else
{
echo "0 results";
}
mysqli_close($conn);
?>
OUTPUT :
<?php
// Define the database connection details
$servername = "localhost"; // Replace with your database server name
$username = "root"; // Replace with your MySQL username
$password = "abc6263@"; // Replace with your MySQL password
$dbname = "student"; // Replace with your MySQL database name
Output :
10] delete records:
<?php
// MySQL database credentials
$host = 'localhost';
$username = 'root';
$password = 'abc6263@';
$dbname = 'student';