I need to, select data from a table and then make changes and update is the same tabele and another table.

Right now my code is very simple and is giving some erros, right now, he just search the table. can you hepl me?

<?php
//conecção ao servidor
mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");

$nordem = $_POST['nordem']; 

$query="SELECT * FROM entrada where nordem_n = '" . mysql_real_escape_string($nordem) . "'";
mysql_query ($query) or die(mysql_error());
$result=mysql_query($query);


$query1="SELECT * FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
mysql_query ($query1) or die(mysql_error());
$result1=mysql_query($query1);

$num = mysql_num_rows($result);
mysql_close();
?>
<?php
$o1= mysql_result($result1,"data");
$o2= mysql_result($result1,"nordem");
$o3= mysql_result($result1,"fornecedor");
$o4= mysql_result($result1,"guian");
$o5= mysql_result($result1,"ncliente");
$o6= mysql_result($result1,"cliente");
?>


<FORM>
<INPUT TYPE="button" value="Imprimir" onClick="window.print()">
</FORM>
<table><tr>
 <td><h1>Data:</h1></td><h1><?php echo $o1; ?></h1></td>
 <td><h1>N.º Ordem:</h1>  </td>  <td><?php echo $o2; ?></td>
 <td><h1>Fornecedor:</h1> </td> <td><?php echo $o3; ?></td>
 <td> <h1>Guia n.º:</h1>   </td> <td><?php echo $o4; ?></td>
 </TR>
<tr>
 <td><h1>N.º Cliente:</h1></td><td><?php echo $o5; ?></td>
 <td><h1>Cliente:</h1>        </td>    <td><?php echo $o6; ?></td>
</tr></table>
<table>
<tr><td width="80%"></TD><td><img src="imas/sermailpb.png"></td></tr></table>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td><font face="Arial, sans-serif">N.º Ordem</font></td>
<td><font face="Arial, sans-serif">Codigo </br>Produto</font></td>
<td><font face="Arial, sans-serif">Codigo Cliente </br>1-Lote</font></td>
<td><font face="Arial, sans-serif">Codigo Cliente </br>2-Validade</font></td>
<td><font face="Arial, sans-serif">Designacao</font></td>
<td><font face="Arial, sans-serif">Filtro</font></td>
<td><font face="Arial, sans-serif">Familia Marca</font></td>
<td><font face="Arial, sans-serif">Quant Guia</font></td>
<td><font face="Arial, sans-serif">Quant Conferida</font></td>
<td><font face="Arial, sans-serif">Atado</font></td>
<td><font face="Arial, sans-serif">Posicao</font></td>
</tr>

<?php
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"nordem_n");
$f2=mysql_result($result,$i,"codprod");
$f3=mysql_result($result,$i,"lote");
$f4=mysql_result($result,$i,"val");
$f5=mysql_result($result,$i,"designacao");
$f6=mysql_result($result,$i,"filtro");
$f7=mysql_result($result,$i,"familiamarca");
$f8=mysql_result($result,$i,"quantguia");
$f9=mysql_result($result,$i,"quantconf");
$f10=mysql_result($result,$i,"atado");
$f11=mysql_result($result,$i,"posicao");
?>
<style type="text/css" media="print">
   .button {
   visibility: hidden;  
   display: none;
   size: Landscape;
   } 
   </style>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f6; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f7; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f8; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f9; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f10; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f11; ?></font></td>

</tr>

<?php
$i++;
}
?>




the output:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'nordem_n = '1'' at line 1

Seems like there could be 2 errors:
Either the name of the colum you are trying to access is in capital letters i.e. mySql is little jealous of the case in which the names are written so check the name of the column, does it is same as you have declared in the Database table or not..

Another one is, you should cost one more variable
like:
$escaped=mysql_real_escape_string($noredem);
$query=mysql_query("Select * from ordem Where nordem='$escaped'");
if(!query)
die('Cant access DB');
else
-----> Anything you like goes here..
Dron Rathore

that could be a solution to the select query, however, I'm using this, and almost works, at least i can see the list of one table..
`

<?php
//conecção ao servidor
mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");

$nordem = $_POST['nordem']; 

$query="SELECT * FROM entrada where nordem_n = '" . mysql_real_escape_string($nordem) . "'";
mysql_query ($query) or die(mysql_error());
$result=mysql_query($query);


$result1="SELECT data FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$data=mysql_query($result1)or die(mysql_error());

$result2="SELECT nordem FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$nordem1=mysql_query($result2) or die(mysql_error());

$result3="SELECT fornecedor FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$fornecedor=mysql_query($result3) or die(mysql_error());

$result4="SELECT guian FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$guian=mysql_query($result4) or die(mysql_error());

$result5="SELECT ncliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$ncliente= mysql_query($result5) or die(mysql_error());

$result6="SELECT cliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$cliente=mysql_query($result6) or die(mysql_error());

$num = mysql_num_rows($result);
mysql_close();
?>

`

all the fields os table ordem, have the same mysql_error, resource Id #**
why?

You need to fetch the results. mysql_query returns a resource, not a value. Apart from that, you can get all values in a single query.

like this?

$result1="SELECT data FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
mysql_fetch_array($o1);

maybe not, it output the same resource id#, i supose it's my fault. but where?

if ($row = mysql_fetch_array($o1)) {
    echo $row['data'];
}
else {
    echo 'No record found';
}

thanks priateas...again you saved me!

it's workin properly.

now we've reached the real question.
i have check boxes and a uptdate button, i wan to change the checked row of the table, witch statmente should I use to do it?

i think that maybe better if I use a second php file with a include, but don´t know wath statementes or funcions to put in...

Made changes, only missing, the working sumit button..

<?php
//conecção ao servidor
mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");

$nordem = $_POST['nordem']; 

$query="SELECT * FROM entrada where nordem_n = '" . mysql_real_escape_string($nordem) . "'";
$result=mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);

