alkoofi
alkoofi

Reputation: 43

why my sql statement, inserts two rows in the database?

I have the following code, knowing that its not in a loop. although i'm requiring it in another file but still its not in a loop. I don't know why i'm getting two rows in the database after executing those lines

 $stmt400 = $db->prepare("insert into history (last_scan,warning_files,new_files,username) values(?,?,?,?)");
$stmt400->execute(array($date,$sum,$row100[0],$user));

Upvotes: 0

Views: 142

Answers (2)

eeetee
eeetee

Reputation: 527

Since you're requiring the file twice, you can use require_once to prevent it from loading and executing anything twice.

Upvotes: 1

Shakti Phartiyal
Shakti Phartiyal

Reputation: 6254

If your code is required in another file then it will execute and lead to two insertions. I suggest you put the code in a function in the file you require. That way it will not execute automatically and will only be called when you call that function.

Upvotes: 0

Related Questions