SQL Insertion Help - Changing Attributes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maxmurphy
Forum Newbie
Posts: 2
Joined: Tue Dec 02, 2008 8:10 am

SQL Insertion Help - Changing Attributes

Post 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);
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: SQL Insertion Help - Changing Attributes

Post by novice4eva »

maybe loosing the single quotes will help!! But just maybeeeee

Code: Select all

....$keys)values($values)";//instead of values('$values')
maxmurphy
Forum Newbie
Posts: 2
Joined: Tue Dec 02, 2008 8:10 am

Re: SQL Insertion Help - Changing Attributes

Post 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.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: SQL Insertion Help - Changing Attributes

Post 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
Post Reply