0
$valor = $_POST['valor'];

$post_vars = array('iphone3g1', 'iphone3g2', 'nome', 'iphone41', 'postal', 'apelido');
foreach($post_vars as $var) {
    $$var = "'" . mysql_real_escape_string($_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!!!

hsz
  • 148,279
  • 62
  • 259
  • 315
Souza
  • 1,124
  • 5
  • 19
  • 44
  • possible duplicate of [php $_POST to get values - not the best way](http://stackoverflow.com/questions/5135997/php-post-to-get-values-not-the-best-way) – Your Common Sense Feb 28 '11 at 14:26
  • hey you have to edit your earlier question or comment accepted answer, not starting new one. Just to make people not waste their time writing answers you've got already! – Your Common Sense Feb 28 '11 at 14:26
  • I edited the question, nobody answered. Can You help me please? Please, try to Explain the modifications You make to the code, i dont want just the code to paste but to learn. Thank You very much. – Souza Feb 28 '11 at 18:34

2 Answers2

0
$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);
hsz
  • 148,279
  • 62
  • 259
  • 315
  • I am getting this error. Fatal error: Call to undefined function array_implode() in /home/iphonepo/public_html/mywebsite.com/reparar.php on line 17 – Souza Feb 28 '11 at 16:29
0
$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) . ")");
Geoffrey
  • 10,843
  • 3
  • 33
  • 46