0

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++;         

}

}
2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Senyo
0

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

Edited by Senyo

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.