code is not checking is username or password is in database [duplicate]









up vote
-1
down vote

favorite













This question already has an answer here:



  • check if row exists with mysql

    3 answers



  • Reference - What does this error mean in PHP?

    31 answers



I have spent ages trying to figure out how to check the input for username and email and see whether it is in the database, however, nothing is working and the data still gets inserted regardless of whether it is already in the database or not. I have taken the previous code I had for this out as it did not work and was wondering if anyone knew how to apply this function.



this is my form



<form method="post" action="connect.php">
<fieldset class="form-group">
User : <input type="text" name="username" class="form-control" placeholder="user"><br><br>
Password : <input type="password" name="password" id="password" onkeyup='check();'class="form-control"
placeholder="password"/>
<br><br>

<label>confirm password:

<input type="password" name="password1" id="password1" onkeyup="check();" class="form-control" placeholder=" confirm password" style="width: 234%;">
<span id='message'></span>




<br><br>
Email :
<input type="email" name="email" class="form-control" placeholder="email" style="width: 234%;"><br><br>

<input type="submit" value="Sign up" name="Sign up" class="btn btn-primary" style="width: 225%;">
</label>
</fieldset>
</form>


</div>
</div>


this is my php



<?php
session_start();

$username = filter_input(INPUT_POST, 'username');
$password = filter_input(INPUT_POST, 'password');
if (!empty($username))
if (!empty($password))
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "picshare";
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);

if (mysqli_connect_error())
die('Connect Error ('. mysqli_connect_errno() .') '
. mysqli_connect_error());

else
$sql = "INSERT INTO login (username, password)
values ('$username','$password')";
if ($conn->query($sql))
echo "New record is inserted sucessfully";

header("location: practises.php");

else
echo "Error: ". $sql ." ". $conn->error;


$conn->close();


else
echo "Password should not be empty";
die();


else
echo "Username should not be empty";
die();

?>









share|improve this question













marked as duplicate by Funk Forty Niner html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 11 at 18:08


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • I don't see a SELECT query.
    – Funk Forty Niner
    Nov 11 at 18:07










  • You're outputting before header btw.
    – Funk Forty Niner
    Nov 11 at 18:08










  • Maybe setting the email as unique? At least you will have an error when inserting an already present email. But as @FunkFortyNiner said, you should SELECT and check if the account is already present
    – Vexorei
    Nov 11 at 18:10















up vote
-1
down vote

favorite













This question already has an answer here:



  • check if row exists with mysql

    3 answers



  • Reference - What does this error mean in PHP?

    31 answers



I have spent ages trying to figure out how to check the input for username and email and see whether it is in the database, however, nothing is working and the data still gets inserted regardless of whether it is already in the database or not. I have taken the previous code I had for this out as it did not work and was wondering if anyone knew how to apply this function.



this is my form



<form method="post" action="connect.php">
<fieldset class="form-group">
User : <input type="text" name="username" class="form-control" placeholder="user"><br><br>
Password : <input type="password" name="password" id="password" onkeyup='check();'class="form-control"
placeholder="password"/>
<br><br>

<label>confirm password:

<input type="password" name="password1" id="password1" onkeyup="check();" class="form-control" placeholder=" confirm password" style="width: 234%;">
<span id='message'></span>




<br><br>
Email :
<input type="email" name="email" class="form-control" placeholder="email" style="width: 234%;"><br><br>

<input type="submit" value="Sign up" name="Sign up" class="btn btn-primary" style="width: 225%;">
</label>
</fieldset>
</form>


</div>
</div>


this is my php



<?php
session_start();

$username = filter_input(INPUT_POST, 'username');
$password = filter_input(INPUT_POST, 'password');
if (!empty($username))
if (!empty($password))
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "picshare";
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);

if (mysqli_connect_error())
die('Connect Error ('. mysqli_connect_errno() .') '
. mysqli_connect_error());

else
$sql = "INSERT INTO login (username, password)
values ('$username','$password')";
if ($conn->query($sql))
echo "New record is inserted sucessfully";

header("location: practises.php");

else
echo "Error: ". $sql ." ". $conn->error;


$conn->close();


else
echo "Password should not be empty";
die();


else
echo "Username should not be empty";
die();

?>









share|improve this question













marked as duplicate by Funk Forty Niner html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 11 at 18:08


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • I don't see a SELECT query.
    – Funk Forty Niner
    Nov 11 at 18:07










  • You're outputting before header btw.
    – Funk Forty Niner
    Nov 11 at 18:08










  • Maybe setting the email as unique? At least you will have an error when inserting an already present email. But as @FunkFortyNiner said, you should SELECT and check if the account is already present
    – Vexorei
    Nov 11 at 18:10













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:



  • check if row exists with mysql

    3 answers



  • Reference - What does this error mean in PHP?

    31 answers



I have spent ages trying to figure out how to check the input for username and email and see whether it is in the database, however, nothing is working and the data still gets inserted regardless of whether it is already in the database or not. I have taken the previous code I had for this out as it did not work and was wondering if anyone knew how to apply this function.



this is my form



