开发者

Insert into table from array

$valor = $_POST['valor'];

$post_vars = array('iphone3g1', 'iphone3g2', 'nome', 'iphone41', 'postal', 'apelido');
foreach($post_vars as $var) {
    $$var = "'" . mysql_real_escape_st开发者_如何转开发ring($_POST[$var]). "', ";
}

$sql = "INSERT INTO clientes (iphone3g1, iphone3g2, nome, iphone41, postal, apelido, valor) VALUES ($$var '$valor')";
$query= mysql_query($sql);

Thank You so much for your previous answers guys.

I manares do write down this bit of code, i think it males scense but os not working.

I hope You can help me.

Thank You!!!


$valor = $_POST['valor'];

$post_vars = array('iphone3g1', 'iphone3g2', 'nome', 'iphone41', 'postal', 'apelido');
$post_values = array();
foreach($post_vars as $var) {
    $post_values[$var] = "'" . mysql_real_escape_string($_POST[$var]). "'";
}

$sql = "INSERT INTO clientes (" . array_implode(',', array_keys($post_values)) . ") VALUES (" . array_implode(',', array_values($post_values)) . ")";
$query= mysql_query($sql);


$columns = array('iphone3g1', 'iphone3g2', 'nome', 'iphone41', 'postal', 'apelido', 'valor');
foreach($columns as $column)
  $values[$column] = "'" . mysql_real_escape_string($_POST[$column]) . "'";
$rs = mysql_query("INSERT INTO clients (" . implode(',', $columns) . ") VALUES (" . implode(',', $values) . ")");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