What’s wrong with this code?

Asked

Viewed 119 times

1

What is the error of this code?

( ! ) Parse error: syntax error, Unexpected '$obj' (T_VARIABLE), expecting Function (T_FUNCTION) in C: wamp www php index.php on line 53

<?php

class Aluga {

public $nome;
public $snome;
public $cpf;
public $rg;
public $tel;
public $email;
public $status;
public $datainicio;
public $datafim;
public $qntpessoas;

function __construct($nome,$snome,$cpf,$rg,$tel,$email,$datainicio,$datafim,$qntpessoas){

$this->nome = $nome;
$this->snome = $snome;
$this->cpf = $cpf;
$this->rg = $rg;
$this->tel = $tel;
$this->email = $email;
$this->status = 0;
$this->datainicio = $datainicio;
$this->datafim = $datafim;
$this->qntpessoas = $qntpessoas;
}

function enviarDados(){

    $sql = 'INSERT INTO `alugueis`(`nome`, `snome`, `cpf`, `rg`, `tel`, `email`, `status`, `datainicio`, `datafim`, `qntpessoas`) VALUES (?,?,?,?,?,?,?,?,?,?)';

    $pdo = new PDO("mysql:host=localhost;dbname=test;","root", "");

    $stmt = $pdo->prepare($sql);

    $stmt->bindValue(1, $this->nome);
    $stmt->bindValue(2, $this->snome);
    $stmt->bindValue(3, $this->cpf);
    $stmt->bindValue(4, $this->rg);
    $stmt->bindValue(5, $this->tel);
    $stmt->bindValue(6, $this->email);
    $stmt->bindValue(7, $this->status);
    $stmt->bindValue(8, $this->datainicio);
    $stmt->bindValue(9, $this->datafim);
    $stmt->bindValue(10, $this->qntpessoas);

    $stmt->execute();
}


$obj = new Aluga("1","2","3","4","5","7","8","9","10");
$obj->enviarDados();


?>

1 answer

0


You forgot to close the class opening, missing one } in the end.

<?php

class Aluga {
    public $nome;
    public $snome;
    public $cpf;
    public $rg;
    public $tel;
    public $email;
    public $status;
    public $datainicio;
    public $datafim;
    public $qntpessoas;

    function __construct($nome,$snome,$cpf,$rg,$tel,$email,$datainicio,$datafim,$qntpessoas){
        $this->nome = $nome;
        $this->snome = $snome;
        $this->cpf = $cpf;
        $this->rg = $rg;
        $this->tel = $tel;
        $this->email = $email;
        $this->status = 0;
        $this->datainicio = $datainicio;
        $this->datafim = $datafim;
        $this->qntpessoas = $qntpessoas;
    }

    function enviarDados(){
        $sql = 'INSERT INTO `alugueis`(`nome`, `snome`, `cpf`, `rg`, `tel`, `email`, `status`, `datainicio`, `datafim`, `qntpessoas`) VALUES (?,?,?,?,?,?,?,?,?,?)';
        $pdo = new PDO("mysql:host=localhost;dbname=test;","root", "");
        $stmt = $pdo->prepare($sql);

        $stmt->bindValue(1, $this->nome);
        $stmt->bindValue(2, $this->snome);
        $stmt->bindValue(3, $this->cpf);
        $stmt->bindValue(4, $this->rg);
        $stmt->bindValue(5, $this->tel);
        $stmt->bindValue(6, $this->email);
        $stmt->bindValue(7, $this->status);$stmt->bindValue(8, $this->datainicio);$stmt->bindValue(9, $this->datafim);$stmt->bindValue(10, $this->qntpessoas);

        $stmt->execute();
    }
}

$obj = new Aluga("1","2","3","4","5","7","8","9","10");
$obj->enviarDados();
?>
  • vlw msm xDD am well Noob that kk' I was so focused on the "$obj" that I ended up n looking if something was missing

  • @Lucas Acontece . If possible mark the answer as accepted. =)

  • Marked :) But Aki, can you tell me have any risk of sql Injection in this code? : P

  • @Lucas The risk will always have, but using PDO already greatly decreases the possibilities. Take a look too in this question =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.