Menu
can someone help me what is wrong with this
“[COLOR=DarkRed]INSERT INTO clientes VALUES(‘$_POST[id]’,’$_POST[nombre]’,’$
it doesnt insert the values
[code=php]
"INSERT INTO clientes VALUES (".$_POST['id'].",".$_POST['doc_id'].",'".$_POST['nombre']."','".$_POST['direccion_fact']."')"[/code]
See if that works for you.[code=php]
//you can include variables directly in double quoted strings, and the value will be added to the string
$foo = "bar";
echo "The variable foo is $foo"; //The variable foo is bar
//you can include array values directly in double quoted strings if the key is not a string
$blah = array("hey","foo"=>"bar","ho hum"=>"bored");
echo "The first value in the array is $blah[0]"; //The first value in the array is hey
//you CANNOT include array values directly in double quoted strings if the key is a string
echo "The second value in the array is $blah['foo']"; //parse error!
//technically you can include an array value without using single quotes around the key even if its a string, and it will work
echo "The second value in the array is $blah[foo]"; //The second value in the array is bar
//this will not work, though, with array keys that contain spaces
echo "The third value in the array is $blah[ho hum]"; //parse error!
//you can break up a string to stick in any values; the pieces must be put back together with periods (.)
echo "The third value in the array is ".$blah['ho hum']; //The third value in the array is bored
//there are yet more methods for including values in strings
// you can use printf()
printf("The third value in the array is %s", $blah['ho hum']); //The third value in the array is bored
//check the manual for more information about this function
[/code]
[code=php]$miconexion->consulta(sprintf("INSERT INTO clientes VALUES (%d,%d,'%s','%s')", $_POST['id'], $_POST['doc_id'], $_POST['nombre'], $_POST['direccion_fact']));
[/code]
Its a nice function and makes things easier to read in a lot of cases. BTW-- printf() is equivalent to echo'ing sprintf(). Sorry about getting carried away with telling you all this stuff. :rolleyes: [code=php]<?php
if (count($_POST)) {
require_once('Connections/principal.php');
$miconexion = new Db("webappdetec","localhost","webappdetec","webappdetecpass") ;
$miconexion->consulta("INSERT INTO clientes (id, doc_id, nombre, direccion_fact) VALUES (".$_POST['id'].",".$_POST['doc_id'].",'".$_POST['nombre']."','".$_POST['direccion_fact']."')");
}
?>[/code]
0.1.9 — BETA 5.19