0

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();
nortron
  • 3,873
  • 1
  • 24
  • 27
  • Wow, I used the enter code here deal. WTF? It looked fine in the preview. How do I fix that? –  Feb 15 '10 at 18:59
  • Use the "code" button. I fixed it for you. **edit:** FFS, stop goofing it up. – ceejayoz Feb 15 '10 at 19:00
  • Thanks. I used the code button. Or at least I thought I had. Like I said, it looked ok in the preview. –  Feb 15 '10 at 19:04
  • Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Feb 23 '20 at 22:27

1 Answers1

-1

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 />';
nortron
  • 3,873
  • 1
  • 24
  • 27
  • 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. –  Feb 15 '10 at 19:11
  • So, just to clarify, that was NOT the problem. The issue is still unresolved. –  Feb 15 '10 at 19:14
  • @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. – nortron Feb 15 '10 at 19:15
  • @robert knobulous: Np, glad to hear it. – nortron Feb 15 '10 at 19:26