0

I have created a simple login / register form in php, it works very well in local host.

When testing in localhost when i try and register the same email address twice then it informs me that the email is already taken. However i have now uploaded my entire login form to go daddy hosting cpanel and it for some reason allows me to register the same email twice ?? I think this is a bit odd considering its the exact same code uploaded.

Here is my register form ....

If anyone has some tips it would be greatly appreciated

<?php 
if(isset($_SESSION['user'])!="")
{
 header("Location: home.php");
}
include_once 'dbconnect.php';



if(isset($_POST['btn-signup']))
{
 $uname = mysql_real_escape_string($_POST['uname']);
 $sname = mysql_real_escape_string($_POST['sname']);
 $email = mysql_real_escape_string($_POST['email']);
 $upass = md5(mysql_real_escape_string($_POST['pass']));

a:

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {


?>

<script>
        window.onload = function() { document.getElementById('register_error').innerHTML = 'Invalid Email Address'; };
</script> 


<?php


      return;
      goto a;

}



 if(mysql_query("INSERT INTO users(username,second_name,email,password) VALUES('$uname','$sname','$email','$upass')"))
 {
        header( "refresh:5; url=login.php" );

  ?>
<script>

        window.onload = function() { document.getElementById('register_success').innerHTML = 'Sucessfully Registered, You will now be redirected to the login page'; };
</script>        <?php
 }
 else
 {
  ?>
 <script>window.onload = function() { document.getElementById('register_error').innerHTML = 'This email is allready taken'; };
</script>        <?php
 }
}

?>
Bradley Cousins
  • 187
  • 6
  • 17
  • 1
    The issue properly is that your email column in the database isn't set to unique, since I can't see anywhere in your code that you check if it all ready exist. – Epodax Jan 07 '16 at 11:36
  • thismaybe the problem. I have just tried to make all emails unique however phpmyadmin replies saying i already have some of the same emails. Do you know how to drop all users in the database ? – Bradley Cousins Jan 07 '16 at 11:42
  • Google it. How to dump "How to dump data from a mysql table" – Epodax Jan 07 '16 at 11:47

1 Answers1

1

Either you have to setemail field as UNIQUE in db or need to check if the email is already exists with PHP script.

dhi_m
  • 1,235
  • 12
  • 21
  • Hi, I think this maybe the problem. I have just tried to make all emails unique however phpmyadmin replies saying i already have some of the same emails. Do you know how to drop all users in the database ? – Bradley Cousins Jan 07 '16 at 11:42
  • First please take backup of your table and then try to set UNIQUE after clearing the data.In phpmyadmin there is option to empty the table – dhi_m Jan 07 '16 at 11:44
  • In phpmyadmin there is option to empty the table – dhi_m Jan 07 '16 at 11:46
  • Please check this http://stackoverflow.com/questions/454174/how-to-empty-all-rows-from-all-tables-in-mysql-in-sql – dhi_m Jan 07 '16 at 11:52