Skip to content

Commit

Permalink
Remove unnecessary files and update lab assignment links
Browse files Browse the repository at this point in the history
  • Loading branch information
sthsuyash committed Jan 13, 2024
1 parent 833a967 commit b1e5503
Show file tree
Hide file tree
Showing 36 changed files with 319 additions and 2 deletions.
66 changes: 66 additions & 0 deletions 5th_Semester/Web_Technology/Lab4 (PHP)/10_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>

<head>
<title>PHP Form</title>
</head>

<body>
<h2>PHP Form Example</h2>

<?php
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve and display the values
$name = $_POST["name"];
$email = $_POST["email"];
$gender = $_POST["gender"];
$interests = isset($_POST["interests"]) ? $_POST["interests"] : [];

echo "<h3>Form Submission Results</h3>";
echo "Name: $name<br/>";
echo "Email: $email<br/>";
echo "Gender: $gender<br/>";

if (!empty($interests)) {
echo "Interests: " . implode(", ", $interests) . "<br/>";
} else {
echo "No interests selected.<br/>";
}
}
?>

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<label for="name">Name:</label>
<input type="text" name="name" id="name" required>

<br>

<label for="email">Email:</label>
<input type="email" name="email" id="email" required>

<br>

<label>Gender:</label>
<input type="radio" name="gender" value="male" id="male">
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female">
<label for="female">Female</label>

<br>

<label>Interests:</label>
<input type="checkbox" name="interests[]" value="programming" id="programming">
<label for="programming">Programming</label>
<input type="checkbox" name="interests[]" value="reading" id="reading">
<label for="reading">Reading</label>
<input type="checkbox" name="interests[]" value="traveling" id="traveling">
<label for="traveling">Traveling</label>

<br>

<input type="submit" value="Submit">
</form>
</body>

</html>
14 changes: 14 additions & 0 deletions 5th_Semester/Web_Technology/Lab4 (PHP)/11_file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
$filename = "example.txt";

// Read content from file
$content = file_get_contents($filename);

// Modify content
$newContent = str_replace("old_text", "new_text", $content);

// Write updated content back to file
file_put_contents($filename, $newContent);

echo "File updated successfully";
?>
10 changes: 10 additions & 0 deletions 5th_Semester/Web_Technology/Lab4 (PHP)/2_variables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
$integerVar = 42;
$floatVar = 3.14;
$stringVar = "Hello, World!";
define("MY_CONSTANT", "This is a constant");
echo MY_CONSTANT . "<br>";
echo $integerVar . "<br>";
echo $floatVar . "<br>";
echo $stringVar;
?>
11 changes: 11 additions & 0 deletions 5th_Semester/Web_Technology/Lab4 (PHP)/3_if-else.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$number = 7;

if ($number > 0) {
echo "Positive";
} elseif ($number < 0) {
echo "Negative";
} else {
echo "Zero";
}
?>
9 changes: 9 additions & 0 deletions 5th_Semester/Web_Technology/Lab4 (PHP)/4_function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
function calculateAverage($numbers)
{
return array_sum($numbers) / count($numbers);
}

$testArray = [5, 10, 15];
echo calculateAverage($testArray);
?>
13 changes: 13 additions & 0 deletions 5th_Semester/Web_Technology/Lab4 (PHP)/5_class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
class Book
{
public $title;
public $author;
}

$book1 = new Book();
$book1->title = "The Great Gatsby";
$book1->author = "F. Scott Fitzgerald";

echo $book1->title . " by " . $book1->author;
?>
19 changes: 19 additions & 0 deletions 5th_Semester/Web_Technology/Lab4 (PHP)/6_form_retrieval.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<title>Q.6 Form retrieval</title>
</head>

<body>
<form method="post" action="#">
<input type="text" name="username" placeholder="Username">
<input type="submit" value="Submit">
</form>
</body>
</html>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
echo "Submitted username: $username";
}
?>
32 changes: 32 additions & 0 deletions 5th_Semester/Web_Technology/Lab4 (PHP)/7_enhancement_of_6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$email = $_POST["email"];
$phone = $_POST["phone"];

