-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unnecessary files and update lab assignment links
- Loading branch information
Showing
36 changed files
with
319 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
5th_Semester/Web_Technology/Lab4 (PHP)/6_form_retrieval.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
5th_Semester/Web_Technology/Lab4 (PHP)/7_enhancement_of_6.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]; | ||
} | ||
?> |
12 changes: 12 additions & 0 deletions
12
5th_Semester/Web_Technology/Lab4 (PHP)/Connecting_to_database/1_connection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
?> |
39 changes: 39 additions & 0 deletions
39
5th_Semester/Web_Technology/Lab4 (PHP)/Connecting_to_database/2_insert.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
18 changes: 18 additions & 0 deletions
18
5th_Semester/Web_Technology/Lab4 (PHP)/Connecting_to_database/3_retrieve.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
?> |
40 changes: 40 additions & 0 deletions
40
5th_Semester/Web_Technology/Lab4 (PHP)/Connecting_to_database/4_edit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
14 changes: 14 additions & 0 deletions
14
5th_Semester/Web_Technology/Lab4 (PHP)/Connecting_to_database/5_delete.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
?> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters