Error when setting variable inside foreach

Asked

Viewed 33 times

0

I have this piece of code in PHP. When sending to the database data images are separated by ; and the videos only put ; in the last video .

foreach($html->find('img') as $imagensdescricao) {

    $imagens1 .= $imagensdescricao->src;   
    $imagens1 = mysql_real_escape_string($imagens1.";");

}

foreach($html->find('iframe') as $videodescricao) 
    $videos1  .= $videodescricao->src;
    $videos1 = mysql_real_escape_string($videos1.";");

That’s how I’m sending:

$sqlinsert="INSERT INTO eventos ( Titulo , Preco, Imagens , Datainicio , Datafim , Descricao , Local , Hora , Videos , Imagem) VALUES ( '$Titulo' ,'$preco' , '$imagens1' , '$datainicio' , '$datafim' , '$resumo' , '$local' , '$horario' , '$videos1' ,'$imagem')";
  • This is no mistake with the database the error is that if, for, foreach without {} only allow a line and the tag phpmyadmin has no connection with the problem, phpmyadmin is a software for managing banks, it has no link with mysql or its code

1 answer

0


Well I put my mistakes here and solve right away the solution to my problem was to put {}

foreach($html->find('img') as $imagensdescricao) {

    $imagens1 .= $imagensdescricao->src;   
    $imagens1 = mysql_real_escape_string($imagens1.";");

}

foreach($html->find('iframe') as $videodescricao) {
    $videos1  .= $videodescricao->src;
    $videos1 = mysql_real_escape_string($videos1.";");}

Browser other questions tagged

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