if (!$result) {
    $message  = 'N.º de Ordem inexistente ' . mysql_error() . "\n";
    die($message);
}




$result2="SELECT nordem FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o2=mysql_query($result2) or die(mysql_error());


$result3="SELECT fornecedor FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o3=mysql_query($result3) or die(mysql_error());


$result4="SELECT guian FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o4=mysql_query($result4) or die(mysql_error());


$result5="SELECT ncliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o5= mysql_query($result5) or die(mysql_error());


$result6="SELECT cliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o6=mysql_query($result6) or die(mysql_error());


mysql_close();
?>
<?php
//$o1= mysql_result($result1,"data");
//$o2= mysql_result($result1,"nordem");
//$o3= mysql_result($result1,"fornecedor");
//$o4= mysql_result($result1,"guian");
//$o5= mysql_result($result1,"ncliente");
//$o6= mysql_result($result1,"cliente");
?>


<FORM>
<INPUT TYPE="button" value="Imprimir" onClick="window.print()">
</FORM>
<table><tr>
 <td><h1>Data:</h1></td>          <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT data FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['data'];
    }
    else {
    echo 'No record found';
    }
    ?>

 <td><h1>N.º Ordem:</h1>   </td>  <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT nordem FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['nordem'];
    }
    else {
    echo 'No record found';
    }
    ?></td>
 <td><h1>Fornecedor:</h1>  </td>  <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT fornecedor FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['fornecedor'];
    }
    else {
    echo 'No record found';
    }
    ?></td>
 <td> <h1>Guia n.º:</h1>   </td>  <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT guian FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['guian'];
    }
    else {
    echo 'No record found';
    }
    ?></td>
 </TR>
<tr>
 <td><h1>N.º Cliente:</h1> </td>  <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT ncliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['ncliente'];
    }
    else {
    echo 'No record found';
    }
    ?></td>
 <td><h1>Cliente:</h1>     </td>  <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT cliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['cliente'];
    }
    else {
    echo 'No record found';
    }
    ?></td>
</tr></table>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td><font face="Arial, sans-serif">N.º Ordem</font></td>
<td><font face="Arial, sans-serif">Codigo </br>Produto</font></td>
<td><font face="Arial, sans-serif">Codigo Cliente </br>1-Lote</font></td>
<td><font face="Arial, sans-serif">Codigo Cliente </br>2-Validade</font></td>
<td><font face="Arial, sans-serif">Designacao</font></td>
<td><font face="Arial, sans-serif">Filtro</font></td>
<td><font face="Arial, sans-serif">Familia Marca</font></td>
<td><font face="Arial, sans-serif">Quant Guia</font></td>
<td><font face="Arial, sans-serif">Quant Conferida</font></td>
<td><font face="Arial, sans-serif">Atado</font></td>
<td><font face="Arial, sans-serif">Posicao</font></td>
<td><input type="submit" class="printbutton" value="Alterar entrada" onclick = "window.new(formulario.html)" ></td>
</tr>

<?php
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"nordem_n");
$f2=mysql_result($result,$i,"codprod");
$f3=mysql_result($result,$i,"lote");
$f4=mysql_result($result,$i,"val");
$f5=mysql_result($result,$i,"designacao");
$f6=mysql_result($result,$i,"filtro");
$f7=mysql_result($result,$i,"familiamarca");
$f8=mysql_result($result,$i,"quantguia");
$f9=mysql_result($result,$i,"quantconf");
$f10=mysql_result($result,$i,"atado");
$f11=mysql_result($result,$i,"posicao");
?>
<style type="text/css" media="print">
   .button {
   visibility: hidden;  
   display: none;
   size: Landscape;
   } 
   </style>
<tr>
<td><input type=text name="nordem_n" value="<?php  echo $f1; ?>"></font></td>
<td><input type=text name="codprod" value="<?php echo $f2; ?>"></font></td>
<td><input type=text name="lote" value="<?php echo $f3; ?>"></font></td>
<td><input type=text name="val" value="<?php echo $f4; ?>"></font></td>
<td><input type=text name="designacao" value="<?php echo $f5; ?>"></font></td>
<td><input type=text name="filtro" value="<?php echo $f6; ?>"></font></td>
<td><input type=text name="familiamarca" value="<?php echo $f7; ?>"></font></td>
<td><input type=text name="quantguia" value="<?php echo $f8; ?>"></font></td>
<td><input type=text name="quantconf" value="<?php echo $f9; ?>"></font></td>
<td><input type=text name="atado" value="<?php echo $f10; ?>"></font></td>
<td><input type=text name="posicao" value="<?php echo $f11; ?>"></font></td>
<td><input class="printbutton" type="checkbox" name="check[]"  value="1"  /></td>

</tr>

<?php
$i++;
}
?>

