I am a newbie and I am trying to make a signUp form using php and bootstrap. I have chosen the 'emailAddress' of the users as my primary key in my mysql database table named 'user_accounts'. What I desire is if the Email of the user is unique, it should add their record to the database(which is working absolutely fantastic) but if the user enters an email already existing in the database, it should not add their record in the database, bring them back on the same page and changing the 'form-group' to 'form-group has-danger' element(as in bootstrap) giving them the message to change thier email and signUp again. It is not adding the record of repeated email in the database as the email field is the primary key but it is not showing the 'form-group has-danger' on submitting, thus not giving the error message. Here is my code -
<body>
<div class="container">
<center>
<form class="signUpForm" method="post">
<h1 class="signUpH1"><strong>Sign Up!</strong></h1>
<hr>
<fieldset>
<div class="form-group">
<label for="fullName">Full Name</label>
<input type="text" class="form-control" name="fullName" placeholder="Enter name">
</div>
<?php
$_REQUEST[$status];
if ($status == 'changeEmail') {
# code...
echo "<div class='form-group has-danger'>
<label for='emailAddress'>Email address</label>
<input type='email' class='form-control is-invalid' name='emailAddress' placeholder='Enter email'>
<div class='invalid-feedback'>Sorry, an account with that Email already exists! Try another.</div>
</div>";
}
else {
# code...
echo "<div class='form-group'>
<label for='emailAddress'>Email address</label>
<input type='email' class='form-control' name='emailAddress' aria-describedby='emailHelp' placeholder='Enter email'>
<small id='emailHelp' class='form-text text-muted'>We'll never share your email with anyone else.</small>
</div>";
}
?>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" placeholder="Enter Password">
</div>
<button type="submit" class="btn btn-primary" name="signUp">Submit</button>
</fieldset>
</form>
</center>
</div>
<?php
if (isset($_REQUEST['signUp'])) {
$fullName = $_REQUEST['fullName'];
$emailAddress = $_REQUEST['emailAddress'];
$password = $_REQUEST['password'];
$link = mysql_connect("localhost","root","");
mysql_select_db("practiceDatabase",$link);
mysql_query("insert into user_accounts values ('".$fullName."','".$emailAddress."','".$password."')");
$n = mysql_affected_rows();
if ($n == 0) {
# code...
$status = 'changeEmail';
return $status;
}
mysql_close($link);
}
?>
</body>
Any Help much appreciated! Thanks!