if (empty($username) || empty($email) || empty($phone)) {
echo "All fields are required.";
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Invalid email address.";
} elseif (!preg_match("/^(98|97)/", $phone)) {
echo "Phone number must start with 98 or 97.";
} else {
echo "Form data validated successfully!";
}
}
?>

<html>
<head>
<title>Q.7 Form validation</title>
</head>

<body>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<input type="text" name="username" placeholder="Username">
<input type="text" name="email" placeholder="Email">
<input type="text" name="phone" placeholder="Phone">
<input type="submit" value="Submit">
</form>
</body>
</html>
14 changes: 14 additions & 0 deletions 5th_Semester/Web_Technology/Lab4 (PHP)/8_button_click.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<title>Q.8 Button click</title>
</head>
<form method="post">
<input type="submit" name="submitBtn" value="Click me">
</form>
</html>

<?php
if (isset($_POST["submitBtn"])) {
echo "Button clicked!";
}
?>
7 changes: 7 additions & 0 deletions 5th_Semester/Web_Technology/Lab4 (PHP)/9_cookies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
setcookie("user_pref", "dark_mode", time() + 3600, "/");

if (isset($_COOKIE["user_pref"])) {
echo "User preference: " . $_COOKIE["user_pref"];
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "csit";

$conn = mysqli_connect($servername, $username, $password, $dbname);

if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
include "1_connection.php";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Validate and sanitize input data
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_VALIDATE_EMAIL);

// Check if data is valid
if ($name && $email) {
$sql = "INSERT INTO first_semester (name, email) VALUES ('$name', '$email')";
if (mysqli_query($conn, $sql)) {
echo "Record inserted successfully!";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
} else {
echo "Invalid data provided.";
}

mysqli_close($conn);
}
?>

<html>

<head>
<title>Form validation and database insertion</title>
</head>

<body>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<input type="text" name="name" placeholder="Name">
<input type="text" name="email" placeholder="Email">
<input type="submit" value="Submit">
</form>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
include "1_connection.php";

$sql = "SELECT * FROM first_semester";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
echo "<table border='1'><tr><th>ID</th><th>Name</th><th>Email</th><th>Update</th><th>Delete</th></tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr><td>" . $row["id"] . "</td><td>" . $row["name"] . "</td><td>" . $row["email"] . "</td><td><a href='4_edit.php?id=" . $row["id"] . "'>Update</a></td><td><a href='5_delete.php?id=" . $row["id"] . "'>Delete</a></td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}

mysqli_close($conn);
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
include "1_connection.php";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id = $_GET["id"];
// Validate and sanitize input data
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_VALIDATE_EMAIL);

// Check if data is valid
if ($name && $email) {
$sql = "UPDATE first_semester SET name='$name', email='$email' WHERE id='$id'";
if (mysqli_query($conn, $sql)) {
echo "Record inserted successfully!";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
} else {
echo "Invalid data provided.";
}

mysqli_close($conn);
}
?>

<html>

<head>
<title>Data edit</title>
</head>

<body>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<input type="text" name="name" placeholder="Name">
<input type="text" name="email" placeholder="Email">
<input type="submit" value="Submit">
</form>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
include "1_connection.php";

$id = $_GET["id"];

$sql = "DELETE FROM first_semester WHERE id='$id'";
if (mysqli_query($conn, $sql)) {
echo "Record deleted successfully!";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>
3 changes: 1 addition & 2 deletions 5th_Semester/Web_Technology/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

1. [Lab Assignment-I (HTML)](<Lab1 (HTML)/README.md>)
2. [Lab Assignment-II (CSS)](<Lab2 (CSS)/README.md>)
3. [Lab Assignment-III (JavaScript)](<Lab3 (Javascript)/README.md>)
3. [Lab Assignment-III (Javascript and XML)](<Lab3 (Javascript & XML)/README.md>)
4. [Lab Assignment-IV (PHP)](<Lab4 (PHP)/README.md>)
5. [Lab Assignment-V (Javascript and XML)](<Lab5 (Javascript & XML)/README.md>)

## [Class Codes](class_codes/README.md)

0 comments on commit b1e5503

Please sign in to comment.