0

I need little help here. Anyhelp greatly appreciated. My 1st code with die command and the footer will not show up because of the die command. So i have changed from die command to if else function. Here is my edited code. The problem is can't insert new data into database.

         <?php 
    // Connects to your Database 
    mysql_connect("localhost", "root", "") or die(mysql_error()); 
    mysql_select_db("destiku_db") or die(mysql_error()); 


    //This code runs if the form has been submitted
    if (isset($_POST['submit'])) 
    { 

        //This makes sure they did not leave any fields blank
        if (!$_POST['email'] | !$_POST['password'] | !$_POST['password2'] ) 
        { echo "You did not complete all of the required fields"; }

        // this makes sure both passwords entered match
        elseif ($_POST['password'] != $_POST['password2']) 
        { 
            echo "Your passwords did not match."; 

            // here we encrypt the password and add slashes if needed
            $_POST['password'] = md5($_POST['password2']);

            if (!get_magic_quotes_gpc()) 
            {
                $_POST['password'] = addslashes($_POST['password']);
                $_POST['email'] = addslashes($_POST['email']);
            }
        }

        // checks if the email is in use
        elseif (!get_magic_quotes_gpc()) 
        { 
            $_POST['email'] = addslashes($_POST['email']);

            $usercheck = $_POST['email'];
            $check = mysql_query("SELECT u_email FROM user_login WHERE u_email = '$usercheck'");
            $check2 = mysql_num_rows($check);

            //if the name exists it gives an error
            if ($check2 != 0) 
            { echo"Sorry, the email ";?> <?php $_POST['email'] ?> <?php echo"is already in use."; }
        } 

        else
        {   

            // now we insert it into the database
            $insert = "INSERT INTO user_login (u_email, u_password) VALUES ('".$_POST['email']."', '".$_POST['password']."')";
            $add_member = mysql_query($insert);


          echo"
            <h1>Registered</h1>
            <p>Thank you, you have registered - you may now
            <a href=index.php?1=php&page=login>Login</a>.</p>"; 
        }

    } 

    else 
    {   
    ?>

        <form action="<?php echo"index.php?1=php&page=registration"; ?>" method="post">
        <table border="0">
        <tr><td>Email:</td><td><input type="text" name="email" maxlength="60"></td></tr>

        <tr><td>Password:</td><td><input type="password" name="password" maxlength="10"></td></tr>

        <tr><td>Confirm Password:</td><td><input type="password" name="password2" maxlength="10"></td></tr>

        <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> 
        </table>
        </form>

    <?php
    }
    ?> 

Thanks in adv.

Cik Deena
  • 1
  • 3
  • 2
    Which die function; you have two. Blind stab; your MySQL API doesn't work anymore. Use `mysql_` or PDO. Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Mar 20 '15 at 15:30
  • 1
    Btw, `if (!$_POST['email'] | !$_POST['password'] | !$_POST['password2'] )` missing another `|` for each of those. – Funk Forty Niner Mar 20 '15 at 15:31
  • 1
    Don't store plain-text passwords: http://stackoverflow.com/questions/401656/secure-hash-and-salt-for-php-passwords?rq=1. And your title and first paragraph seem to reference other code than the code given in your question.. – jeroen Mar 20 '15 at 15:33

0 Answers0