-1

I've been stuck for a couple days connecting the registration looking through forums etc. No error seems to populate on the page, but when I take a look at phpMyAdmin it doesn't show the registration info inserted in the db.

register.php

<?php

session_start();

if(isset($_SESSION['user'])!="")

{

    header("Location: home.php");

}
$servername = "correctly inserted info";
$username = "correctly inserted info";
$password = "correctly inserted info";
$dbname = "correctly inserted info";

$conn = new mysqli($servername, $username, $password, $dbname);



if(isset($_POST['btn-signup']))

{
$fname = mysql_real_escape_string($_POST['fullname']);

$uname = mysql_real_escape_string($_POST['username']);

$email = mysql_real_escape_string($_POST['email']);

$upass = md5(mysql_real_escape_string($_POST['password']));


 if(mysql_query("INSERT INTO users(fullname,username,email,password)  VALUES('$fname','$uname','$email','$upass')"))


{

    ?>

    <script>alert('successfully registered');</script>

    <?php

}

else

{

    ?>

    <script>alert('error while registering you...');</script>

    <?php

}

}

?>

registration.php

<!DOCTYPE html>
<!--[if IE 9 ]><html class="ie9"><![endif]-->
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    <meta name="format-detection" content="telephone=no">
    <meta charset="UTF-8">

    <meta name="description" content="Violate Responsive Admin Template">
    <meta name="keywords" content="Super Admin, Admin, Template, Bootstrap">

    <title>Super Admin Responsive Template</title>

    <!-- CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/form.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/generics.css" rel="stylesheet"> 
 </head>
  <body id="skin-blur-violate">
    <section id="login">
        <header>
            <h1>SUPER ADMIN</h1>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.  Nulla eu risus. Curabitur commodo lorem fringilla enim feugiat commodo sed ac lacus.</p>
        </header>

        <div class="clearfix"></div>

       <!-- Login -->
        <form class="box tile animated active" id="box-login">

        <!-- Register -->
        <?php require_once("register.php"); ?>

        <form class="box animated tile" id="box-register" method="post">

            <h2 class="m-t-0 m-b-15">Register</h2>
            <input type="text" class="login-control m-b-10" placeholder="Full Name" name="fname" required/>
            <input type="text" class="login-control m-b-10" placeholder="Username" name="uname" required/>
            <input type="email" class="login-control m-b-10" placeholder="Email Address" name="email" required/>    
            <input type="password" class="login-control m-b-10" placeholder="Password" name="pass" required/>

            <button class="btn btn-sm m-r-5" type="submit">Register</button>

            <small><a class="box-switcher" data-switch="box-login"  href="">Already have an Account?</a></small>
        </form>

        <!-- Forgot Password -->

    </section>                      

    <!-- Javascript Libraries -->
    <!-- jQuery -->
    <script src="js/jquery.min.js"></script> <!-- jQuery Library -->

        <!-- Bootstrap -->
        <script src="js/bootstrap.min.js"></script>

        <!--  Form Related -->
        <script src="js/icheck.js"></script> <!-- Custom Checkbox +  Radio -    ->

        <!-- All JS functions -->
        <script src="js/functions.js"></script>
    </body>
</html>

I've editing the code to help cause I'm still coming up with the same issue, but many seem to be on the right track. I was using mysql and mysqli interchangeably. I looking in my dbconnect.php file and found the following which looks like I'll also need to change to make it uniform with the mysqli being displayed in other areas. On the right track, but not there yet.

I just found though that dbconnect.php is deploying the mysql version and not the mysql version any thoughts?

I just found though that dbconnect.php is deploying the mysql version and not the mysql version any thoughts?

dbconnect.php

<?php

if(!mysql_connect("correct host","correct username","correct password"))

{

die('oops connection problem ! --> '.mysql_error());

}

if(!mysql_select_db("correct db"))

{

die('oops database selection problem ! --> '.mysql_error());

}



?>

Based on the starting responses I found that many we're helping me get on the right track...here are the other correlating files since the general theme is I am interchanging mysql and mysqli. Parts of it seemed to work initially but now it's all coming apart so if anyone can help me put it all back together again appreciate it. I'm still having no response from posting to the database which is why I'm making the edits.

