Skip to content
Snippets Groups Projects
Commit 6ab43ffb authored by Raghav's avatar Raghav
Browse files

Data inserted into DB, Failed to execute page when data is not correct

parent e1dd03fd
No related branches found
No related tags found
No related merge requests found
<main class="form-signup w-100 m-auto">
<form action="/photogram-project-php/test.php" method="post">
<img class="mb-4 center" src="/photogram-project-php/assets/brand/devyani_logo_edit_light copy.svg" alt="" width="72" height="77">
<h1 class="h3 mb-3 fw-normal">Please sign up</h1>
<?php
<div class="form-floating">
<input name="username" type="text" class="form-control" id="floatingInput" placeholder="Username">
<label for="floatingInput">Username</label>
</div>
<div class="form-floating">
<input name="email" type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
<label for="floatingInput">Email address</label>
</div>
<div class="form-floating">
<input name="password" type="password" class="form-control" id="floatingPassword" placeholder="Password">
<label for="floatingPassword">Password</label>
</div>
<div class="form-floating">
<input name="phone" type="text" class="form-control" id="floatingInput" placeholder="Phone number">
<label for="floatingInput">Phone number</label>
$signup = false;
// checks if all the values are received from form.
if (isset($_POST['username']) and isset($_POST['password']) and isset($_POST['email']) and isset($_POST['phone'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$error = signup($username, $password, $email, $phone);
$signup = true;
}
// checks if the data stored in database
if ($signup) {
if (!$error) { ?>
<main class="container">
<div class="bg-body-tertiary p-5 rounded">
<h1>Signup Success</h1>
<p class="lead">Know you can login <a href="login.php">here</a>.</p>
<a class="btn btn-lg btn-primary" href="/docs/5.3/components/navbar/" role="button">View navbar docs »</a>
</div>
</main>
<div class="form-check text-start my-3">
<input class="form-check-input" type="checkbox" value="remember-me" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Remember me
</label>
<?php } else { ?>
<main class="container">
<div class="bg-body-tertiary p-5 rounded">
<h1>Something went wrong..</h1>
<p class="lead">Please try again .. <a href="login.php">here</a>.</p>
<?=$error?>
<a class="btn btn-lg btn-primary" href="/docs/5.3/components/navbar/" role="button">View navbar docs »</a>
</div>
<button class="hvr-grow-shadow btn btn-primary w-100 py-2 " type="submit">Sign Up</button>
</form>
</main>
\ No newline at end of file
</main>
<?php }
} else {
?>
<main class="form-signup w-100 m-auto">
<form action="/photogram-project-php/signup.php" method="post">
<img class="mb-4 center" src="/photogram-project-php/assets/brand/devyani_logo_edit_light copy.svg" alt=""
width="72" height="77">
<h1 class="h3 mb-3 fw-normal">Please sign up</h1>
<div class="form-floating">
<input name="username" type="text" class="form-control" id="floatingInput" placeholder="Username">
<label for="floatingInput">Username</label>
</div>
<div class="form-floating">
<input name="email" type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
<label for="floatingInput">Email address</label>
</div>
<div class="form-floating">
<input name="password" type="password" class="form-control" id="floatingPassword" placeholder="Password">
<label for="floatingPassword">Password</label>
</div>
<div class="form-floating">
<input name="phone" type="text" class="form-control" id="floatingInput" placeholder="Phone number">
<label for="floatingInput">Phone number</label>
</div>
<div class="form-check text-start my-3">
<input class="form-check-input" type="checkbox" value="remember-me" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Remember me
</label>
</div>
<button class="hvr-grow-shadow btn btn-primary w-100 py-2 " type="submit">Sign Up</button>
</form>
</main>
<?php } ?>
\ No newline at end of file
......@@ -32,15 +32,16 @@ function signup($user, $pass, $email, $phone)
$sql = "INSERT INTO `auth` (`username`, `password`, `email`, `phone`, `block`, `active`)
VALUES ('$user', '$pass', '$email', '$phone', '0', '1');";
$result = false;
$error = false;
if ($conn->query($sql) === TRUE) {
$result = true;
$error = false;
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
$result = false;
$error = $conn->error;
}
$conn->close();
return $result;
return $error;
}
<pre>
<?php
include 'libs/load.php';
// print("_SERVER\n");
// print_r($_SERVER);
// print("_GET\n");
// print_r($_GET);
// print("_POST\n");
// print_r($_POST);
print("_SERVER\n");
print_r($_SERVER);
print("_GET\n");
print_r($_GET);
print("_POST\n");
print_r($_POST);
// print("_FILE\n");
// print_r($_FILES);
print("_FILE\n");
print_r($_FILES);
// print("_COOKIE\n");
// print_r($_COOKIE);
print("_COOKIE\n");
print_r($_COOKIE);
if(signup("raghav","raghav","raghav@example.com","9566743991")){
print("Data inserted");
}else{
print("Failed to inserted");
echo "Error: " . $sql . "<br>" . $conn->error;
}
// if(signup("raghav","raghav","raghav@example.com","9566743991")){
// print("Data inserted");
// }else{
// print("Failed to inserted");
// echo "Error: " . $sql . "<br>" . $conn->error;
// }
?>
</pre>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment