Mehrere Datensätze gleichzeitig aktualisieren

phpameise

Mitglied
Hallo Programmierer. Ich habe Eine Tabelle mit Name, Vorname, Email und id. Ich frage dort die Datensätze ab. Das funktioniert. Allerdings übersteigt das aktualisieren meine Kenntnisse der Programmierkunst. Sicher muss man dort auch mit arrays und schleife arbeiten. Hat jemand Lust mir zu helfen? Hier mein Code:
PHP:
<?php require_once('../../../Connections/Bewerbung.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE tblBewerber SET Name=%s, Vorname=%s, Email=%s WHERE id=%s",
                       GetSQLValueString($_POST['Name'], "text"),
                       GetSQLValueString($_POST['Vorname'], "text"),
                       GetSQLValueString($_POST['Email'], "text"),
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_Bewerbung, $Bewerbung);
  $Result1 = mysql_query($updateSQL, $Bewerbung) or die(mysql_error());
}

mysql_select_db($database_Bewerbung, $Bewerbung);
$query_Recordset1 = "SELECT * FROM tblBewerber";
$Recordset1 = mysql_query($query_Recordset1, $Bewerbung) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
  <form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <tr>
  <td>
  <table width="500" border="0" cellspacing="1" cellpadding="0">
  <tr>
  <td align="center">&nbsp;</td>
  <td align="center"><strong>Name</strong></td>
  <td align="center"><strong>Vorname</strong></td>
  <td align="center"><strong>Email</strong></td>
  </tr>
    
    <?php do { ?>
      <tr>
        <td align="center"><input name="id" type="hidden" id="id" value="<? echo $row_Recordset1['id']; ?>" /></td>
        <td align="center"><input name="Name" type="text" id="Name" value="<?php echo $row_Recordset1['Name']; ?>"></td>
        <td align="center"><input name="Vorname" type="text" id="Vorname" value="<?php echo $row_Recordset1['Vorname']; ?>"></td>
        <td align="center"><input name="Email" type="text" id="Email" value="<?php echo $row_Recordset1['Email']; ?>"></td>
        
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    <tr>
      <td colspan="4" align="center"><input type="submit" name="senden" value="senden"></td>
</tr>
  </table>
  </td>
  </tr>
<input type="hidden" name="MM_update" value="form1" />
  </form>
</table>

<?php
mysql_free_result($Recordset1);
?>
Kann es sein, dass dieser Code der Schlüssel ist?
PHP:
function mysql_update_array($table, $data, $id_field, $id_value) {
  foreach ($data as $field=>$value) {
    $fields[] = sprintf("`%s` = '%s'", $field, mysql_real_escape_string($value));
  }
  $field_list = join(',', $fields);
 
  $query = sprintf("UPDATE `%s` SET %s WHERE `%s` = %s", $table, $field_list, $id_field, intval($id_value));
 
  return $query;
}
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück