0% found this document useful (0 votes)
5 views

script programming

The document provides a series of PHP and HTML programs for various applications including string manipulation, biodata forms, search functionality with a database, file uploads using Node.js, email sending with Nodemailer, and a simple login system. Each program includes the necessary code and instructions for setting it up in a local XAMPP environment. Additionally, it covers the use of MySQL for database interactions and includes error handling for user inputs.

Uploaded by

yarudanee181513
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

script programming

The document provides a series of PHP and HTML programs for various applications including string manipulation, biodata forms, search functionality with a database, file uploads using Node.js, email sending with Nodemailer, and a simple login system. Each program includes the necessary code and instructions for setting it up in a local XAMPP environment. Additionally, it covers the use of MySQL for database interactions and includes error handling for user inputs.

Uploaded by

yarudanee181513
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Aim

Software required

Xampp

Program

1.Type the program in notepad and save it in C:\xampp\htdocs as paul1.php(all files selected)

<?php
$s="Welcome to php";
echo "the given string is".$s."<br>";
$length=strlen($s);
echo "the length of the string is".$length."<br>";
$upper=strtoupper($s);
echo "the upper case of the string is".$upper."<br>";
$lower=strtolower($s);
echo "the lower case of the string is".$lower."<br>";
$reversed=strrev($s);
echo "the reversed string is".$reversed."<br>";
$arr=str_split($s,3);
echo "Array after splitting:<br>";
print_r($arr);
echo "<br>";
$arr=array(33,11,44,16,25,89,92);
echo "The elements in the array are:<br>";
print_r($arr);
echo "<br>";
$count1=count($arr);
echo "Count of elements in the array:".$count1."<br>";
$cur=current($arr);
echo "Current element:".$cur."<br>";
$last=end($arr);
echo "Last element:".$last."<br>";
$reverse=array_reverse($arr);
echo "Reversed array:<br>";
print_r($reverse);
echo "<br>";
sort($arr);
echo "Sorted array:";
print_r($arr);

?>
Result:
Aim

Software required

Xampp

Program

1.Type the program in notepad and save it in C:\xampp\htdocs as the following names in the
heading of programs

Sandoosh.html

<!doctype html>
<html>
<head>
<title> Biodata Form</title>
</head>
<body>
<h2 align="center"; style="font-size:30px"> Biodata Form</h2>
<form action="YARU.php" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age" required min="0" max="45"><br><br>
<h3>JGLC</h3>

<label for="s1">subject1:</label>
<input type="number" id="s1" name="marks[]" required min="0" max="99"><br><br>
<label for="s2">subject2:</label>
<input type="number" id="s2" name="marks[]" required min="0" max="99"><br><br>
<label for="s3">subject3:</label>
<input type="number" id="s3" name="marks[]" required min="0" max="99"><br><br>
<label for="s4">subject4:</label>
<input type="number" id="s4" name="marks[]" required min="0" max="99"><br><br>
<label for="s5">subject5:</label>
<input type="number" id="s5" name="marks[]" required min="0" max="99"><br><br>
<input type="submit" value="submit">
</form>
<h2 align="center"; style="font-size:00px">giri deepa</h2>
</body>
</html>
YARU.php

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {

$name=$_POST["name"];
$age=$_POST["age"];
$marks=$_POST["marks"];
$total=array_sum($marks);
$average=$total/count($marks);
echo "<h2>jaga das biodata form</h2>";
echo "Name:" .$name . "<br>";
echo "Age:" . $age . "<br>";
echo "Total Marks:" . $total . "<br>";
echo "Average Marks:" . number_format($average,2) . "<br>";
}
else
{
echo "Invalid request method";
}
?>
Result:
Aim

Software required

Xampp

Mysql

Program

1.Type the program in notepad and save it in C:\xampp\htdocs as the following names in the
heading of programs

Search.html

<html>
<body>

<form action="phpSearch.php" method="post">


Search <input type="text" name="search"><br>
<input type ="submit">
</form>

</body>
</html>

phpSearch.php

<?php

