/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Insertion error

Hi again ?

I have a loop like:

[code=php]
foreach($active_keys as $key)
{
……
}
[/code]

In each loop, the $f variable changes, i can see this by simply writing echo $f. But $id is the same in each loop.

[code=php]
foreach($active_keys as $key)
{
…..
mysql_query(“insert into photos values (‘$id’,’$f’)”);
…..
}
[/code]

I execute this, but only the first element can be inserted to the table. But i see that the iteration goes more than 1 times. Why does the mysql_query() function works just once?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@aaronbdavisAug 01.2006 — You'll need to give us more to work with:

How does the $active_keys array get created and what is in it at execution?

How do the $id and $f variables get created and what is in them at execution?

If $id is the same on each iteration, make sure that there isn't a primary key constraint on the first column. If there is, it should trigger an error (unless you have suppressed them with @)

Please post some more code so we can help.
Copy linkTweet thisAlerts:
@Sleep_ModeauthorAug 01.2006 — The primary key attribute was the problem. I didn't know that. It works now. Thank you so much aaronbdavis ?
×

Success!

Help @Sleep_Mode spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...