I've made it connects to another php file, where the code is:

  <?php
    //conecção ao servidor
    $conn = mysql_connect("localhost", "root")or die("sem conecção ao servidor");
    $db = mysql_select_db("sermail")or die("Base de dados não foi encontrada");
    // VAr

   //table entrada vars to update
  $lote=$_POST['lote'][$i];
  $val=$_POST['val'][$i];
  $designacao=$_POST['designacao'][$i];
  $familiamarca=$_POST['familiamarca'][$i];
  $filtro=$_POST['filtro'][$i];
  $quantguia=$_POST['quantguia'][$i];
  $guantconf=$_POST['guantconf'][$i];
  $atado=$_POST['atado'][$i];
  $posicao=$_POST['posicao'][$i];
    $sql2a = "update entrada Set lote='$lote[$i]', val=$_POST['val'][$i], designacao=$_POST['designacao'][$i],filtro=$_POST['filtro'][$i], familiamarca=$_POST['familiamarca'][$i], quantguia=$_POST['quantguia'][$i], quantconf=$_POST['quantconf'][$i], atado=$_POST['atado'][$i], posicao=$_POST['posicao'][$i], codprod=$_POST['codprod'][$i]";
    for ($i=0; $i<count($_POST['check']); $i++) {
     if ($_POST['check'][$i] == 0) continue;
        $sql2a = "update entrada Set  lote= $_POST['lote'][$i], val=$_POST['val'][$i], designacao=$_POST['designacao'][$i],filtro=$_POST['filtro'][$i], familiamarca=$_POST['familiamarca'][$i], quantguia=$_POST['quantguia'][$i], quantconf=$_POST['quantconf'][$i], atado=$_POST['atado'][$i], posicao=$_POST['posicao'][$i], codprod=$_POST['codprod'][$i]'WHERE $_POST['check'][$i] == 0";

     // $sql2a .= '(\'' . $_POST['lote'][$i] . '\', \'' . $_POST['val'][$i] . '\', \'' . $_POST['designacao'][$i] . '\', \'' . $_POST['filtro'][$i] . '\', \'' . $_POST['familiamarca'][$i] . '\', \'' . $_POST['quantguia'][$i] . '\', \'' . $_POST['quantconf'][$i] . '\', \'' . $_POST['atado'][$i] . '\', \'' . $_POST['posicao'][$i] . '\', \'' . $_POST['codprod'][$i] . '\')';
    if ($i<count($_POST['check']) - 1) {
    $sql2a .= ',';
    } 
    } 

    mysql_query($sql2a) or die(mysql_error());
    // pagina inicial, Furmolario.html
    Echo "<a href='formulario.html'>Nova ficha de entrada</a>";

    ?>
    <?php
    mysql_close();

    ?>

now it gave me an error:
( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp\www\teste\update.php on line 17

if the error is in the variables as I supose,how to identify variables in a update query?

Put them between curly brackets.

$_POST['val'][$i]

{$_POST['val'][$i]}

WHERE $_POST['check'][$i] == 0

If in the above code $_POST['check'][$i] equals zero, then ALL RECORDS in your table will be overwritten.

same error...

    //conecção ao servidor
    $conn = mysql_connect("localhost", "root")or die("sem conecção ao servidor");
    $db = mysql_select_db("sermail")or die("Base de dados não foi encontrada");
    // VAr
    //table entrada vars to update
    $lote=$_POST['lote'][$i];
    $val=$_POST['val'][$i];
    $designacao=$_POST['designacao'][$i];
    $familiamarca=$_POST['familiamarca'][$i];
    $filtro=$_POST['filtro'][$i];
    $quantguia=$_POST['quantguia'][$i];
    $guantconf=$_POST['guantconf'][$i];
    $atado=$_POST['atado'][$i];
    $posicao=$_POST['posicao'][$i];
    for ($i=0; $i<count($_POST['check']); $i++) {
    if ($_POST['check'][$i] == 0) continue;
    $sql2a = "update entrada Set lote= {$_POST['lote'][$i]}, val={$_POST['val'][$i]}, designacao={$_POST['designacao'][$i]},filtro={$_POST['filtro'][$i]}, familiamarca={$_POST['familiamarca'][$i]}, quantguia={$_POST['quantguia'][$i]}, quantconf={$_POST['quantconf'][$i]}, atado={$_POST['atado'][$i]}, posicao={$_POST['posicao'][$i]}, codprod={$_POST['codprod'][$i]}'WHERE $_POST['check'][$i] == 1";
    // $sql2a .= '(\'' . $_POST['lote'][$i] . '\', \'' . $_POST['val'][$i] . '\', \'' . $_POST['designacao'][$i] . '\', \'' . $_POST['filtro'][$i] . '\', \'' . $_POST['familiamarca'][$i] . '\', \'' . $_POST['quantguia'][$i] . '\', \'' . $_POST['quantconf'][$i] . '\', \'' . $_POST['atado'][$i] . '\', \'' . $_POST['posicao'][$i] . '\', \'' . $_POST['codprod'][$i] . '\')';
    if ($i<count($_POST['check']) - 1) {
    $sql2a .= ',';
    }
    }
    mysql_query($sql2a) or die(mysql_error());
    // pagina inicial, Furmolario.html
    Echo "<a href='formulario.html'>Nova ficha de entrada</a>";
    ?>
    <?php
    mysql_close();
    ?>

got it. error fixed

after cleaning the unnecessary lines got this code.

<?php
    //conecção ao servidor
    $conn = mysql_connect("localhost", "root")or die("sem conecção ao servidor");
    $db = mysql_select_db("sermail")or die("Base de dados não foi encontrada");

    for ($i=0; $i<count($_POST['check']); $i++) {
    if ($_POST['check'][$i] == 0) continue;
    $sql2a = "update entrada Set lote= {$_POST['lote'][$i]}, 
    val={$_POST['val'][$i]}, 
    designacao={$_POST['designacao'][$i]},
    filtro={$_POST['filtro'][$i]}, 
    familiamarca={$_POST['familiamarca'][$i]}, 
    quantguia={$_POST['quantguia'][$i]}, 
    quantconf={$_POST['quantconf'][$i]}, 
    atado={$_POST['atado'][$i]}, 
    posicao={$_POST['posicao'][$i]}, 
    codprod={$_POST['codprod'][$i]}
    WHERE {$_POST['check'][$i]} = 1";
    // $sql2a .= '(\'' . $_POST['lote'][$i] . '\', \'' . $_POST['val'][$i] . '\', \'' . $_POST['designacao'][$i] . '\', \'' . $_POST['filtro'][$i] . '\', \'' . $_POST['familiamarca'][$i] . '\', \'' . $_POST['quantguia'][$i] . '\', \'' . $_POST['quantconf'][$i] . '\', \'' . $_POST['atado'][$i] . '\', \'' . $_POST['posicao'][$i] . '\', \'' . $_POST['codprod'][$i] . '\')';
    if ($i<count($_POST['check']) - 1) {
    $sql2a .= ',';
    }
    }
    mysql_query($sql2a) or die(mysql_error());
    // pagina inicial, Furmolario.html
    Echo "<a href='formulario.html'>Nova ficha de entrada</a>";
    ?>
    <?php
    mysql_close();
    ?>

and this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' codprod=1 WHERE 1 = 1' at line 9

anyway, I tried to update th posicao field, witch is varchar, after the firs trial, that suposed went good, i've looked in the mysql db, and it have been changed but not to the value i wanted? why?

the update changes all values to 1number/letter... don't understand why

WORST of all, it changes all values in that table to the first row of data that i change...

help please

Ugh.. lets try again.. just did a long explanation, hit delete, and I lost the page... fun fun...

I shall shorten it...

iterate over your post instead of calling them directly...

mysql_connect('localhost', 'foo', 'bar');

$expected = array('check', 'lote', 'val' ....);
$inserts = array();
foreach($_POST as $key => $value) {
    if(in_array($key, $expected)) {
           if(is.... ) {                 // you have a ton of choices here. Check data 
              $inserts[$key] = mysql_real_escape_string($value);    //type, check from
                                              //inside an array... is_numeric,
               }                            //is_string....) look here for more
           }                         //http://php.net/manual/en/function.is-numeric.php
                                           //alternatively, you can run a preg_match()
      }

$sql2a = "update table entrada set ";
$i = 0;
$count = count($inserts);
foreach($inserts as $k => $v) {
$i++;
if($i < $count) {
$sql2a .= "$k = '$v', ";
}
else {
$sql2a .="$k = '$v' ";
}

$sql2a .= "WHERE ......";

$result = mysql_query($sql2a);

So... that's my suggestion... I think I got that right...

Keep in mind, that when you run your type check you can do multiple ifs, or if you are less caring about what type of data goes in jsut run if(is_foo() || is_bar() ) {} or something similar...

Ryan

Hello again.

I apreciate your help and code ryantroop, i tested it, but i can't put it to worck, but anyway, reading the code I understande that it wil not work as I wope/need. probably i make some mistake in there,I will see it.

the code:

1st file html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Pesquisar</title>
<link rel="stylesheet" type="text/css" href="styles/styles.css" />
</head>
<body bgcolor=#00814B>
<table width= "900px"> <tr><td width="600px"></td><td><img src="imas/sermaillogo.png"align="right"></Td></tr></table>
<form action="pesquisar.php" method="post">
<h1>N.º Ordem: <input type="text" name="nordem"></h1><br>

<input type="Submit" value=" Pesquisar">
</body>
</html>

2nd file php this one outputs the a table with the result of the query, this table is ment to be updated, if the check box is checked.

<style type="text/css" media="print">
   .button {
   visibility: hidden;  
   display: none;
   size: Landscape;
   } 
   </style>
<?php
//conecção ao servidor
mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");

$nordem = $_POST['nordem']; 

$query="SELECT * FROM entrada where nordem_n = '" . mysql_real_escape_string($nordem) . "'";
$result=mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);

if (!$result) {
    $message  = 'N.º de Ordem inexistente ' . mysql_error() . "\n";
    die($message);
}




$result2="SELECT nordem FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o2=mysql_query($result2) or die(mysql_error());


$result3="SELECT fornecedor FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o3=mysql_query($result3) or die(mysql_error());


$result4="SELECT guian FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o4=mysql_query($result4) or die(mysql_error());


$result5="SELECT ncliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o5= mysql_query($result5) or die(mysql_error());


$result6="SELECT cliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o6=mysql_query($result6) or die(mysql_error());


mysql_close();
?>
<?php
//$o1= mysql_result($result1,"data");
//$o2= mysql_result($result1,"nordem");
//$o3= mysql_result($result1,"fornecedor");
//$o4= mysql_result($result1,"guian");
//$o5= mysql_result($result1,"ncliente");
//$o6= mysql_result($result1,"cliente");
?>


<FORM>
<INPUT TYPE="button" value="Imprimir" onClick="window.print()">
</FORM>
<table><tr>
 <td><h1>Data:</h1></td>          <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT data FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['data'];
    }
    else {
    echo 'No record found';
    }
    ?>

 <td><h1>N.º Ordem:</h1>   </td>  <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT nordem FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['nordem'];
    }
    else {
    echo 'No record found';
    }
    ?></td>
 <td><h1>Fornecedor:</h1>  </td>  <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT fornecedor FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['fornecedor'];
    }
    else {
    echo 'No record found';
    }
    ?></td>
 <td> <h1>Guia n.º:</h1>   </td>  <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT guian FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['guian'];
    }
    else {
    echo 'No record found';
    }
    ?></td>
 </TR>
<tr>
 <td><h1>N.º Cliente:</h1> </td>  <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT ncliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['ncliente'];
    }
    else {
    echo 'No record found';
    }
    ?></td>
 <td><h1>Cliente:</h1>     </td>  <td><?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT cliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['cliente'];
    }
    else {
    echo 'No record found';
    }
    ?></td>
</tr></table>

<form action="update.php" method="post">
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td><font face="Arial, sans-serif">N.º Ordem</font></td>
<td><font face="Arial, sans-serif">Codigo </br>Produto</font></td>
<td><font face="Arial, sans-serif">Codigo Cliente </br>1-Lote</font></td>
<td><font face="Arial, sans-serif">Codigo Cliente </br>2-Validade</font></td>
<td><font face="Arial, sans-serif">Designacao</font></td>
<td><font face="Arial, sans-serif">Filtro</font></td>
<td><font face="Arial, sans-serif">Familia Marca</font></td>
<td><font face="Arial, sans-serif">Quant Guia</font></td>
<td><font face="Arial, sans-serif">Quant Conferida</font></td>
<td><font face="Arial, sans-serif">Atado</font></td>
<td><font face="Arial, sans-serif">Posicao</font></td>
<td><input type="submit" class="printbutton" value="Alterar entrada"  ></td>
</tr>

<?php
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"nordem_n");
$f2=mysql_result($result,$i,"codprod");
$f3=mysql_result($result,$i,"lote");
$f4=mysql_result($result,$i,"val");
$f5=mysql_result($result,$i,"designacao");
$f6=mysql_result($result,$i,"filtro");
$f7=mysql_result($result,$i,"familiamarca");
$f8=mysql_result($result,$i,"quantguia");
$f9=mysql_result($result,$i,"quantconf");
$f10=mysql_result($result,$i,"atado");
$f11=mysql_result($result,$i,"posicao");
?>

<tr>
<td>  <font>                                         <?php echo $f1; ?>      </font></td>
<td>  <input type=text SIZE=9  name="codprod"         value="<?php echo $f2; ?>">        </font></td>
<td>  <input type=text SIZE=6  name="lote"            value="<?php echo $f3; ?>">           </font></td>
<td>  <input type=text SIZE=6  name="val"             value="<?php echo $f4; ?>">            </font></td>
<td>  <input type=text SIZE=20  name="designacao"      value="<?php echo $f5; ?>">     </font></td>
<td>  <input type=text SIZE=8 name="filtro"          value="<?php echo $f6; ?>">         </font></td>
<td>  <input type=text SIZE=10  name="familiamarca"    value="<?php echo $f7; ?>">   </font></td>
<td>  <input type=text SIZE=6  name="quantguia"       value="<?php echo $f8; ?>">      </font></td>
<td>  <input type=text SIZE=6  name="quantconf"       value="<?php echo $f9; ?>">      </font></td>
<td>  <input type=text SIZE=6  name="atado"           value="<?php echo $f10; ?>">         </font></td>
<td>  <input type=text SIZE=6  name="posicao"         value="<?php echo $f11; ?>">       </font></td>
<td>  <input class="printbutton" type="checkbox" name="check[]"  value="1"  /></td>

</tr>

<?php
$i++;
}
?>
</table>
</form>

3th file php, it's suposed to update the checked rows, send the data to the db.

<?php
    //conecção ao servidor
    $conn = mysql_connect("localhost", "root")or die("sem conecção ao servidor");
    $db = mysql_select_db("sermail")or die("Base de dados não foi encontrada");

    //update

    $sql2a = "UPDATE entrada SET  ";
    for ($i=0; $i<count($_POST['check']); $i++) {
        if ($_POST['check'][$i] == 0) continue;
    $sql2a .="
    codprod={$_POST['codprod'][$i]},
    lote= {$_POST['lote'][$i]}, 
    val={$_POST['val'][$i]}, 
    designacao={$_POST['designacao'][$i]},
    filtro={$_POST['filtro'][$i]}, 
    familiamarca={$_POST['familiamarca'][$i]}, 
    quantguia={$_POST['quantguia'][$i]}, 
    quantconf={$_POST['quantconf'][$i]}, 
    atado={$_POST['atado'][$i]}, 
    posicao={$_POST['posicao'][$i]}"
    ;

    //$sql2a .=WHERE {$_POST['check'][$i]} = 1";
    // $sql2a .= '(\'' . $_POST['lote'][$i] . '\', \'' . $_POST['val'][$i] . '\', \'' . $_POST['designacao'][$i] . '\', \'' . $_POST['filtro'][$i] . '\', \'' . $_POST['familiamarca'][$i] . '\', \'' . $_POST['quantguia'][$i] . '\', \'' . $_POST['quantconf'][$i] . '\', \'' . $_POST['atado'][$i] . '\', \'' . $_POST['posicao'][$i] . '\', \'' . $_POST['codprod'][$i] . '\')';
    if ($i<count($_POST['check']) - 1) {
    $sql2a .= ',';
    $sql2a .="WHERE {$_POST['check'][$i]} = 1";
    }
    }
    mysql_query($sql2a) or die(mysql_error());
    echo $sql2a;echo"</br>";
    // pagina inicial, update.html
    Echo "<a href='pesquisar.html'>Nova pesquisa</a>";
    ?>  
    <?php
    mysql_close();
    ?>

The output of all this is:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 1 = 1 codprod=6, lote= 6, val=1, designacao=4, filtro=4, familiam' at line 11"

as usual, I understand where the error is, but can't find it.. NEED HHELLPP pleaze

after corrected the code, another problem apears, he changes all rows in the table instead of only the checked ones or even only those returned by the query. he changes all the table.

I still think you are using $_POST a bit...awkwardly...

I also think youre using MySQL very ineffeciently... you can make combined queries, I feel, for much of what you are doing.

However, line 28 is the only query that matches your error. On line 27 and 28, your comma is being placed improperly, I think... to double check, change line 31 to:

mysql_query($sql2a) or die("THIS IS MY ERROR!");

If you get that message, then you need to change your iteration, and make it happen one step earlier.

Ryan

you are right, i'm new to php and mysql, that's why i need help, and post every modification i made to the code. if you have some time, can you help me?

It will come with practice...

I think youre doing it right... first, get it working the way you want. Then we can work on refactoring your code and making it "pretty." It's hard when you are plopped into advanced (heck, Im not even that advanced) code, without knowing the basics of what it is doing.

Did you find the error in the place I said? Or is it somewhere else?

it seems to be something else...

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: check in C:\wamp\www\teste up\update.php on line 7
Call Stack

Time Memory Function Location

1 0.0008 149672 {main}( ) ..\update.php:0
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

The first lines are nothing major. If you can configure your server to disable error reporting, they will go away. Again, it comes down to your code being "ugly" and the parser is very unhappy with you. (Unless someone else knows something I dont).

The second problem... which file is update.php?

It seems you have a bad query somewhere else...

update.php is the 3th file. in the botom of 1st page I pasted the code of 3 files.

I think i need to express myself a litle better in order to get your help.

This is a form where i search for an order nunber, then i can change some data and update the rows that i've cheked. im trying a lot of possibilities, but i need to do it.

in your opinion, wat's the best way?

If it were me doing this, it wouldn't be too terribly different, it would just be shorter and a bit more readable. On top of that, I would sanitize my queries and control type setting from the user, so that someone couldnt pass '$10000' when theyre supposed to be putting in their address. Also, allowing $_POST to be placed directly in your query allows hackers/stupid people to send a query to either get all info from your table, or worse destroy your table. I also don't know how your SQL tables were set up, nor what permissions you allow for the user.

That said, your whole project could be done with a single PHP page. There is no need to spread it out over so many, but I understand that compartmentalizing the way you are helps to keep references and purpose to each page. That's a style issue more than a "this is the best way."

Lastly, I would probably break up all these into functions and import the repetetive connection data as necessary. For future reference, look into how .htaccess is configured with PHP (so you can create a protected directory), and how you can store passwords, database names, encryption keys, functions, and other includes that you don't want made available to the public, in a directory that is not accessable from outside the server or root FTP access.

As for the problem you are encountering --
I've personally never encountered the error you are getting. Google seems to say it's a problem with your query - in that it is asking your SQL DB to do something that it knows it shouldnt be doing, or it's overloaded due to the data it is sending back. I'm not sure where in your code that is happening, other than the SQL getting upset that you are making rapid queries, but you have more on a previous page and it causes no fault. So, Im not entirely sure..

Also, since you're on a Windows server, there may be some configurations I'm not very familliar with (I learned, and continue to use Linux for web dev) but I don't think they would be so dissimilar... hopefully someone else will chime in and help out.

Trying do it again, this time, i chose the hard way, 1 query per row, only 6 rows are alowed to update at once, so no problem with time. as usual.... PROBLEMS
the idea was simple, the input fields with the table values. i've done that before, this time something went wrong.... agian Help needed

1st visual.php

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Ficha de entrada de material</title>
        <meta name="alex" content="sermail" />
        <link rel="stylesheet" type="text/css" href="styles/styles.css" />
        <script type="text/javascript">
 function printpage()
   {
   window.print()
   }
 </script>
    <script>
      function showMe (it, box) {
       var vis = (box.checked) ? "block" : "none";
      document.getElementById(it).style.display = vis;
      }
     </script>


<style type="text/css" media="print">
   @page land {size: landscape;}
   .printbutton {
   visibility: hidden;
   display: none;
   }
   .validado {
   visibility: hidden;
   display: none;
   }
    .background{ color: #0000;}
    .page landscape {size: landscape;}
    .page
    { bgcolor: #0000; }
    .h1{color: #000;
    font-family: Arial, sans-serif;
    font-size: 18px;
    font-weight: bold;
    text-align: left;}
    .h2{color: #000;
    font-weight: normal;
    text-align: center;
    font-family: Arial, sans-serif;
    font-size: 16px;}
.land{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2)}
h4 {
    color: #000;
    font-weight: normal;
    text-align: center;
    font-family: Arial, sans-serif;
    font-size: 18px;

</style>

 <script language="javascript">
             window.resizeTo(870,650, );
             </script>  


<?php
mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");

$nordem = $_POST['nordem']; 

$query="SELECT * FROM entrada where nordem_n = '" . mysql_real_escape_string($nordem) . "'";
$result=mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);

if (!$result) {
    $message  = 'N.º de Ordem inexistente ' . mysql_error() . "\n";
    die($message);
}
 while($rows=mysql_fetch_array($result))


?><body class="land" bgcolor= #00814B >
    <div class="body">
        <div class="content">

<form action="act.php" method="post">

<div class="tamanho" style="width:870px">

 <table width="870px" > <tr><td><img class="img" src="imas/sermaillogo.png"></br>
     <input type="submit" class="printbutton" value="Actualizar">
     <input type="button" class="printbutton" value="Imprimir"       onclick="printpage()" />
     <INPUT type="button" class="printbutton" value="Fechar"         onClick="window.close()">
</table>  

</div></h1></td>
<table><tr>
<td> <h1> Data:</h1></td><td> <input type="text" size="10" name="data"                  value=<?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT data FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['data'];
    }
    else {
    echo 'No record found';
    }  ?>/></td>
<td><h1>N.º Ordem:</h1>  </td>  <td><input type="text" size="10" name="nordem"          value=<?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT nordem FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['nordem'];
    }
    else {
    echo 'No record found';
    }   ?>/></td>
<td><h1>Fornecedor:</h1> </td> <td><input type="text" size="10" name="fornecedor"       value=<?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT fornecedor FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['fornecedor'];
    }
    else {
    echo 'No record found';
    }  ?>/></td>
<td> <h1>Guia n.º:</h1>   </td>   <td><input type="text" size="10'" name="guian"        value=<?php  mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT guian FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['guian'];
    }
    else {
    echo 'No record found';
    }  ?>/></td>
 </TR>
 <tr>
<td><h1>N.º Cliente:</h1></td><td><input type="text" size="10"name="ncliente"           value=<?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT ncliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['ncliente'];
    }
    else {
    echo 'No record found';
    }   ?>/></td>
<td><h1>Cliente:</h1>        </td>    <td><input type="text" size="15"name="cliente"    value=<?php mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$result1="SELECT cliente FROM ordem where nordem = '" . mysql_real_escape_string($nordem) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
    echo $row['cliente'];
    }
    else {
    echo 'No record found';
    }  ?>/></td>
</tr></table>
     <table border style="1" color="000" cellspacing=0  id="produtos"  >
 <tr ><td></td>
 <td></td>
 <td ><h2>Cód. <br/>Produto </h2></td>
 <td><h2>Cód. Cliente <br>1-Lote</h2></td>
 <td><h2>Cód. Cliente<br>2-validade</h2></td>
 <td><h2>Designação</h2></td>
 <td><h2>Filtro 1 <br> Unidade de <br>negócio</h2></td>
 <td><h2>Familia/Marca</h2></td>
 <td><h2>Quant.<br> Guia</h2></td>
 <td><h2>Quant. <br>Conferida</h2></td>
 <td><h2>Atado</h2></td>
 <td><h2>Posição</h2></td>
   </tr>


