MySQL Forums
Forum List  »  PHP

Notice: Object of class mysqli could not be converted to int in C:\wamp64\www\
Posted by: Daniel Silva Dani
Date: October 07, 2016 09:45AM

Not I write data to a form in the bank, every time I click send these errors appears:

1) Notice: Object of class mysqli could not be converted to int in C:\wamp64\www\test\salvateste.php

2)Warning: mysqli_affected_rows() expects parameter 1 to be mysqli, boolean given in C:\wamp64\www\test\salvatest.php

the pages are these:


test.php page


<Form method = "POST" action = "/ test / salvatest.php">
   <Div class = "container">
    <Div class = "form-group">
      <Label for = "name"> Name </ label>
      <Input type = "text" name = "name" id = "name" placeholder = "full name" class = "form-control" required>
      
    </ Div>
    <Div class = "form-group">
      <Label for = "name"> Email </ label>
      <Input type = "email" name = "email" id = "email" placeholder = "nome@email.com" class = "form-control" required>
      
    </ Div>
    <Div class = "form-group">
      <Label for = "phone"> Phone </ label>
      <Input type = "tel" name = "phone" id = "phone" placeholder = "home phone" class = "form-control">
    
    </ Div>
    <Div class = "form-group">
      <Label for = "phone"> Mobile </ label>
      <Input type = "tel" pattern = "^ \ d {2} - \ d {5} - \ d {4} $" name = "cell" id = "phone" placeholder = "cell phone xx-xxxxx-xxxx "class =" form-control "required>
    
    </ Div>
    <Div class = "form-group">
      <Label for = "address"> Address </ label>
      <Textarea name = "address" rows = "5" class = "form-control"> </ textarea>
    
    </ Div>
    
    <Div class = "form-group">
      <Label for = "subject"> Subject </ label>
      <Input type = "text" name = "subject" id = "subject" placeholder = "subject" class = "form-control" required>
      
    </ Div>
    <Div class = "form-group">
      <Label for = "message"> Post </ label>
      <Textarea name = "message" rows = "5" class = "form-control"> </ textarea>
    </ Div>
    <Button type = "submit" class = "btn-primary btn"> Send </ button>
   
   </ Div>
 </ Form>

Connect page connect.php

<?php
$servidor = "localhost";
$usuario = "root";
$senha = "";
$dbname = "contato";

//criando a conexao com o banco
$conn = mysqli_connect($servidor, $usuario, $senha, $dbname) or die(mysqli_error());

if (!$conn) {
printf("Não conectou ao localhost. Error: %s\n", mysqli_connect_error());
exit();
}


?>


page that saves the form: salvatest.php


<?php
include_once("conexao.php");
$nome = $_POST['nome'];
$email =$_POST['email'];
$telefone = $_POST['telefone'];
$celular = $_POST['celular'];
$endereco = $_POST['endereco'];
$assunto = $_POST['assunto'];
$mensagem = $_POST['mensagem'];

$result_msg_contato = "INSERT INTO tbl_contato (nome, email, telefone, celular, endereco, assunto, mensagem, criada) VALUES ('$nome', '$email', '$telefone', '$celular', '$endereco', '$assunto', '$mensagem') ";
$resultado_msg_contato = mysqli_query($conn,$result_msg_contato);

if (mysqli_affected_rows($conn > 0)){
echo "gravado com sucesso";
}else {
echo "erro na gravação";
}

?>

Options: ReplyQuote


Subject
Written By
Posted
Notice: Object of class mysqli could not be converted to int in C:\wamp64\www\
October 07, 2016 09:45AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.