pdo - Update different mysql rows at once -
as title says..
i have table generated reading mysql database, has 20+ rows. want update different rows together, how can achieve this? tried way, no success...
"exception 'pdoexception' message 'sqlstate[hy093]: invalid parameter number: number of bound variables not match number of tokens'"
<tbody> <?php require_once('configintern.php'); $pdo = coninterna(); $elenco = 'select * elenco sezione = "1a" order cognome asc'; $stato = $pdo->prepare($elenco); $stato ->execute(); $lista = $stato ->fetchall(); $infos = array(); foreach ($lista $rs) { $id = $rs['id']; if (isset($_post['submit'])) { $sezione = "1a"; $presente = isset($_post['presente']) ? $_post['presente'] : 0; $ticket = isset($_post['ticket']) ? $_post['ticket'] : 0; $pm = isset($_post['pm']) ? $_post['pm'] : 0 ; $pd = isset($_post['pd']) ? $_post['pd'] : 0 ; $celiaco = isset($_post['celiaco']) ? $_post['celiaco'] : 0 ; $sl = isset($_post['sl']) ? $_post['sl'] : 0 ; $pb = isset($_post['pb']) ? $_post['pb'] : 0 ; $pc = isset($_post['pc']) ? $_post['pc'] : 0 ; $ph = isset($_post['ph']) ? $_post['ph'] : 0 ; $sql = "update elenco set presente = :presente, ticket = :ticket, pm = :pm, pd = :pd, celiaco = :celiaco, sl = :sl, pb = :pb, pc = :pc, ph = :ph id = :id"; try { $stmt = $pdo->prepare($sql); $stmt->bindparam(':id', $id, pdo::param_str); $stmt->bindparam(':presente', $presente, pdo::param_str); $stmt->bindparam(':sezione', $sezione, pdo::param_str); $stmt->bindparam(':ticket', $ticket, pdo::param_str); $stmt->bindparam(':pm', $pm, pdo::param_str); $stmt->bindparam(':pd', $pd, pdo::param_str); $stmt->bindparam(':celiaco', $celiaco, pdo::param_str); $stmt->bindparam(':sl', $sl, pdo::param_str); $stmt->bindparam(':pb', $pb, pdo::param_str); $stmt->bindparam(':pc', $pc, pdo::param_str); $stmt->bindparam(':ph', $ph, pdo::param_str); $stmt->execute(); } catch (pdoexception $e) { echo $e; } } ?> <tr> <td><?php echo $rs['cognome']; ?></td> <td><input type="checkbox" name="presente" <?php if($rs['presente'] == 1) echo 'checked'; ?> ></td> <td><input type="checkbox" name="ticket" <?php if($rs['ticket'] == 1) echo 'checked'; ?> ></td> <td><input type="checkbox" name="pm" <?php if($rs['pm'] == 1) echo 'checked'; ?> ></td> <td><input type="checkbox" name="pd" <?php if($rs['pd'] == 1) echo 'checked'; ?> ></td> <td><input type="checkbox" name="celiaco" <?php if($rs['celiaco'] == 1) echo 'checked'; ?> ></td> <td><input type="checkbox" name="sl" <?php if($rs['sl'] == 1) echo 'checked'; ?> ></td> <td> </td> <td><input type="checkbox" name="pb" <?php if($rs['pb'] == 1) echo 'checked'; ?> ></td> <td><input type="checkbox" name="pc" <?php if($rs['pc'] == 1) echo 'checked'; ?> ></td> <td><input type="checkbox" name="ph" <?php if($rs['ph'] == 1) echo 'checked'; ?> ></td> </tr> <?php } ?> </tbody>
Comments
Post a Comment