I'm trying to write a registration form, firstly I tried to do it OO, but this didn't respond, it seemed to just clear the form and refresh the page, but didn't insert any data:
EDIT: Current code:
<?php
session_start();
include 'registrationform.php';
include 'connection.php';
if (isset($_POST['regsubmit']))
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$user = $_POST['username'];
$pass = $_POST['password'];
$query = "INSERT INTO users (firstname, lastname, username, password) VALUES(?, ?, ?, ?)";
$statement = $connection->prepare($query);
//bind parameters for markers, where (s = string, i = integer, d = double, b = blob)
$statement->bind_param('ssss', $firstname, $lastname, $username, $password);
if($statement->execute()){
print 'Success! ID of last inserted record is : ' .$statement->insert_id .'<br />';
//$_SESSION['username'] = $_POST['username'];
}else{
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$statement->close();
?>
Registration Form
<!DOCTYPE html>
<?php
include 'header.php';
?>
<center>
<html>
<link rel="stylesheet" type="text/css" href="web.css" />
</font>
<head>
</head>
<body>
<div id="registrationform">
Please enter your registration details<br /><br />
<form method="post" action="registrationsubmit.php">
First Name:
<input type="text" name="firstname" />
<br /><br>
Last Name:
<input type="text" name="lastname" />
<br /><br>
Username:
<input type="text" name="username" />
<br /><br>
Password:
<input type="text" name="password" />
<br /><br>
<input type="submit" name="regsubmit" value="Submit" />
</form>
</div>
</body>
</html>
</center>
OO Attempt
<?php
session_start();
include 'registrationform.php';
include 'connection.php';
if (isset($_POST['regsubmit']))
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$user = $_POST['username'];
$pass = $_POST['password'];
$stmt = $connection->prepare("INSERT INTO users VALUES (?, ?, ?, ?)");
$stmt->bind_param('ssss', $firstname, $lastname, $user, $pass);
$stmt->execute();
printf("%d Row inserted.\n", $stmt->affected_rows);
$stmt->close();
}
?>
As this wasn't working I tried just doing it without OO, for a starting point. But now I'm given the error "Access denied for user ''@'10.246.64.24' (using password: NO)", yet my connection connects fine and I've also written a login that works perfectly so can't figure it out. Here is the current code that I have:
registrationsubmit.php
<?php
include "connection.php";
include "header.php";
if(isset($_POST['regsubmit']))
{
mysql_select_db("c3438525_co_uk",$connection);
$firstname = $_POST['$firstname'];
$lastname = $_POST['$lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
$query = "INSERT INTO users (FirstName, LastName, Username, Password) VALUES ('$firstname', '$lastname', '$username', '$password')";
$data = mysql_query ($query)or die(mysql_error());
if($data) { echo "Successfully Registered"; }
else
{
?>
<script>alert('error while registering you...');</script>
<?php
}
}
?>
Connection.php
<?php
ob_start();
$connection = mysqli_connect("***", "***", "BFUWGpn3", "***");
?>