<form method="post" action="connect.php">
<fieldset class="form-group">
User : <input type="text" name="username" class="form-control" placeholder="user"><br><br>
Password : <input type="password" name="password" id="password" onkeyup='check();'class="form-control"
placeholder="password"/>
<br><br>

<label>confirm password:

<input type="password" name="password1" id="password1" onkeyup="check();" class="form-control" placeholder=" confirm password" style="width: 234%;">
<span id='message'></span>




<br><br>
Email :
<input type="email" name="email" class="form-control" placeholder="email" style="width: 234%;"><br><br>

<input type="submit" value="Sign up" name="Sign up" class="btn btn-primary" style="width: 225%;">
</label>
</fieldset>
</form>


</div>
</div>


this is my php



<?php
session_start();

$username = filter_input(INPUT_POST, 'username');
$password = filter_input(INPUT_POST, 'password');
if (!empty($username))
if (!empty($password))
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "picshare";
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);

if (mysqli_connect_error())
die('Connect Error ('. mysqli_connect_errno() .') '
. mysqli_connect_error());

else
$sql = "INSERT INTO login (username, password)
values ('$username','$password')";
if ($conn->query($sql))
echo "New record is inserted sucessfully";

header("location: practises.php");

else
echo "Error: ". $sql ." ". $conn->error;


$conn->close();


else
echo "Password should not be empty";
die();


else
echo "Username should not be empty";
die();

?>









share|improve this question














This question already has an answer here:



  • check if row exists with mysql

    3 answers



  • Reference - What does this error mean in PHP?

    31 answers



I have spent ages trying to figure out how to check the input for username and email and see whether it is in the database, however, nothing is working and the data still gets inserted regardless of whether it is already in the database or not. I have taken the previous code I had for this out as it did not work and was wondering if anyone knew how to apply this function.



this is my form



<form method="post" action="connect.php">
<fieldset class="form-group">
User : <input type="text" name="username" class="form-control" placeholder="user"><br><br>
Password : <input type="password" name="password" id="password" onkeyup='check();'class="form-control"
placeholder="password"/>
<br><br>

<label>confirm password:

<input type="password" name="password1" id="password1" onkeyup="check();" class="form-control" placeholder=" confirm password" style="width: 234%;">
<span id='message'></span>




<br><br>
Email :
<input type="email" name="email" class="form-control" placeholder="email" style="width: 234%;"><br><br>

<input type="submit" value="Sign up" name="Sign up" class="btn btn-primary" style="width: 225%;">
</label>
</fieldset>
</form>


</div>
</div>


this is my php



<?php
session_start();

$username = filter_input(INPUT_POST, 'username');
$password = filter_input(INPUT_POST, 'password');
if (!empty($username))
if (!empty($password))
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "picshare";
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);

if (mysqli_connect_error())
die('Connect Error ('. mysqli_connect_errno() .') '
. mysqli_connect_error());

else
$sql = "INSERT INTO login (username, password)
values ('$username','$password')";
if ($conn->query($sql))
echo "New record is inserted sucessfully";

header("location: practises.php");

else
echo "Error: ". $sql ." ". $conn->error;


$conn->close();


else
echo "Password should not be empty";
die();


else
echo "Username should not be empty";
die();

?>




This question already has an answer here:



  • check if row exists with mysql

    3 answers



  • Reference - What does this error mean in PHP?

    31 answers







php html mysql database mysqli






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 18:06









E. Olaogun

1




1




marked as duplicate by Funk Forty Niner html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 11 at 18:08


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Funk Forty Niner html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 11 at 18:08


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • I don't see a SELECT query.
    – Funk Forty Niner
    Nov 11 at 18:07










  • You're outputting before header btw.
    – Funk Forty Niner
    Nov 11 at 18:08










  • Maybe setting the email as unique? At least you will have an error when inserting an already present email. But as @FunkFortyNiner said, you should SELECT and check if the account is already present
    – Vexorei
    Nov 11 at 18:10

















  • I don't see a SELECT query.
    – Funk Forty Niner
    Nov 11 at 18:07










  • You're outputting before header btw.
    – Funk Forty Niner
    Nov 11 at 18:08










  • Maybe setting the email as unique? At least you will have an error when inserting an already present email. But as @FunkFortyNiner said, you should SELECT and check if the account is already present
    – Vexorei
    Nov 11 at 18:10
















I don't see a SELECT query.
– Funk Forty Niner
Nov 11 at 18:07




I don't see a SELECT query.
– Funk Forty Niner
Nov 11 at 18:07












You're outputting before header btw.
– Funk Forty Niner
Nov 11 at 18:08




You're outputting before header btw.
– Funk Forty Niner
Nov 11 at 18:08












Maybe setting the email as unique? At least you will have an error when inserting an already present email. But as @FunkFortyNiner said, you should SELECT and check if the account is already present
– Vexorei
Nov 11 at 18:10





Maybe setting the email as unique? At least you will have an error when inserting an already present email. But as @FunkFortyNiner said, you should SELECT and check if the account is already present
– Vexorei
Nov 11 at 18:10


















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands