Jump to content

Transferring records from Access to MySQL via PHP


Eiolon

Recommended Posts

When users click the refresh button, I want the records from the Access database to move to the MySQL database.

 

It semi-working except I am only getting the first record from the Access database transferred over.  Any ideas on how to get the other records?

 

<?php

$conn=odbc_connect('pcres','','');
$sql="SELECT PC_Id, Stop_Time FROM usage";
$rs=odbc_exec($conn,$sql); 

require_once('includes/mysql.php');

$pc = odbc_result($rs,"PC_Id");
$stop = odbc_result($rs,"Stop_Time");

$query_users = "SELECT pc, stop FROM pcres ORDER BY stop ASC";
$users = mysql_query($query_users) OR die ('Cannot retrieve a list of current users.');

if (isset($_POST['refresh'])) {

$delete_old = "DELETE FROM pcres";
$result_old = mysql_query($delete_old) OR die ('Could not delete old data.');

if ($delete_old) {

$insert = "INSERT INTO pcres (pc, stop) VALUES ('$pc','$stop')";
$result = mysql_query($insert) OR die ('Could not insert into database.');

if ($insert) {
header('Location: index.php');
exit; }

}

}

?>

<form id="add" name="add" method="post" action=""><input type="submit" name="refresh" id="button" value="REFRESH" /></form>

<table class="data" border="1">
  <tr>
    <th><div align="left">PC</div></th>
<th><div align="left">Stop Time</div></th>
  </tr>
  <?php do { ?>
  <tr onmouseover="this.bgColor='#EBFAFF';" onmouseout="this.bgColor='#FFFFFF';">
    <td><?php echo $row_users['pc']; ?></td>
<td><?php echo $row_users['stop']; ?></td>
  </tr>
  <?php } while ($row_users = mysql_fetch_assoc($users)); ?>
</table>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.