Jag försöker att få min databas att få uppgifter som id, födelsedag osv,
Registeringen funkar men databasen tar inte emot datan.
Här är bild av databasen: http://gyazo.com/3cae58c04145f7a99ee312a7d024ca23
Här en bild av definitionerna: http://gyazo.com/3b6f8ef852f69d348d1ac02096a36ea0
Här är PHP koden:
[PHP]
<?php
require_once ("Includes/simplecms-config.php");
require_once ("Includes/connectDB.php");
require_once ("Includes/session.php");
if (isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$birthday = $_POST['birthday'];
$nationality = $_POST['nationality'];
$url = $_POST['url'];
$query = "INSERT INTO users (username, password, email, phone, nationality, birthday, url) VALUES (?, SHA(?))";
$statement = $databaseConnection->prepare($query);
$statement->bind_param('ss', $username, $password, $email, $phone, $birthday, $url);
$statement->execute();
$statement->store_result();
$creationWasSuccessful = $statement->affected_rows == 1 ? true : false;
if ($creationWasSuccessful)
{
$userId = $statement->insert_id;
$addToUserRoleQuery = "INSERT INTO users_in_roles (user_id, role_id) VALUES (?, ?)";
$addUserToUserRoleStatement = $databaseConnection->prepare($addToUserRoleQuery);
// TODO: Extract magic number for the 'user' role ID.
$userRoleId = 2;
$addUserToUserRoleStatement->bind_param('dd', $userId, $userRoleId);
$addUserToUserRoleStatement->execute();
$addUserToUserRoleStatement->close();
$_SESSION['userid'] = $userId;
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['phone'] = $phone;
$_SESSION['birthday'] = $birthday;
$_SESSION['nationality'] = $nationality;
$_SESSION['url'] = $url;
}
else
{
echo "Failed registration";
}
}
?>
[/PHP]
Här är HTML koden:
Registeringen funkar men databasen tar inte emot datan.
Här är bild av databasen: http://gyazo.com/3cae58c04145f7a99ee312a7d024ca23
Här en bild av definitionerna: http://gyazo.com/3b6f8ef852f69d348d1ac02096a36ea0
Här är PHP koden:
[PHP]
<?php
require_once ("Includes/simplecms-config.php");
require_once ("Includes/connectDB.php");
require_once ("Includes/session.php");
if (isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$birthday = $_POST['birthday'];
$nationality = $_POST['nationality'];
$url = $_POST['url'];
$query = "INSERT INTO users (username, password, email, phone, nationality, birthday, url) VALUES (?, SHA(?))";
$statement = $databaseConnection->prepare($query);
$statement->bind_param('ss', $username, $password, $email, $phone, $birthday, $url);
$statement->execute();
$statement->store_result();
$creationWasSuccessful = $statement->affected_rows == 1 ? true : false;
if ($creationWasSuccessful)
{
$userId = $statement->insert_id;
$addToUserRoleQuery = "INSERT INTO users_in_roles (user_id, role_id) VALUES (?, ?)";
$addUserToUserRoleStatement = $databaseConnection->prepare($addToUserRoleQuery);
// TODO: Extract magic number for the 'user' role ID.
$userRoleId = 2;
$addUserToUserRoleStatement->bind_param('dd', $userId, $userRoleId);
$addUserToUserRoleStatement->execute();
$addUserToUserRoleStatement->close();
$_SESSION['userid'] = $userId;
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['phone'] = $phone;
$_SESSION['birthday'] = $birthday;
$_SESSION['nationality'] = $nationality;
$_SESSION['url'] = $url;
}
else
{
echo "Failed registration";
}
}
?>
[/PHP]
Här är HTML koden:
HTML-kod:
<! DOCTYPE html> <html> <head> <meta name="keywords" content=""> <meta name="description" content=""> <meta name="author" content=""> <link rel="stylesheet" href="styles/global-style.css"> <link rel="stylesheet" href="styles/font-face.css"> <link rel="stylesheet" href="styles/input.css"> <link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> <link href='http://fonts.googleapis.com/css?family=Schoolbell' rel='stylesheet' type='text/css'> <title>the point</title> </head> <body> <div id="register"> <div id="logo">The Point</div> <form action="register.php" method="post" autocomplete="off"> <div id="label">Username:</div> <div id="input"><input type="text" name="username" id="username"></div> <div id="label">Password:</div> <div id="input"><input type="password" name="password" id="password"></div> <div id="label">Email:</div> <div id="input"><input type="email" name="email" id="email"></div> <div id="label">Phone:</div> <div id="input"> <input type="tel" name="tel" id="tel" maxlength="3"> <span>-</span> <input type="tel" name="tel" id="tel" maxlength="3"> <span>-</span> <input type="tel" name="tel" id="tel" maxlength="3"> </div> <div id="label">Birthday:</div> <div id="input"> <input type="tel" name="birth" maxlength="2" placeholder="MM"> <span>-</span> <input type="tel" name="birth" maxlength="2" placeholder="DD"> <span>-</span> <input type="tel" name="birth" maxlength="2" placeholder="YY"> </div> <div id="label">Nationality:</div> <div id="input"><input type="text" name="nationality" id="nationality"></div> </div> <div id="label">URL:</div> <div id="input"> <span id="url">http://www.thepoint.com/user/</span> <input type="text" name="url" id="url" placeholder="user-id"> </div> <input type="submit" name="submit" id="submit" value="Register"> <input type="reset" name="reset" id="reset" value="Reset"> </form> <span id="content"> More info <a href="http://www.example.com" id="link">here</a> or login <a href="http://localhost:8080/login.php" id="link">here</a>! </span> </div> </body> </html>