Updating many records PHP script


so use while loop show photos (using url links in database) 2 inputs: 1) checkbox , 2) textbox. form names give each images checkbox , textbox a$photoid , b$photodescription respectively (so checkboxes can accessed through a$photoid , b$photodescription - via post).

however, i'm confused php update script.

 

i want php script following:

-for each of checkbox values (a) need update field in db each of photos (a$photoid)

-for each of textbox values (b) need update field in db each of photos (b$photoid)

 

not sure if right way (at all!) achieve this. i'm going old-school facebook-esk edit photos page - can change descriptions , check box main photo (although box-checking boolean value means 'whether display in websites gallery or not').

 

please can enlighten me? lot,

 

chris

here need do.

 

in dreamweaver update code need replace

 

if ((isset($_post["mm_update"])) && ($_post["mm_update"] == "form1")) {

with

foreach($_post['checkbox'] $i) {

 

then add [$i] each of getsqlvaluestring.  example if form sends photo should have getsqlvaluestring($_post['photo'], "text"),

you need replace

getsqlvaluestring($_post['photo'][$i], "text"),

 

finally in form need this.

 

before loop put in code:

<?php $i=0;?>

 

then in form checbox have or simliar:

<input type="checkbox" name="checkbox" id="checkbox">

replace with:

<input type="checkbox" name="checkbox[]" id="checkbox" value="<?php echo $i++;?>">

also each form field have, name needs end in [].

 

below example of form have inserting multiple records.  update same principal, see in action make changes site.

 

form code:

 

<?php $i=0;?>

<?php { ?>

            <tr>

              <td width="150"><?php echo $row_recordset2['first_name']; ?> <?php echo $row_recordset2['last_name']; ?></td>

              <td width="40"><input type="checkbox" name="checkbox[]" id="checkbox" value="<?php echo $i++;?>">

                <input type="hidden" name="ticket_id[]" value="<?php echo $_session['lastid'];?>">

                <input type="hidden" name="email[]" value="<?php echo $row_recordset2['email']; ?>">

                <input type="hidden" name="name[]" value="<?php echo $row_recordset2['first_name']; ?> <?php echo $row_recordset2['last_name']; ?>">

                <label for="checkbox"></label></td>

            </tr>

            <?php } while ($row_recordset2 = mysql_fetch_assoc($recordset2)); ?>

 

insert code:

 

$editformaction = $_server['php_self'];
if (isset($_server['query_string'])) {
  $editformaction .= "?" . htmlentities($_server['query_string']);
}

foreach($_post['checkbox'] $i) {
  $insertsql = sprintf("insert cc_users (ticket_id, email, name) values (%s, %s, %s)",
                       getsqlvaluestring($_post['ticket_id'][$i], "int"),
                       getsqlvaluestring($_post['email'][$i], "text"),
        getsqlvaluestring($_post['name'][$i], "text"));

  mysql_select_db($database_helpdesk, $helpdesk);
  $result1 = mysql_query($insertsql, $helpdesk) or die(mysql_error());

  $insertgoto = "new_ticket_email2.php";
  if (isset($_server['query_string'])) {
    $insertgoto .= (strpos($insertgoto, '?')) ? "&" : "?";
    $insertgoto .= $_server['query_string'];
  }
  header(sprintf("location: %s", $insertgoto));
}



More discussions in Develop server-side applications in Dreamweaver


adobe

Comments