0

Hello,
This is my first appearance on a forum ever, I am fairly new at programming and I have following question :
If I make a INSERT...SELECT statement (to transfer data from one table to another) in a MySQL-editor, the statement gets executed once ; the same statement in my PHP-script gets executed twice. Anyone a idea how this is possible ?

^<?php
require_once('../includes/verbinding.php');
$id = $_GET['id'];
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
echo mysqli_error($dbc);
$query = "INSERT INTO Coach (CoachVoornaam, CoachFamnaam, CoachAdresnummer, CoachPostcode, CoachWoonplaats, CoachProvincie)
select TMPCoachVoornaam as CoachVoornaam, TMPCoachFamnaam as CoachFamnaam, TMPCoachAdresnummer as CoachAdresnummer, TMPCoachPostcode as CoachPostcode, TMPCoachWoonplaats as CoachWoonplaats, TMPCoachProvincie as CoachProvincie FROM TMPCoach
where TMPCoachID='" . $id ."'";
mysqli_query($dbc, $query);
echo mysqli_error($dbc);
mysqli_close($dbc);
echo 'einde php-script';
?>
6
Contributors
17
Replies
18
Views
7 Years
Discussion Span
Last Post by Geertc
0

I think no need of the content inside the brackets

If I don't add what is between brackets(), I get the errormessage "column count doesn't match the value count", and if I leave out the brackets, I'm getting a syntax-error...

0

There is no reason why it should be executed twice, unless you refreshed the page.

Checked that, but the page doesn't get refreshed...

0

verbinding.php just contains 4 DEFINE() for my db-connection. I even deleted the code , and retyped it but the result is the same. Sorry guys...

0

Not sure but you can execute these two query separately.
First insert query then execute it and then select query and again execute.
Its a trial & error.

0

Not sure but you can execute these two query separately.
First insert query then execute it and then select query and again execute.
Its a trial & error.

You missed the point. It is one insert query, not an insert query followed by a select.

0

You missed the point. It is one insert query, not an insert query followed by a select.

My table doesn't have duplicate code of duplicate id's. I am just in the stadium of designing a structure, so my table has 8 entries to keep an overview of what is going on with my data.
Other things that I've tried are LIMIT 1, when selecting from the original table, of use the DISTINCT keyword when selecting.

0

Okay, thank you very much for helping. I'll come back to you when I solved the issue. I'm sure it must be something that I'm overlooking....

0

Good luck finding the issue, can't think of anything else.

This is a bit weird... I deleted the whole page and build it up again, and now everything seems to work as it should.
Thank you for helping me !

0

Maybe you should add

null

as the value for ur id which i guess is ur key.

Edited by aMOEBa: n/a

0

The problem of executing the sql-statement twice is solved : I had forgotten the ON-clausule that is required when you use an INNER JOIN. I'm pretty sure I'll never forget it as long as I live. Thanks for reaching some solutions...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.