Firmeza
Firmeza

Reputation: 137

mysqli_stmt could not be converted to string

I am having a problem when inserting data into MySQL. This is the error, and i can't find the solution. Wheres the phpmyadmin camps and certains names in :

PHPMYADMIN - NAME:

  1. email -> email
  2. password -> pass1
  3. nome -> nome
  4. data_de_nascimeto -> data
  5. pais -> pais
  6. contribuinte -> n_contribuinte
  7. endereco -> morada
  8. codpostal -> codpostal
  9. localidade -> localidade

Register.php: (<form action="registo.php" method="get">)

<button type="submit" name="submit">Enviar</button>
</form>    
<?php
                if(isset($_GET['submit'])){
                $date = mysql_real_escape_string($_GET['data']);
                $date = date('Y-m-d', strtotime(str_replace('-', '/', $date)));
                $inst=mysqli_prepare($connect,"INSERT INTO cliente(email, password, nome, pais, contribuinte, endereco, codpostal, localidade, data_de_nascimento) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
                $pw_hash=password_hash($_GET['pass1'], PASSWORD_DEFAULT);
                $inst->bind_param("ssssissss", $_GET['email'], $pw_hash, $GET_['nome'], $_GET['pais'], $GET_['n_contribuinte'], $GET_['morada'], $GET_['codpostal'], $GET_['localidade'], $date);
                if($inst->execute()==TRUE){
                    echo '<p>Registo efetuado com sucesso</p>';
                }
                else print_r($inst);

                }
?>

EDIT: (print_r($inst);)

mysqli_stmt Object 
( 
    [affected_rows] => -1 
    [insert_id] => 0 
    [num_rows] => 0 
    [param_count] => 9 
    [field_count] => 0 
    [errno] => 1048 
    [error] => Column 'nome' cannot be null 
    [error_list] => Array( 
                            [0] => Array( 
                                            [errno] => 1048 
                                            [sqlstate] => 23000 
                                            [error] => Column 'nome' cannot be null 
                                        ) 
                         ) 
    [sqlstate] => 23000 
    [id] => 1 
)

But name is with string on input.

Upvotes: 1

Views: 1675

Answers (1)

Donovan Solms
Donovan Solms

Reputation: 961

From what I can see is you have a typo in the bind_param section of your code.

What you have:

$inst->bind_param("ssssissss", $_GET['email'], $pw_hash, $GET_['nome'], $_GET['pais'], $GET_['n_contribuinte'], $GET_['morada'], $GET_['codpostal'], $GET_['localidade'], $date);

You are calling $GET_['nome'] instead of $_GET['nome']. Notice the underscore in the wrong place. Which is why the value isn't being pulled in.

Same with $GET_['n_contribuinte'], $GET_['morada'], $GET_['codpostal'] and $GET_['localidade'].

Upvotes: 1

Related Questions