<tr>
 <td><input type="hidden" name="id1" value=<?php echo $rows['id'];?></td>
 <td><input class="printbutton" type="checkbox" name="check1"  value="1"  /></td>
 <td ><input type="text" size="9"name="codprod1"          value=<?php echo $rows['codprod'];?>/></td>
 <td ><input type="text" size="6"name="lote1"             value=<?php echo $rows['lote'];?>/></td>
 <td ><input type="text" size="6"name="val1"              value=<?php echo $rows['val'];?>/></td>
 <td ><textarea cols="20" rows="2" name="designacao1"     value=<?php echo $rows['designacao'];?>>

</textarea></td>
 <td ><input type="text" size="8"name="filtro1"           value=<?php echo $rows['filtro'];?>/></td>
 <td ><input type="text" size="10"name="familiamarca1"    value=<?php echo $rows['familiamarca'];?>/></td>
 <td ><input type="text" size="6"name="quantguia1"        value=<?php echo $rows['quantguia'];?>/></td>
 <td ><input type="text" size="6"name="quantconf1"        value=<?php echo $rows['quantconf'];?>/></td>
 <td ><input type="text" size="6"name="atado1"            value=<?php echo $rows['atado'];?>/></td>
 <td ><input type="text" size="6"name="posicao1"          value=<?php echo $rows['posicao'];?>/></td>
 </tr>

<tr>
<td><input type="hidden" name="id2" value=<?php echo $rows['id'];?></td>
 <td><input class="printbutton" type="checkbox" name="check2"  value="1"  /></td>
 <td ><input type="text" size="9"name="codprod2"          value=<?php echo $rows['codprod'];?>/></td>
 <td ><input type="text" size="6"name="lote2"             value=<?php echo $rows['lote'];?>/></td>
 <td ><input type="text" size="6"name="val2"              value=<?php echo $rows['val'];?>/></td>
 <td ><textarea cols="20" rows="2" name="designacao2"     value=<?php echo $rows['designacao'];?>>

</textarea></td>
 <td ><input type="text" size="8"name="filtro2"           value=<?php echo $rows['filtro'];?>/></td>
 <td ><input type="text" size="10"name="familiamarca2"    value=<?php echo $rows['familiamarca'];?>/></td>
 <td ><input type="text" size="6"name="quantguia2"        value=<?php echo $rows['quantguia'];?>/></td>
 <td ><input type="text" size="6"name="quantconf2"        value=<?php echo $rows['quantconf'];?>/></td>
 <td ><input type="text" size="6"name="atado2"            value=<?php echo $rows['atado'];?>/></td>
 <td ><input type="text" size="6"name="posicao2"          value=<?php echo $rows['posicao'];?>/></td>

 </tr>
 <tr>
 <td><input type="hidden" name="id3" value=<?php echo $rows['id'];?></td>
 <td><input class="printbutton" type="checkbox" name="check3"  value="1"  /></td>
 <td ><input type="text" size="9"name="codprod3"          value=<?php echo $rows['codprod'];?>/></td>
 <td ><input type="text" size="6"name="lote3"             value=<?php echo $rows['lote'];?>/></td>
 <td ><input type="text" size="6"name="val3"              value=<?php echo $rows['val'];?>/></td>
 <td ><textarea cols="20" rows="2" name="designacao3"     value=<?php echo $rows['designacao'];?>>

</textarea></td>
 <td ><input type="text" size="8"name="filtro3"           value=<?php echo $rows['filtro'];?>/></td>
 <td ><input type="text" size="10"name="familiamarca3"    value=<?php echo $rows['familiamarca'];?>/></td>
 <td ><input type="text" size="6"name="quantguia3"        value=<?php echo $rows['quantguia'];?>/></td>
 <td ><input type="text" size="6"name="quantconf3"        value=<?php echo $rows['quantconf'];?>/></td>
 <td ><input type="text" size="6"name="atado3"            value=<?php echo $rows['atado'];?>/></td>
 <td ><input type="text" size="6"name="posicao3"          value=<?php echo $rows['posicao'];?>/></td>

 </tr>
 <tr>

 <td><input type="hidden" name="id4" value=<?php echo $rows['id'];?></td>
 <td><input class="printbutton" type="checkbox" name="check4"  value="1"  /></td>
 <td ><input type="text" size="9"name="codprod4"          value=<?php echo $rows['codprod'];?>/></td>
 <td ><input type="text" size="6"name="lote4"             value=<?php echo $rows['lote'];?>/></td>
 <td ><input type="text" size="6"name="val4"              value=<?php echo $rows['val'];?>/></td>
 <td ><textarea cols="20" rows="2" name="designacao4"     value=<?php echo $rows['designacao'];?>>

</textarea></td>
 <td ><input type="text" size="8"name="filtro4"           value=<?php echo $rows['filtro'];?>/></td>
 <td ><input type="text" size="10"name="familiamarca4"    value=<?php echo $rows['familiamarca'];?>/></td>
 <td ><input type="text" size="6"name="quantguia4"        value=<?php echo $rows['quantguia'];?>/></td>
 <td ><input type="text" size="6"name="quantconf4"        value=<?php echo $rows['quantconf'];?>/></td>
 <td ><input type="text" size="6"name="atado4"            value=<?php echo $rows['atado'];?>/></td>
 <td ><input type="text" size="6"name="posicao4"          value=<?php echo $rows['posicao'];?>/></td>

 </tr>
 <tr>
 <td><input type="hidden" name="id5" value=<?php echo $rows['id'];?></td>
 <td><input class="printbutton" type="checkbox" name="check5"  value="1"  /></td>
 <td ><input type="text" size="9"name="codprod5"          value=<?php echo $rows['codprod'];?>/></td>
 <td ><input type="text" size="6"name="lote5"             value=<?php echo $rows['lote'];?>/></td>
 <td ><input type="text" size="6"name="val5"              value=<?php echo $rows['val'];?>/></td>
 <td ><textarea cols="20" rows="2" name="designacao5"     value=<?php echo $rows['designacao'];?>>

