2
I would like to know how to make this my code work to insert data in Mysql multiple way.
In the first file applies in the case a repetition of 5 items, the problem is that I do not know if I did the right 2 file that is not entering the data in SQL. I need in case when doing the rescue apply the rescue of all data placed in the 5 fields put in formulario.php
so that they are sent properly by taking all their parameters and inserting them into SQL when passed to the enviar.php
Filing cabinet formulario.php
<form id="form1" name="form1" method="post" action="/enviar.php">
<?php
$valor = 5;
for ($repeticao = 1; $repeticao <= $valor; $repeticao++) { ?>
<label>
<input name="numero2" type="text" id="numero" value="" size="10" />
</label>
<label>
</label>
<select name="cat" style="width:150px;" id="input">
<option value="--- Escolha ---" selected="selected">----- Escolha -----</option>
<?
include("/../config.php");
$select = mysql_query("SELECT * FROM `medias_subcategoria` WHERE `cat`='1' ORDER BY `nome`");
while($dados = mysql_fetch_array($select)){ ?>
<option value='<?php $dados["id"];?>><?php $dados["nome"];?></option>
<? } ?>
</select>
<? } ?>
<input type="submit" name="button" id="button" value="Enviar" />
</form>
Filing cabinet enviar.php
<?php
include("/../config.php");
$cat = $_POST["cat"];
foreach($cat as $cod => $value){
$select = mysql_query("SELECT * FROM `medias_subcategoria` WHERE `id`='".$cod."'");
$subcat = mysql_fetch_array($select);
$cat = $subcat['cat'];
$subcat = $subcat['id'];
$medias_categoria_url = $subcat['medias_categoria_url'];
$medias_subcategoria_url = $subcat['medias_subcategoria_url'];
$sql =
"insert into medias_medias (cat,subcat,medias_categoria_url,medias_subcategoria_url)
values('',
'$cat[$cod]',
'$subcat[$cod]',
'$medias_categoria_url[$cod]',
'$medias_subcategoria_url[$cod]')";
$consulta = mysql_query($sql) or die(mysql_error());
if($consulta) {
echo "<br/><center><div id=\"Aviso_ok\">Media Cadastradq com Sucesso</div></center><br/>";
}else{
echo "<br/><center><div id=\"Aviso_erro\">Erro ao Cadastrar a Media</div></center><br/>";}
} ?>
I don’t have time to answer the question itself, but just watching quickly, at least change mysql_query to mysqli_query becausemysql_* is obsolete. Another point is to mix layers.. Try to understand the basics of MVC.
– Daniel Omine
Rodrigo reversed the question to stay the original so that the answer is valid.
– Jorge B.