index.php

<?php

session_start();

include_once 'dbconnect.php';



if(isset($_SESSION['user'])!="")

{

header("Location: home.php");

}



if(isset($_POST['btn-login']))

{

$email = mysql_real_escape_string($_POST['email']);

$upass = mysql_real_escape_string($_POST['pass']);

$res=mysql_query("SELECT * FROM users WHERE email='$email'");

$row=mysql_fetch_array($res);



if($row['password']==md5($upass))

{

    $_SESSION['user'] = $row['user_id'];

    header("Location: home.php");

}

else

{

    ?>

    <script>alert('wrong details');</script>

    <?php

}



}

?>

Just so I'm showing all I have in this process....I'm also putting in my login.php file so hopefully I can get this all resolved.

login.php

<!DOCTYPE html>
<!--[if IE 9 ]><html class="ie9"><![endif]-->
<head>
    <meta name="viewport" content="width=device-width, initial-    scale=1.0, maximum-scale=1.0" />
    <meta name="format-detection" content="telephone=no">
    <meta charset="UTF-8">

    <meta name="description" content="Violate Responsive Admin Template">
    <meta name="keywords" content="Super Admin, Admin, Template, Bootstrap">

    <title>Super Admin Responsive Template</title>

    <!-- CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/form.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/generics.css" rel="stylesheet"> 
</head>
<body id="skin-blur-violate">
    <section id="login">
        <header>
            <h1>SUPER ADMIN</h1> 
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eu risus. Curabitur commodo lorem fringilla enim feugiat commodo sed ac lacus.</p>
        </header>

        <div class="clearfix"></div>

        <!-- Login -->
        <?php require_once("index.php"); ?>

 <form class="box tile animated active" id="box-login">
            <h2 class="m-t-0 m-b-15">Login</h2>
            <input type="text" class="login-control m-b-10" placeholder="Username or Email Address">
            <input type="password" class="login-control" placeholder="Password">
            <div class="checkbox m-b-20">
                <label>
                    <input type="checkbox">
                    Remember Me
                </label>
            </div>
            <button type="submit" name="btn-login" class="btn btn-sm m-r-5">Sign In</button>

            <small>
                <a href="registration.php">Don't have an Account?</a> or
                <a class="box-switcher" data-switch="box-reset" href="">Forgot Password?</a>
            </small>
        </form>

        <!-- Forgot Password -->
        <form class="box animated tile" id="box-reset">
            <h2 class="m-t-0 m-b-15">Reset Password</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eu risus. Curabitur commodo lorem fringilla enim feugiat commodo sed ac lacus.</p>
            <input type="email" class="login-control m-b-20" placeholder="Email Address">    

            <button class="btn btn-sm m-r-5">Reset Password</button>

            <small><a class="box-switcher" data-switch="box-login" href="">Already have an Account?</a></small>
        </form>
    </section>                      

    <!-- Javascript Libraries -->
    <!-- jQuery -->
    <script src="js/jquery.min.js"></script> <!-- jQuery Library -->

    <!-- Bootstrap -->
    <script src="js/bootstrap.min.js"></script>

    <!--  Form Related -->
    <script src="js/icheck.js"></script> <!-- Custom Checkbox + Radio -->

    <!-- All JS functions -->
    <script src="js/functions.js"></script>
 </body>
</html>
Francisco
  • 10,918
  • 6
  • 34
  • 45
