Reputation: 385
I tried to put data from a form into a database. But I get a parse error saying that it cant find the function newuserid(). That function is ment to get latest userid in the database and than do +1 for a new user.
Why is this not working? I can't seem to find anything about this on the internet.
Here is a code snippet:
/**
* newuserid - Creates a userid for every user, to link up to other services
*/
function newuserid() {
//Get latest userid
$q = "SELECT userid FROM blog_users ORDER BY userid DESC LIMIT 1";
$latest_userid = mysqli_query($this->connection, $q);
$userid = $latest_userid + 1;
return $userid;
}
/**
* addNewUser - Inserts the given (username, password, email)
*/
function addNewUser($userdata){
//Account
$username = $userdata['username'];
$password = $userdata['password'];
//Personal Information
$first_name = $userdata['first_name'];
$last_name = $userdata['last_name'];
$bdate = $userdata['bdate'];
//Address
$address = $userdata['address'];
$street_number = $userdata['street_number'];
$city = $userdata['city'];
$postal_code = $userdata['postalcode'];
//Phone & Email
$email = $userdata['email'];
$phone = $userdata['phone'];
$userid = newuserid();
$q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '$userid', '$first_name', '$last_name', '$bdate', '$address', '$street_number', '$city', '$postal_code', '$email', '$phone')";
return mysqli_query($this->connection, $q);
}
Does someone know how to fix this, or recode a piece? Sorry, but i don't know alot about PHP, so I might use the wrong therms for some things.
Please help me find the problem.
Upvotes: 1
Views: 94
Reputation: 59701
Since you use $this
in your code i assume that these functions are in a class, so you would have also to use $this
to call the function like this:
$userid = $this->newuserid();
//^^^^^ If this code is in a class you have to use $this
Upvotes: 3