</textarea></td>
 <td ><input type="text" size="8"name="filtro5"           value=<?php echo $rows['filtro'];?>/></td>
 <td ><input type="text" size="10"name="familiamarca5"    value=<?php echo $rows['familiamarca'];?>/></td>
 <td ><input type="text" size="6"name="quantguia5"        value=<?php echo $rows['quantguia'];?>/></td>
 <td ><input type="text" size="6"name="quantconf5"        value=<?php echo $rows['quantconf'];?>/></td>
 <td ><input type="text" size="6"name="atado5"            value=<?php echo $rows['atado'];?>/></td>
 <td ><input type="text" size="6"name="posicao5"          value=<?php echo $rows['posicao'];?>/></td>

 </tr>
 <tr>
 <td><input type="hidden" name="id6" value=<?php echo $rows['id'];?></td>
 <td><input class="printbutton" type="checkbox" name="check6"  value="1"  /></td>
 <td ><input type="text" size="9"name="codprod6"          value=<?php echo $rows['codprod'];?>/></td>
 <td ><input type="text" size="6"name="lote6"             value=<?php echo $rows['lote'];?>/></td>
 <td ><input type="text" size="6"name="val6"              value=<?php echo $rows['val'];?>/></td>
 <td ><textarea cols="20" rows="2" name="designacao6"     value=<?php echo $rows['designacao'];?>>

</textarea></td>
 <td ><input type="text" size="8"name="filtro6"           value=<?php echo $rows['filtro'];?>/></td>
 <td ><input type="text" size="10"name="familiamarca6"    value=<?php echo $rows['familiamarca'];?>/></td>
 <td ><input type="text" size="6"name="quantguia6"        value=<?php echo $rows['quantguia'];?>/></td>
 <td ><input type="text" size="6"name="quantconf6"        value=<?php echo $rows['quantconf'];?>/></td>
 <td ><input type="text" size="6"name="atado6"            value=<?php echo $rows['atado'];?>/></td>
 <td ><input type="text" size="6"name="posicao6"          value=<?php echo $rows['posicao'];?>/></td>
 </tr>

 </table>
  <?php
    mysql_close();

    ?>

2nd act.php

<?php
mysql_connect("localhost", "root")or die("sem conecção ao servidor"); 
mysql_select_db("sermail")or die("Base de dados não foi encontrada");

$nordem = $_POST['nordem']; 

$query="SELECT * FROM entrada where nordem_n = '" . mysql_real_escape_string($nordem) . "'";
$result=mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);

if ($_POST['check1'] == 0) {
$Sql1= " UPDATE entrada SET codprod = '$codprod1' ,lote = '$lote1' ,val = '$val1' ,designacao = '$designacao1' ,filtro = '$filtro1' ,familiamarca = '$familiamarca1' ,quantguia = '$quantguia1' ,quantconf = '$quantconf1' ,atado = '$atado1' ,posicao = '$posicao'  WHERE id = '$id1' ";
    mysql_query ($sql1) or die(mysql_error());
}
if ($_POST['check2'] == 0) {
$Sql2= " UPDATE entrada SET codprod = '$codprod2' ,lote = '$lote2' ,val = '$val2' ,designacao = '$designacao2' ,filtro = '$filtro2' ,familiamarca = '$familiamarca2' ,quantguia = '$quantguia2' ,quantconf = '$quantconf2' ,atado = '$atado2' ,posicao = '$posicao2'  WHERE id = '$id2' ";
    mysql_query ($sql2) or die(mysql_error());
}
if ($_POST['check3'] == 0) {
$Sql3= " UPDATE entrada SET codprod = '$codprod3' ,lote = '$lote3' ,val = '$val3' ,designacao = '$designacao3' ,filtro = '$filtro3' ,familiamarca = '$familiamarca3' ,quantguia = '$quantguia3' ,quantconf = '$quantconf3' ,atado = '$atado3' ,posicao = '$posicao'  WHERE id = '$id3' ";
    mysql_query ($sql3) or die(mysql_error());
}
if ($_POST['check4'] == 0) {
$Sql4= " UPDATE entrada SET codprod = '$codprod4' ,lote = '$lote4' ,val = '$val4' ,designacao = '$designacao4' ,filtro = '$filtro4' ,familiamarca = '$familiamarca4' ,quantguia = '$quantguia4' ,quantconf = '$quantconf4' ,atado = '$atado4' ,posicao = '$posicao'  WHERE id = '$id4' ";
    mysql_query ($sql4) or die(mysql_error());
}
if ($_POST['check5'] == 0) {
$Sql5= " UPDATE entrada SET codprod = '$codprod5' ,lote = '$lote5' ,val = '$val5' ,designacao = '$designacao5' ,filtro = '$filtro5' ,familiamarca = '$familiamarca5' ,quantguia = '$quantguia5' ,quantconf = '$quantconf5' ,atado = '$atado5' ,posicao = '$posicao'  WHERE id = '$id5' ";
    mysql_query ($sql5) or die(mysql_error());
}
if ($_POST['check6'] == 0) {
$Sql6= " UPDATE entrada SET codprod = '$codprod6' ,lote = '$lote6' ,val = '$val6' ,designacao = '$designacao6' ,filtro = '$filtro6' ,familiamarca = '$familiamarca6' ,quantguia = '$quantguia6' ,quantconf = '$quantconf6' ,atado = '$atado6' ,posicao = '$posicao'  WHERE id = '$id6' ";
    mysql_query ($sql6) or die(mysql_error());
}
?>
 <?php
    mysql_close();

    ?>

BTw, i don´t want if after if, i want them independent. but it seems that the 2,3 4,5 and 6 depends on the first. who can i do that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.