$search = $_POST['search'];

$servername = "localhost";
$username = "root";
$password = "";
$db = "college";

$conn = new mysqli($servername, $username, $password, $db);

if ($conn->connect_error){
die("Connection failed: ". $conn->connect_error);
}
$sql = "select * from student where regno like '%$search%'";
$result = $conn->query($sql);

if ($result->num_rows > 0){


while($row = $result->fetch_assoc() ){
echo "student name=".$row["NAME"]." <br>Tamil ".$row["M1"]."<br>English ".
$row["M2"]."<br>Maths ".$row["M3"]." <br>Science ".$row["M4"]."<br>Social ".
$row["M5"]."<br>";
}
} else {
echo "0 records";
}

$conn->close();

?>
Result:
Ex5

Aim

Program

<!doctype html>
<html lang="en">
<head>
<meta name="viewport"content="width=device-width,initial-scale=1.0">
<title>Disable Right Click</title>
<script src="jquery-1.7.1.js"></script>
<script>
$(document).ready(function()
{
$(document).on("contextmenu",function(e)
{
e.preventDefault();
alert("right-click is disabled on this webpage.");
});
});
</script>
</head>
<body>
<h1>right click disabled example</h1>
<p>try right clicking anywhere on this page!</p>
</body>
</html>
Ex7

Aim

Program

server.js

const express = require('express')


const multer = require('multer');
const upload = multer({ dest: 'uploads/' })

const app = express()


const port = 3000

app.use(express.static('public'));

app.get('/', (req, res) => {


res.sendFile(__dirname + '/index.html');
});

app.post('/profile', upload.single('avatar'), function (req, res, next) {


// req.file is the `avatar` file
// req.body will hold the text fields, if there were any
try {
// req.file is the `fileUpload` file
// req.body will hold the text fields, if there were any

// handle success
return res.status(200).json({ message: 'File uploaded successfully!' });
} catch (error) {
// handle error
return res.status(400).json({ message: error.message });
}
});

app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})

package.json
{
"name": "nodejs-multer",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC"
}

index.html

<h1>Multer Upload Example</h1>

<form action="/profile" method="post" enctype="multipart/form-data">


<input type="file" name="avatar" />
<input type="submit" value="Upload">
</form>
Result
Ex8

Aim

Program

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({


service: 'gmail',
auth: {
user: '[email protected]',
pass: 'tdpa beiz rlfp hxds'
}
});

var mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};

transporter.sendMail(mailOptions, function(error, info){


if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
Result
Ex4

Aim

Program

login.php

<html>
<form method="post" action="login_check.php">
<input type="text" name="user" value="username" placeholder="Username" style="font-
size:24px" required>
<input type="text" name="pass" value="password" placeholder="Password" style="font-
size:24px" required>
<button type="submit" name="Login" value="Login">LogIn </button>
</form>
</html>

connection.php

<?php
$host = "localhost";
$user = "root";
$password = '';
$db_name = "college";

$con = mysqli_connect($host, $user, $password, $db_name);


if(mysqli_connect_errno()) {
die("Failed to connect with MySQL: ". mysqli_connect_error());
}
?>

login_check.php

<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
include('connection.php');
$username = $_POST['user'];
$password = $_POST['pass'];

//to prevent from mysqli injection


$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysqli_real_escape_string($con, $username);
$password = mysqli_real_escape_string($con, $password);

$sql = "select *from USERS where username = '$username' and password =


'$password'";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$username=$row['username' ];
$count = mysqli_num_rows($result);

if($count == 1){
//echo "<h1><center> Login successful </center></h1>";
//$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
//$username=$row['username' ];
$_SESSION['username']=$username;
header("Location: wel.php");
exit;
}
else{
//echo "<h1> Login failed. Invalid username or password.</h1>";
session_destroy();
header("Location: login.php");
exit;
}
}
?>

wel.php

<?php
session_start();
//$username=$_SESSION['username'];
//echo $username;
?>
<ul>
<li><a href='#'>Welcome <?php echo $_SESSION['username']; ?>

You might also like