{"id":1313,"date":"2023-06-04T01:59:30","date_gmt":"2023-06-03T20:14:30","guid":{"rendered":"https:\/\/notesvandar.com\/?p=1313"},"modified":"2023-06-04T15:17:00","modified_gmt":"2023-06-04T09:32:00","slug":"bim-iv-web-technology-practical-questions-and-answers","status":"publish","type":"post","link":"https:\/\/notesvandar.com\/bim-iv-web-technology-practical-questions-and-answers\/","title":{"rendered":"BIM IV Web Technology Practical Questions and Answers"},"content":{"rendered":"\n<p>Here are the Practical questions and answers for BIM IV Web Technology II.<\/p>\n\n\n\n<p>1. Write php code to check if a number is even or odd.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\n$number = 12; \/\/ Change the value of $number to the desired number\n\nif ($number % 2 == 0) {\n\n\u00a0\u00a0\u00a0 echo $number . \" is even.\";\n\n} else {\n\n\u00a0\u00a0\u00a0 echo $number . \" is odd.\";\n\n}\n\n?><\/pre>\n\n\n\n<p>2. Write php code to display today&#8217;s date and time in 12- Hours format.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ Get the current date and time\n$currentDateTime = date('Y-m-d h:i:s A');\n\n\/\/ Display the current date and time\necho \"Current date and time: \" . $currentDateTime;\n?>\n<\/pre>\n\n\n\n<p>3. Write php code to find the length of given string.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n$string = \"Hello, World!\"; \/\/ Change the value of $string to the desired string\n\n$length = strlen($string);\n\necho \"Length of the string: \" . $length;\n?>\n<\/pre>\n\n\n\n<p>4. Write code to create database. Apply your own assumptions.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n$servername = \"localhost\"; \/\/ Replace with your database server name\n$username = \"root\"; \/\/ Replace with your database username\n$password = \"\"; \/\/ Replace with your database password\n\n\/\/ Create a connection to the MySQL server\n$conn = new mysqli($servername, $username, $password);\n\n\/\/ Check connection\nif ($conn->connect_error) {\n    die(\"Connection failed: \" . $conn->connect_error);\n}\n\n\/\/ Create a new database\n$databaseName = \"myDatabase\"; \/\/ Replace with your desired database name\n$sql = \"CREATE DATABASE $databaseName\";\nif ($conn->query($sql) === TRUE) {\n    echo \"Database created successfully\";\n} else {\n    echo \"Error creating database: \" . $conn->error;\n}\n\n\/\/ Close the database connection\n$conn->close();\n?>\n<\/pre>\n\n\n\n<p>5. Write code to connect database and show message for connection status.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\n$host = 'your_host';\n$database = 'your_database';\n$username = 'your_user';\n$password = 'your_password';\n\n\/\/ Create a connection object\n$conn = new mysqli($host, $username, $password, $database);\n\n\/\/ Check if the connection was successful\nif ($conn->connect_error) {\n    \/\/ Display an error message if connection fails\n    die(\"Error while connecting to the database: \" . $conn->connect_error);\n}\n\n\/\/ Display a success message\necho \"Connected to the database!\";\n\n\/\/ Close the connection\n$conn->close();\n\n?><\/pre>\n\n\n\n<p>6. Create input forms for user registration. Apply server validation for the following and store in the database.<\/p>\n\n\n\n<p>&nbsp;&#8211; Name is required<\/p>\n\n\n\n<p>&nbsp;&#8211; Phone must be only digit<\/p>\n\n\n\n<p>&nbsp;&#8211; Username is required and min 5 character<\/p>\n\n\n\n<p>&nbsp;&#8211; Password is required and exactly 8 character<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n$errors = [];\n\nif ($_SERVER['REQUEST_METHOD'] === 'POST') {\n    if (empty($_POST['name'])) {\n        $errors['name'] = 'Name is required';\n    }\n\n    if (empty($_POST['phone']) || !ctype_digit($_POST['phone'])) {\n        $errors['phone'] = 'Phone must be numeric';\n    }\n\n    if (empty($_POST['username']) || strlen($_POST['username']) &lt; 5) {\n        $errors['username'] = 'Username is required and should be at least 5 characters long';\n    }\n\n    if (empty($_POST['password']) || strlen($_POST['password']) !== 8) {\n        $errors['password'] = 'Password is required and should have exactly 8 characters';\n    }\n\n    if (empty($errors)) {\n        $name = $_POST['name'];\n        $phone = $_POST['phone'];\n        $username = $_POST['username'];\n        $password = $_POST['password'];\n\n        $host = 'your_host';\n        $database = 'your_database';\n        $db_username = 'your_username';\n        $db_password = 'your_password';\n\n        $conn = new mysqli($host, $db_username, $db_password, $database);\n\n        if ($conn->connect_error) {\n            die(\"Connection failed: \" . $conn->connect_error);\n        }\n\n        $stmt = $conn->prepare(\"INSERT INTO users (name, phone, username, password) VALUES (?, ?, ?, ?)\");\n\n        $stmt->bind_param(\"ssss\", $name, $phone, $username, $password);\n\n        if ($stmt->execute()) {\n            echo \"User registration successful!\";\n        } else {\n            echo \"Error: \" . $stmt->error;\n        }\n\n        $stmt->close();\n        $conn->close();\n    }\n}\n?>\n<\/pre>\n\n\n\n<p>7. Write code to login using username and password from existing data.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nsession_start();\nrequire_once 'db_conn.php';\n\nif ($_SERVER['REQUEST_METHOD'] === 'POST') {\n    $username = $_POST['username'];\n    $password = $_POST['password'];\n\n    $stmt = $conn->prepare(\"SELECT * FROM users WHERE username = ?\");\n    $stmt->bind_param(\"s\", $username);\n    $stmt->execute();\n    $result = $stmt->get_result();\n\n    if ($result->num_rows === 1) {\n        $row = $result->fetch_assoc();\n        $storedPassword = $row['password'];\n\n        if ($password === $storedPassword) {\n            $_SESSION['username'] = $row['username'];\n            $_SESSION['name'] = $row['name'];\n            header(\"Location: dashboard.php\");\n            exit();\n        } else {\n            $loginError = \"Invalid username or password\";\n        }\n    } else {\n        $loginError = \"Invalid username or password\";\n    }\n\n    $stmt->close();\n}\n?><\/pre>\n\n\n\n<p>8. Update existing data to change password to user\u2019s phone number.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nsession_start();\nrequire_once 'db_conn.php';\n\nif ($_SERVER['REQUEST_METHOD'] === 'POST') {\n    if (isset($_SESSION['username'])) {\n        $username = $_SESSION['username'];\n\n        $stmt = $conn->prepare(\"SELECT phone FROM users WHERE username = ?\");\n        $stmt->bind_param(\"s\", $username);\n        $stmt->execute();\n        $result = $stmt->get_result();\n\n        if ($result->num_rows === 1) {\n            $row = $result->fetch_assoc();\n            $phone = $row['phone'];\n\n            $updateStmt = $conn->prepare(\"UPDATE users SET password = ? WHERE username = ?\");\n            $updateStmt->bind_param(\"ss\", $phone, $username);\n            $updateStmt->execute();\n\n            echo \"Password successfully updated to the phone number.\";\n        } else {\n            echo \"User not found.\";\n        }\n\n        $stmt->close();\n        $updateStmt->close();\n    } else {\n        echo \"User not logged in.\";\n    }\n}\n\n$conn->close();\n?>\n<\/pre>\n\n\n\n<p>9. Delete a data from database.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nrequire_once 'db_conn.php';\n\n\nif ($_SERVER['REQUEST_METHOD'] === 'POST') {\n\n    $id = $_POST['id'];\n\n    $stmt = $conn->prepare(\"DELETE FROM users WHERE id = ?\");\n    $stmt->bind_param(\"i\", $id);\n    $stmt->execute();\n\n    if ($stmt->affected_rows > 0) {\n        echo \"Record deleted successfully.\";\n    } else {\n        echo \"No records found with the given ID.\";\n    }\n\n    $stmt->close();\n}\n\n$conn->close();\n?>\n<\/pre>\n\n\n\n<p>10. Write PHP code to write &#8220;BIM 4th semester&#8221; in myfile.txt file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n$filename = \"myfile.txt\";\n\nif (!file_exists($filename)) {\n    $file = fopen($filename, \"w\");\n    fclose($file);\n}\n\n$file = fopen($filename, \"w\");\n\nif ($file) {\n    fwrite($file, \"BIM 4th semester\");\n\n    fclose($file);\n\n    echo \"Data has been written to $filename\";\n} else {\n    echo \"Unable to open the file.\";\n}\n?>\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here are the Practical questions and answers for BIM IV Web Technology II. 1. Write php code to check if a number is even or odd. 2. Write php code to display today&#8217;s date and time in 12- Hours format. 3. Write php code to find the length of given string. 4. Write code to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1317,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[66],"tags":[67,68,70,71,69],"class_list":["post-1313","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bim","tag-bim","tag-notesvandat","tag-practical","tag-practical-questions-and-answers","tag-web-tech"],"acf":[],"_links":{"self":[{"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/posts\/1313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/comments?post=1313"}],"version-history":[{"count":8,"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/posts\/1313\/revisions"}],"predecessor-version":[{"id":1323,"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/posts\/1313\/revisions\/1323"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/media\/1317"}],"wp:attachment":[{"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/media?parent=1313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/categories?post=1313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notesvandar.com\/api\/wp\/v2\/tags?post=1313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}