Re: Tricky Query

From: Date: Mon, 17 Jun 2002 03:36:26 +0000
Subject: Re: Tricky Query
Groups: php.db 
Request: Send a blank email to php-db+get-19842@lists.php.net to get a copy of this message
To make it easier for yourself to see errors, don't bother concatenating the string when you don't need to. It makes everything tidier. You could use this: $query = "INSERT INTO socios VALUES ('$numsocio', '$nivelsocio', '$apellido', '$nombre', '$nac1-$nac2-$nac3', '$tipodoc', '$docnum', '$profesion', '$cuilcuit1-$cuilcuit2-$cuilcuit3', '$nacionalidad', '$estcivil', '$domicilio', '$codpostal', '$localidad', '$provincia', '\($tel1\) $tel2', '\($telemer1\) $telemer2', '\($cell1\) $cell2', '$email', '$apellcony', '$nomcony', '$tipodoccony', '$doccony', '$naccony1-$naccony2-$naccony3', '$empresuc', '$categoria', '$fechaingreso1-$fechaingreso2-$fechaingreso3', '$fechabaja1-$fechabaja2-$fechabaja3')"; Instead of this (what you had): $query = "INSERT INTO socios VALUES ('".$numsocio."', '".$nivelsocio."', '".$apellido."', '".$nombre."', '".$nac1."-".$nac2."-".$nac3."', '".$tipodoc."', '".$docnum."', '".$profesion."', '".$cuilcuit1."-".$cuilcuit2."-".$cuilcuit3."', '".$nacionalidad."', '".$estcivil."', '".$domicilio."', '".$codpostal."', '".$localidad."', '".$provincia."', '\(".$tel1."\) ".$tel2."', '\(".$telemer1."\) ".$telemer2."', '\(".$cell1."\) ".$cell2."', '".$email."', '".$apellcony."', '".$nomcony."', '".$tipodoccony."', '".$doccony."', '".$naccony1."-".$naccony2."-".$naccony3."', '".$empresuc."', '".$categoria."', '".$fechaingreso1."-".$fechaingreso2."-".$fechaingreso3."', '".$fechabaja1."-".$fechabaja2."-".$fechabaja3."')"; Alternatively, you could use an insert function (for mySQL) which makes it even easier. I have written one, and if ya want, I can send it to ya. All you would have to write is something like this: $data = array( "column1" => "value1", "column2" => 2, "column3" => "value3" ); dbInsert("tableName",$data); In the function, it also has automatic type checking, so you don't need to add single quotes around your text values (as you would have to do in a regular sql query). It doesn't do too much else from that, but you could program it to, if you needed (such as addslashes(), etc), but as I have magic quotes turned on, it doesn't affect my situation. As for your error, I'm not too sure. I don't know if you have to escape the brackets (as they are inside the string quotes), but try outputting your sql statement and using command line to test query. Or restructure your sql so it looks like this: $query = "INSERT INTO socios SET colname = 'value', col2name = 'value2'"; Adam

« previous php.db (#19842) next »