0

How would I make it so on the user being registered they get redirected to a different page. Ive tried most things, and yes it registers fine but im just struggling with this one bit D:

regsister.inc.php

<?php
//Start session:
session_start();

//Include db settings and create a connection:
include("config.inc.php");

//Create variable for username input and prevent sql injections:
$username = mysql_real_escape_string($_POST['usern2']);
//Create variable for password input, prevent sql injections and hash it with md5:
$password = mysql_real_escape_string(md5($_POST['pass2']));

//Select matching username and password from admin table based on input:
$sql = "INSERT INTO admin VALUES('$username', md5('$password'))";
//$sql = "SELECT * FROM admin WHERE username = '$username' AND password = '$password'";
//Execute query to db:
$execute = mysql_query($sql);

if (mysql_num_rows($execute) == 1) {
    $_SESSION['user'] = $username;
    echo "<p>Register Successful</p>";

}

register.php

<?php
include ("includes/register.inc.php");
    ?>
<!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8">
        <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <link href="css/style.css" rel="stylesheet">
    </head>
    <body>

        <div id="container">

            <?php echo $errormsg; ?>

            <h2>Register</h2>

            <form method="post" action="register.php">
                <label>Username: </label>
                <input type="text" size="25" name="usern2" value=""><br>
                <label>Password: </label>
                <input type="password" size="25" name="pass2" value=""><br>
                <input type="submit" value="Register!">
            </form>

        </div>

    </body>
</html>

Much help would be appreciated, dont roast me im new to PHP D:

n0b0y
  • 3
  • 3
  • 1
    Possible duplicate of [How to make a redirect in PHP?](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – Muhammad Saqlain Feb 25 '17 at 21:58
  • but idk where to put it in the code – n0b0y Feb 25 '17 at 21:59
  • In If condition if (mysql_num_rows($execute) == 1) { //here } – Muhammad Saqlain Feb 25 '17 at 22:00
  • You say "dont roast me im new" but have you made a simple research before asking? This is a very common topic :) also, where did you learn about those `mysql_*` functions? They have been deprecated for years and don't even exist in current PHP versions. You should stop using them now and also upgrade your learning resources. Please study about [PHP Data Objects](http://php.net/manual/en/book.pdo.php), known as PDO for short. – sidyll Feb 25 '17 at 22:01
  • This was from a template and im adding onto it for personal use, thanks everyone – n0b0y Feb 25 '17 at 22:02
  • @MuhammadSaqlain i tried everything from that, and it didnt work, shall I DM you the website? – n0b0y Feb 25 '17 at 22:06
  • What you tried is not in this code. Edit the code if you have tried. – Muhammad Saqlain Feb 25 '17 at 22:09
  • @MuhammadSaqlain I made the code $newURL = 'http://.../login.php' if (mysql_num_rows($execute) == 1) { header('Location: '.$newURL); – n0b0y Feb 25 '17 at 22:12

0 Answers0