1
Hello would like to know how I can change code of area 1 of insert
using the foreach($nome as $cod => $value)
other than the code of area 2
I’m unable to make an adaptation by changing the mode of insert
of Code 2 in such a way that foreach($nome as $cod => $value)
work.
Code 1
mysql_query("INSERT INTO `episodios` SET `nome`='".$_POST["nome"]."',`media`='".$_POST["media"]."',`tamanho`='".$_POST["tamanho"]."',`tipo`='".$_POST["tipo"]."'")
Code 2
$nome = $_POST['nomes'];
$anime = $_POST['animes'];
$tamanho = $_POST['tamanhos'];
$tipo = $_POST['tipo'];
foreach($nome as $cod => $value){
$sql = "insert into episodios (id,nome,anime,tamanho,tipo) values ('','$nome[$cod]','$anime[$cod]','$tamanho[$cod]','$tipo')";
$consulta = mysql_query($sql) or die(mysql_error());
if($consulta) {
echo "<br/><center><div id=\"Aviso_ok\">Episodio Cadastrado com Sucesso</div></center><br/>";
}else{
echo "<br/><center><div id=\"Aviso_erro\">Erro ao Cadastrar o Episodio</div></center><br/>";}
}
What’s the problem? What you can’t do?
– Maniero
I don’t understand the doubt either.
– Jorge B.
I want to use in the case the foreach($name the $Cod => $value) in the code 1 only I’m not sure how to do the Adptation
– Striffer
It’s the same instead of
$_POST["nome"]
you use the$nome[$cod]
– Jorge B.
Minutes thanks for the help
– Striffer
beware of sqlinjection.
– Rui Lima
Only one thing besides having that by so $name[Cod] I have to put in case the $name = $_POST['names']; and the other post values in code 1 since I will replace the $_POST[' ']; at the beginning of code 1 for the post values to be applied ?
– Striffer
Yes that’s what it is
– Jorge B.
Look like @Ruilima said you have to be careful with SQL Injection. You should wear
mysqli_
instead ofmysql_
and use Prepared statements.– Jorge B.
Okay that there in case avoids the use of havij ?
– Striffer
You can still use it to test...
– Jorge B.
Just one more question when it is applied that $name[$Cod] in the code applies the value of $_POST["name"] taken from the right array ? Ai in this case would act as a definition in Where ex Where name='." $name[$Cod]". 'so do ai in the example sort items at least name since it is inside the foreach loop($name as $Cod => $value){ } of the code in question ?
– Striffer
In this case $Select2 = mysql_query("SELECT * FROM
listas
WHEREnome
='".name[Cod]". '"); $dads2 = mysql_fetch_array($Select2);– Striffer