Error updating using array
Posted: Sun Feb 16, 2014 5:10 pm
[text]Hello Staff
I'm having trouble with my script to update records
someone could help me find the error?[/text]
[text]
Thanks to all
[/text]
I'm having trouble with my script to update records
someone could help me find the error?[/text]
Code: Select all
<form method="post">
<?
include "config.php";
$id = $_GET['id'];
$sql = "SELECT * FROM incluidos2 WHERE tipo ='Salgados' ";
$result = mysql_query($sql) or die ("Erro na consulta");
$count=mysql_num_rows($result);
while($linha=mysql_fetch_array($result)){
$id = $linha['id'];
$nome = $linha['nome'];
$tipo = $linha['tipo'];
$valor = $linha['valor'];
$unid = $linha['unid'];
$foto = $linha['foto'];
?>
<input type="hidden" name="id[]" value="<?echo $id?>" />
Unid<input type="text" name="unid[]" size="2" value="<?echo $unid?>" /><br />
<?}?>
<br />
<input type="submit" value="Registrar" />
<br /><br />
</form>
<?php
if (isset($_POST['id'])) {
$id = $_POST['id'];
$sql = "UPDATE incluidos2 SET unid = '$unid' WHERE id = '$id' ";
$result = mysql_query($sql) or die( mysql_error());
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=teste.php\">";
}
}
mysql_close();
?>
Thanks to all
[/text]