Page 1 of 1

Question in import statement

Posted: Tue Oct 16, 2007 2:20 am
by dwessell
Hi,

When I run the code below, nothing seems to be executed, and no error messages are presented. In my experience it's due to a misplaced ' or " somewhere.. But I can't find anything off.. Can someone with a better set of eyes take a look at it?

Code: Select all

<?
$link = mysql_connect(localhost,xx,xx) or die (mysql_error());
$db   = mysql_select_db(xx,$link) or die (mysql_error());

$result = mysql_query("SELECT * FROM members",$link) or die (mysql_error());

while($row = mysql_fetch_array($result,MYSQL_ASSOC){

$sql = 	"INSERT INTO members2 (memberid,name,address,city,state,zip,country, email,cardtype,cardnum,cardexp,cardname,username, password,billplan,promocode,lastbilled,entrydate, expiredate,subdate,ccattempt,cardnum_checksum) 
VALUES 
('$row[memberid]','$row[fname]','$row[address]', '$row[city]','$row[state]','$row[zip]','$row[country]', '$row[email]','$row[cardtype]','$row[cardnum]','$row[cardexp]', $row[username]','$row[password]','$row[billplan]','$row[promocode]', '$row[lastbilled]','$row[entrydate]','$row[expiredate]','$row[subdate]', '$row[ccattempt]','$row[cardnum_checksum]')";


mysql_query($sql,$link) or die (mysql_error());
	}	

?>
Thanks
David

Posted: Tue Oct 16, 2007 3:05 am
by VladSun
I would suggest you to use: INSERT ... SELECT Syntax

Posted: Tue Oct 16, 2007 5:22 am
by jmut
Try putting
error_reporting(E_ALL) and you will see what is wrong
VALUES
('$row[memberid]',
Should go something like

Code: Select all

VALUES
('{$row['memberid']}',

Posted: Tue Oct 16, 2007 7:04 am
by crystal ship
The ')' in the line with the while statement may solve your problem :)

Posted: Tue Oct 16, 2007 8:21 am
by dwessell
Hi..

I added error_reporting(E_ALL); to the top of the script, and there isn't any output... Does something need to be done beside adding the line? I looked on Google, but couldn't find anything..

Thanks
David

Posted: Tue Oct 16, 2007 9:53 am
by dwessell
Thanks all, it was the ) that I was missing.. Duh :)

Posted: Tue Oct 16, 2007 11:48 am
by VladSun
I still can't understand why you have to do it this way ... The use of "INSERT ... SELECT" syntax would be enormous in your case...

Posted: Tue Oct 16, 2007 11:52 am
by dwessell
Hi Vlad,

Good question.. Sorry for not answering it earlier.. The reason I didn't was I have to do some manipulation with the field in question. For example, the old db had fname and lname as fields.. The new db just has full name..

From reading the documentation (And I did) that you suggested, it was clear that I could do that type of manipulation..

Thanks
David

Posted: Tue Oct 16, 2007 11:59 am
by VladSun
Well, you can do a lot of data manipulation at DB layer - your example would lead you to CONCAT() :)

There will be a great performance improvement if you can do this at DB layer, not at code layer. :)

Posted: Mon Oct 22, 2007 2:57 am
by feyd
At the very least there's a missing single quote before the username reference.