Exercise-8 IWP 18BCE0557 Kushal: 1) DB Creation Code
Exercise-8 IWP 18BCE0557 Kushal: 1) DB Creation Code
IWP
18BCE0557 KUSHAL
1) DB creation
CODE:
<?php
header('Content-type: text/plain');
$url='127.0.0.1:3306';
$username='root';
$password='';
$dbname = 'Users';
$conn=mysqli_connect($url, $username, $password);
if($conn->connect_error){
die('Could not Connect My Sql:' . $conn->connect_error);
}
/* Create database */
$sql = "CREATE DATABASE Users";
if ($conn->query($sql) === TRUE) {
echo "\nDatabase Users created successfully";
}
else
{
echo "\nError creating database: " . $conn->error;
}
$conn->close();
if($conn->connect_error){
die('\n2 Could not Connect My Sql:' . $conn->connect_error);
}
$conn->close();
?>
2) CONNECTION Code
3) <?php
4) $url='127.0.0.1:3306';
5) $username='root';
6) $password='';
7) $database='Users';
8) $conn=mysqli_connect($url,$username,$password,$database);
9) if(!$conn){
10) die('Could not Connect My Sql:' .mysql_error());
11) }
12) else {
13) echo "All good here";
14) }
15) ?>
3) Signup
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>signup form</title>
<script language="javascript">
function check()
{
if(document.form1.username.value=="")
{
alert("Plese Enter Username");
document.form1.username.focus();
return false;
if(document.form1.password.value=="")
{
alert("Plese Enter Your passwordword");
document.form1.password.focus();
return false;
}
if(document.form1.pnumber.value=="")
{
alert("Plese Enter Phone No");
document.form1.pnumber.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
echo '<div>
<form name="form1" action="signup.php" method="post"
onSubmit="return check();">
<input type="text" name="username" id="username"
placeholder="Username">
<input type="password" name="password" id="password"
placeholder="Password">
<input type="number" name="pnumber" id="pnumber"
placeholder="Phone Number">
<input type="submit" value="submit">
</form>
</div>';
}
extract($_POST);
include("database.php");
?>
</body>
</html>
4) Login
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>login</title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['message'])) {
echo $_GET['message'];
}
echo '<div>
<form name="form1" action="login.php" method="post">
<input type="text" name="username" id="username"
placeholder="Username">
<input type="password" name="password" id="password"
placeholder="Password">
<input type="submit" value="submit">
</form>
</div>';
}
extract($_POST);
include("database.php");
?>
</body>
</html>