Question in import statement

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
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Question in import statement

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

I would suggest you to use: INSERT ... SELECT Syntax
There are 10 types of people in this world, those who understand binary and those who don't
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post 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']}',
User avatar
crystal ship
Forum Commoner
Posts: 36
Joined: Wed Aug 29, 2007 5:45 am

Post by crystal ship »

The ')' in the line with the while statement may solve your problem :)
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Post 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
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Post by dwessell »

Thanks all, it was the ) that I was missing.. Duh :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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...
There are 10 types of people in this world, those who understand binary and those who don't
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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. :)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

At the very least there's a missing single quote before the username reference.
Post Reply