Reputation: 9
I'm not sure if i'm approaching this right, I'm attempting to store my registeration in an public class, (if that even make sense), anyways, here is my code and it's giving me an
unexpected T_PUBLIC error
.
Am i suppose to put my action="" and link it with my class/register.php ?
register.php
<?php session_start();?>
<a href="index.php">Home</a>
<hr><br />
<h1>Register</h1>
<form action="class/register.php" method="post">
<input type="text" name="username" placeholder="username"><br />
<input type="password" name="password" placeholder="password"><br />
<input type="submit" value="register">
</form>
class/register.php
<?php
public function register($username, $password){
require 'core/connect.php';
$query = $dbConnect()->prepare("INSERT INTO `users` (username, password) VALUES(:username, :password)");
$query->bindParam(':username', $_POST['username']);
$query->bindParam('password', $_POST['password']);
if($query->execute()){
header('Location: Header.php');
} else {
echo 'There has been an error.';
}
}
?>
Upvotes: 0
Views: 44
Reputation: 69
Use this :
<?php
function register($username, $password){
require 'core/connect.php';
$query = $dbConnect()->prepare("INSERT INTO `users` (username, password) VALUES(:username, :password)");
$query->bindParam(':username', $_POST['username'],PDO::PARAM_STR);
$query->bindParam(':password', $_POST['password'],PDO::PARAM_STR);
if($query->execute()){
header('Location: Header.php');
} else {
echo 'There has been an error.';
}
}
?>
Upvotes: 0
Reputation: 68526
Since you are not using any class
( Not able to find any include
or require
after the <?php
tag ), then just remove the public
keyword from your function definition.
Just
function register($username, $password){
will do
instead of
public function register($username, $password){
Upvotes: 1