Page 1 of 1

SQL Insertion Help - Changing Attributes

Posted: Tue Dec 02, 2008 8:17 am
by maxmurphy
I am trying to use a function to insert a value pulled from one SQL table and inserted into another. The original and destination field attribute is money, but when using the insert function, the value is being converted to varchar and causing the insertion to fail.

By no means am I expert at this and appreciate any assistance.

Thanks.

function addUser($array)
{
global $my_con;
$sql="Insert into (";
$keys=implode(",",array_keys($array));
$values=implode("','",array_values($array));

$sql="Insert into mp_marketer_accounts($keys)values('$values')";
print($sql);
$result=odbc_exec($my_con, $sql);

$sql="select top 1 SEQ_NBR_PK from mp_marketer_accounts order by SEQ_NBR_PK desc";

$result=odbc_exec($my_con, $sql);

Re: SQL Insertion Help - Changing Attributes

Posted: Tue Dec 02, 2008 10:04 am
by novice4eva
maybe loosing the single quotes will help!! But just maybeeeee

Code: Select all

....$keys)values($values)";//instead of values('$values')

Re: SQL Insertion Help - Changing Attributes

Posted: Tue Dec 02, 2008 10:09 am
by maxmurphy
Thanks, but i tried that and it really screwed up the insertion. The first and last value in the array had the leading/trailing ' removed. This casued even greater havoc.

Re: SQL Insertion Help - Changing Attributes

Posted: Tue Dec 02, 2008 11:02 am
by novice4eva
shooot...i didn't even bother looking 2 lines up eee lazy me...anyways i was assuming that numerical values don't need single quotes ....umm lets see how can we do it then....there is this is_int() function but then you will have to lose the implode function making it more complex. First i would say do a test, i mean try inserting a row with dummy values: numeric values without quotes and rest with quotes, if it executes successfully then we know its a single quote prob and we can proceed .... else track the what caused the error!!

EDIT:but knowing the type of value doesn't always agree with the data type defined for the column!! varchar will accept numerical values too!! so i guess the solution will be to find the problem to be other than SINGLE QUOTES :D