updateDbRecord の insertIntoDb でそのような動的クエリを作成するにはどうすればよいですか? ID が URL に保存されているため、特定の ID を更新したい場合、update_id=$_GET['id'];
つまり somepage.php?id=12
function insertIntoDb($db, $table, $carry, $carryUrl) {
mysql_select_db($db) or die("Could not select database. " . mysql_error());
$resultInsert = mysql_query("SHOW COLUMNS FROM " . $table);
$fieldnames=array();
if (mysql_num_rows($resultInsert) > 0) {
while ($row = mysql_fetch_array($resultInsert)) {
$fieldnames[] = $row['Field'];
$values = array_intersect_key( $_POST, array_flip($fieldnames) );
}
}
$sql = sprintf('INSERT INTO %s (%s) VALUES ("%s")', $table,
implode(', ', array_map('mysql_escape_string', array_keys($values))), implode('", "',array_map('mysql_escape_string', $values)));
mysql_query($sql);
/* if ($carry == 'yes') {
redirect($carryUrl.'?id='.$_REQUEST['id']);
}
else { echo '<div class="success">Data was entered into the database successfully!<br><a href="view.php?type=recent">View listing?</a></div>'; } */
}
function updateDbRecord($db, $table) {
mysql_select_db($db) or die("Could not select database. " . mysql_error());
$resultInsert = mysql_query("SHOW COLUMNS FROM " . $table . " WHERE Field NOT IN ('id')");
$fieldnames=array();
if (mysql_num_rows($resultInsert) > 0) {
while ($row = mysql_fetch_array($resultInsert)) {
$fieldnames[] = $row['Field'];
$values = array_intersect_key( $_POST, array_flip($fieldnames) );
}
}
#update syntax
}