views:

135

answers:

1

Ok, I don't use php often enough to remember it when I wander back into it. I'm going a bit crazy with this one. I'll post the code below but a few quick explanations. con.php is a php file that creates the database connection $wkHook. There is no issue at all with the connection, so that is not my problem. Basically, I am selecting data from one table, storing it, and then looping through it. In that loop I am trying to insert the data into another table. You will notice that I am echoing $mid in the loop, this is to let me know that the loop itself is working. And it is working. When I loop through every value for $mid is echoed. The query inside the loop, however, is doing nothing. It doesn't even have the decency to throw an error. It just runs through and the loop as if the query wasn't there.

require('con.php');
$runonce=$wkHook->prepare("select moveId, Max, Hev, Work, Split, Rps from Movement order by movementId asc");
          $runonce->execute();
          $runonce->store_result();
          $runonce->bind_result($mid, $max, $hev, $wrk, $spt, $rps);
$user=1;

while($runonce->fetch())
{
    echo $mid."<br>";
    $runup=$wkHook->prepare("insert into Entry
(userId, movementId, Max, Hev, Work, Split, Rps)
values
(?, ?, ?, ?, ?, ?, ?)");
    $runup->bind_param('iisssss', $user, $mid, $max, $hev, $wrk, $spt, $rps);
    $runup->execute();
}
$runup->close();
$runonce->close();
$wkHook->close();
A: 

You seem to be initializing your database connection over and over again. Try removing the second, inner require('con.php').

MySQL errors aren't going to be spit out to the browser by default, you need to call the mysql_error() or mysqli_error functions to see what went wrong if anything. Add this after your execute call in your loop to see if errors are being reported:

echo mysqli_error() . '<br />';
Cryo
Yes, I have tried it without the second initialization originally. I put that in thinking this was the problem. It wasn't and I forgot to remove it. I will change that now.
robert knobulous
So, just to clarify, that was NOT the problem. The issue is still unresolved.
robert knobulous
@robert knobulous : Gotcha. I just updated my answer with something that should give you more information for the underlying problem. Let me know how that goes.
Cryo
Thanks for the tip. That pointed me in the right direction.
robert knobulous
@robert knobulous: Np, glad to hear it.
Cryo