0

Im having some trouble with the following code that my tutor had provided however ive been having some trouble with getting it working.

Im getting this error:

"invalid object or resource mysqli_stmt"

This is my code, it grabs the data from a text input from a previous html file that this PHP file is assigned to, it should then send the data to my database:

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
//Report all errors or strict errors

//<USERNAME> and <PASSWORD> are temporary for this post.
$database = mysqli_connect("localhost", "<USERNAME>", "<PASSWORD>") or
die ('Unable to connect. Check connection params');


$userName = $_POST['userName'];
$password = $_POST['password'];
$emailAddress = $_POST['emailAddress'];

if ($database != FALSE)
{
print "Connection to the database made successfully.";
echo $userName;
echo $password;
echo $emailAddress;
$query = "INSERT INTO customerData(userName, password, emailAddress) VALUES     (?,?,?)";
$stmt = mysqli_stmt_init($database);
mysqli_stmt_prepare($stmt, $query);
mysqli_stmt_bind_param($stmt, 'isii', $userNamename, $password, $emailAddress);
mysqli_stmt_execute($stmt);
print "user added.";
} 

?>

2 Answers 2

1

Not sure what is wrong with the script.

if($database != FALSE)

Could easily be

if($database)
Sign up to request clarification or add additional context in comments.

1 Comment

I think you mean if($database)
0

mysqli_stmt_bind_param($stmt, 'isii', $userNamename, $password, $emailAddress);

'isii' is specifying one too many items.

I think you meant:

mysqli_stmt_bind_param($stmt, 'sss', $userNamename, $password, $emailAddress);

Reference: http://us.php.net/manual/en/mysqli-stmt.bind-param.php#refsect1-mysqli-stmt.bind-param-parameters

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.