Heading Here

Please assist me on this one. I have two DB's, one keeps track of user and system activities and the other keeps track of only user activities. The purpose of the codes below is to first of all retreive all tables from the second DB. These tables have the following columns:

(id |date |debit |credit |number |description |accounttype |company_id)

The idea is to retrieve all tables and only their |debit|credit| columns. Already these fields (|debit|credit|) have some values in them. After retrieval, I should be able to update or if possible do a new insertion to any or all the tables that have been retrieved from the DB.

Below are the codes I've written. It retrieves alright but can't do an insertion or update. Please assist me

The same page calls itself.

//Connection and Extraction from DB

//DB Connection exists

//SQL Query
$sql = "show tables from $companyname";

$results = mysql_query($sql) or die(mysql_error());

$count = 1;
while($row = mysql_fetch_array($results))
{
 $results2 = mysql_query("SELECT * FROM `$row[0]` LIMIT 1") or die('Error'.mysql_error());


 while($row2 = mysql_fetch_array($results2))
 {
  $debit = $row2['debit'];
  $credit = $row2['credit'];

  echo "<tr><td>$count. </td><td width='30%'>".ucwords($row[0])."</td><td width='30%'><input type='text' name='debit' value='$debit' align='right'></td>
     <td width='30%'><input type='text' name='credit' value='$credit' align='right'></td></tr>";
 }
$count++;    
}

 //Insertion into DB  

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


//SQL Query
$sql3 = "show tables from $companyname";

$results3 = mysql_query($sql3) or die(mysql_error());

$count = 1;
while($row3 = mysql_fetch_array($results3))
{
    $results4 = mysql_query("SELECT * FROM `$row3[0]` LIMIT 1") or die('Error '.mysql_error());


        $debit = $_POST['debit'];
        $credit = $_POST['credit'];     

    while($row4 = mysql_fetch_array($results4))
    {

        $query = mysql_query("UPDATE `$row3[0]` SET `debit`= '$row4[debit]' , `credit`= '$row4[credit]' WHERE `id`=`$row4[id]`");

        echo "UPDATE `$row3[0]` SET `debit`= '$row4[debit]' , `credit`= '$row4[credit]' WHERE `id`=`$row4[id]` <br>";
        echo $num;
    }
$count++;         

}

}

Thank you for your response and offer of help but the problem is still persisting.

Thank you for your response and offer of help but the problem is still persisting.

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.