Stuzzle
  • 21
  • 6
  • 1
    You are mixing up `mysql` and `mysqli` – Professor Abronsius Nov 01 '15 at 14:55
  • and this is failing you for 2 reasons `if(isset($_SESSION['user'])!="")` - plus, this piece of code is very familiar. You've taken this from the same place as previously posted questions. – Funk Forty Niner Nov 01 '15 at 15:39
  • and your POST arrays are failing, something that all answers given so far, have not picked up on. Your code is literally stitched with syntax errors. Oh and `if(isset($_POST['btn-signup']))` that will NEVER happen. – Funk Forty Niner Nov 01 '15 at 15:41
  • Note to all answerers so far: Your answers will all fail. Double check it, you missed quite a few things. If you receive downvotes, they would NOT have come from me. – Funk Forty Niner Nov 01 '15 at 15:45
  • I found something else along the same lines....in the dbconnect.php file I also have the same mysql adjustments....I have the following: – Stuzzle Nov 01 '15 at 16:13
  • added more to present more of my findings in the other areas. I'm trying to find a good connection to connect myadmin panel to a full register, and login....I'd be open to using a different code just having problem finding something that I can connect into the html/php/bootstrap of the admin signin I already have. – Stuzzle Nov 01 '15 at 16:32

3 Answers3

2

Errors

  1. You are conflicting mysql and mysqli.
  2. name attribute is not define on here <button class="btn btn-sm m-r-5" type="submit">Register</button>
  3. In register.php you check isset with an class, This will never works if(isset($_POST['btn-signup']))
  4. As well as your Form name field and retrieve fields are wrong.(form - placeholder="Full Name" name="fname"/ in code - mysql_real_escape_string($_POST['fullname']))

Improvements

To check variable is null or empty use empty() keyword

Change this

if(isset($_SESSION['user'])!="")

{

    header("Location: home.php");

}

to this

if(!empty($_SESSION['user'])){
    header("Location: home.php");
}

Bug Fixed code

In register.php

if(isset($_POST['register'])){

    $fname = mysqli_real_escape_string($conn, $_POST['fname']);
    $uname = mysqli_real_escape_string($conn, $_POST['uname']);
    $email = mysqli_real_escape_string($conn, $_POST['email']);
    $upass = md5(mysqli_real_escape_string($conn, $_POST['pass']));

    $sql = "INSERT INTO users(fullname,username,email,password)  VALUES('$fname','$uname','$email','$upass')";
     if(mysqli_query($conn, $sql))
    {
        ?>
        <script>
            alert('successfully registered');
        </script>
        <?php
    }
    else{
        ?>
        <script>
            alert('error while registering you...');
        </script>
        <?php
    }

}

In registration.php

<button class="btn btn-sm m-r-5" type="submit" name="register">Register</button>
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

As mentioned in the comment, you were mixing both mysql and mysqli extensions.

<?php
    session_start();
    error_reporting( E_ALL );

    if( isset( $_SESSION['user'] ) && !empty( $_SESSION['user'] ) ) header("location: home.php");


    $servername = "correctly inserted info";
    $username = "correctly inserted info";
    $password = "correctly inserted info";
    $dbname = "correctly inserted info";
    $conn = new mysqli( $servername, $username, $password, $dbname );


    /* Could not see a form element with that name: $_POST['btn-signup'] */

    if( isset( $_POST['fullname'], $_POST['username'], $_POST['email'], $_POST['password'] ) ) {
        $fname = mysqli_real_escape_string( $conn, $_POST['fullname'] );
        $uname = mysqli_real_escape_string( $conn, $_POST['username'] );
        $email = mysqli_real_escape_string( $conn, $_POST['email'] );
        $upass = md5( mysqli_real_escape_string( $conn, $_POST['password'] ) );

        /* Had ommitted the connection object */
        if( mysqli_query( $conn, "INSERT INTO `users` ( `fullname`, `username`, `email`, `password` ) VALUES ( '$fname', '$uname', '$email', '$upass' )" ) ) {
            echo "<script>alert('successfully registered');</script>";
        } else {
            echo "<script>alert('error while registering you...');</script>";
        }
    }

?>
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
  • double check that and see my comments under their question – Funk Forty Niner Nov 01 '15 at 15:53
  • I adjusted and still don't seem to have any change...the screen flickers when clicking register, but nothing appears in the database...I'm sure the server name, username, password, and dbname are all correct. – Stuzzle Nov 01 '15 at 16:03
-1

$conn = new mysqli($servername, $username, $password, $dbname);

$fname = mysql_real_escape_string($_POST['fullname']);

check them

them also try using some error reporting at the very top of the php code block ..

Mer Igos
  • 23
  • 4