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';
?>

Recommended Answers

All 17 Replies

Member Avatar for rajarajan2017

I think no need of the content inside the brackets

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...

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

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

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

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...

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.

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.

oopppsss :)
was in hurry..back my words

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.

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....

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 !

Maybe you should add

null

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

Thanks for the info.

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.