Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5972999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:44:18+00:00 2026-05-22T20:44:18+00:00

I made a php code for insert data on mysql. if(isset($_POST[‘submitted’])){ $img = NULL;

  • 0

I made a php code for insert data on mysql.

if(isset($_POST['submitted'])){

$img = NULL;
if(isset($_FILES['upload'])){

    include('classes/imagens.class.php');   
    $imagem = new imagem($_FILES['upload']['name'],$_FILES['upload']['tmp_name'],$_FILES['upload']['size'],$_FILES['upload']['error']);

            if($imagem->verifica_extensao($_FILES['upload']['type']) && $imagem->verifica_tamanho()){
                $erro = $imagem->upload();   
                $img = $imagem->getNome(); 
            }              

}

$trimmed = array_map('trim', $_POST); // usa a função trim() em todas as variáveis POST
$tit = $cat = $dat = $end = $des = $pr = $dono = $hor = FALSE; // atribui falso para as variaveis que poderão receber as variaveis POST

    $mysql = new mysql('eventos');

if(!empty($trimmed['nome'])){
    $tit = $mysql->escape_string($trimmed['nome']);
}

    if(!empty($trimmed['categoria'])){
    $cat = $mysql->escape_string($trimmed['categoria']);
}

    if(!empty($trimmed['data'])){
    $dat = $mysql->escape_string($trimmed['data']);
}

if($trimmed['hora'] != '--' && $trimmed['minuto'] != '--'){
            $hor = $trimmed['hora'].":".$trimmed['minuto'];
    $hor = $mysql->escape_string($hor);
}

if(!empty($trimmed['endereco'])){
    $end = $mysql->escape_string($trimmed['endereco']);
}

    if(!empty($trimmed['descricao'])){
    $des = $mysql->escape_string($trimmed['descricao']);
}

    if(!empty($trimmed['preco'])){
    $pr = $mysql->escape_string($trimmed['preco']);
}

    $dono = $_SESSION['user_id'];


   if($tit && $cat && $dat && $end && $des && $pr && $dono && $hor){

        $evento = new evento($tit, $cat, $end, $dat, $hor, $des, $pr, NULL, NULL, $img,$dono, NULL, NULL);
        $evento->cadastrar();
        echo '<h3>Evento cadastrado com sucesso!</h3>';
        echo "<a href=".BASE_URL."><h1>Clique aqui para voltar para a página inicial</h1></a>";
    exit();     
   }

    }   

and my function cadastrar()

function cadastrar(){
    $this->mysql->sql("INSERT INTO eventos (nome, categoria, data, endereco, descricao,ref_imagem,preco,user_id, hora, data_registro) VALUES ('$this->Titulo','$this->Categoria','$this->Data','$this->Endereco','$this->Descricao','$this->RefImagem','$this->Preco','$this->Dono','$this->Horario',NOW())");
}

and my function sql()

function sql($query){
            $this->connect();
            $this->query = $query;
            if(mysqli_query($this->dbc,$this->query)){
                    $linhas_afetadas = mysqli_affected_rows($this->dbc);
                    echo $query;
                    $this->result=mysqli_query($this->dbc,$this->query);
                    $this->disconnect();
                    $retorno = array($this->result,$linhas_afetadas);
                    return $retorno;
            } else {
                    die("Ocorreu um erro ao executar a Query SQL abaixo:<br>$query");
                    $this->disconnect();
            }

    }

and… the result is 2 same columns on the table.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:44:18+00:00Added an answer on May 22, 2026 at 8:44 pm

    Every time you call mysqli_query, a query is launched to the database. You are doing that twice:

    if (mysqli_query(...))
    {
        ....
        $this->result = mysqli_query(...);
    }
    

    So that’s why you end with duplicated data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a site with classic php and mysql functions. I order to
The data for the SQL db used in my PHP code comes from an
I am getting varied results with some PHP code I have written to upload
I have made a subdomain and uploaded php script on that. but php code
I made this piece of php code which grabs a RSS feed, but I'm
This is sample PHP code I made to hash a string. Does this method
how made in PHP from format 52.593800, 21.448850 format +52° 35' 37.68, +21° 26'
I'm using a Google Analytics API Class in PHP made by Doug Tan to
I had made some questions regarding PHP-GTK (there are only 4 php-gtk tagged questions
I have a website built in PHP 4 with a framework made by hand

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.