PHP - Taking values from an HTML table and inserting them into a Mysql table

Asked

Viewed 761 times

-5

I have a table that is the result of a Mysql query from a database on a server. It is shown as follows, for example:

E-MAIL  VALUE
------  -----
email1  P
email2  P
email3  C
email4  P
email5  C
email6  P

I need that on my page (which is on another server other than the one on the page where this table is) it can get the value of the second column (P or C) when the user logs in with one of the emails in this table.

Assuming then that the user is the one of email5, he has to take the value C. After taking the value C, this value will be inserted in another table (Mysql database) of the server of my page.

I’m not sure that’s very clear. My initial idea was to take a table of a Mysql database (from server 1) and put it in another table of another Mysql database (from server 2), but so far I was unsuccessful.

Probably the function will have to be in javascript. But if it can be done in PHP it would be better.

EDITED - The code I tried with quick access to the two banks:

$emailInv = $this->email;
$sqlNuevo = "SELECT DISTINCT uh.TIPO_INVESTIDOR FROM ipi_tst.uh
            JOIN ipi_tst.investidor i ON i.ID = uh.ID_INVESTIDOR
            JOIN ipi_tst.usuario u ON u.ID = i.ID_USUARIO
            WHERE u.EMAIL = '$emailInv' AND u.ID <> 0 ORDER BY FIELD(TIPO_INVESTIDOR,'P','C','O','A')";

$conn = new mysqli("201.7.201.173", "ipi_tst", "ipi_tst", "ipi_tst");
$rNew = $conn->query($sql);

if ($rNew[0]['TIPO_INVESTIDOR'] == 'O'){
    $sqlUpd = "UPDATE b2c.investidor SET office = '1' WHERE email = '$emailInv' AND ID <> 0";
    $res = System::element('db')->query($sqlUpd);
}
else if ($rNew[0]['TIPO_INVESTIDOR'] == 'A'){
    $sqlUpd = "UPDATE b2c.investidor SET office = '2' WHERE email = '$emailInv' AND ID <> 0";
    $res = System::element('db')->query($sqlUpd);
}
else {
    $sqlUpd = "UPDATE b2c.investidor SET office = '0' WHERE email = '$emailInv' AND ID <> 0";
    $res = System::element('db')->query($sqlUpd);
} 
$conn->close();
  • 1

    Do you have access to both banks? Server 1 and 2? If yes you can do everything in PHP. If you only have access to the generated HTML from server table 1, you will have to get the value via javascript. Based on that, make an attempt and post the code so we can better help.

  • 1

    the title leads to a very different interpretation of the context.

  • @Joaopaulo Yes, I have access to both banks. I will edit the post and put the code I tried, closer to a simple Mysql connection.

1 answer

1

I figured out the solution, folks. I was using commands that started with mysqli and probably that was the problem. The code that worked was like this:

                    $emailInv = $this->email;
                    $sqlNuevo = "SELECT DISTINCT uh.TIPO_INVESTIDOR FROM ipi_tst.uh
                    JOIN ipi_tst.investidor i ON i.ID = uh.ID_INVESTIDOR
                    JOIN ipi_tst.usuario u ON u.ID = i.ID_USUARIO
                    WHERE u.EMAIL = '$emailInv' AND u.ID <> 0 ORDER BY FIELD(TIPO_INVESTIDOR,'P','C','O','A') LIMIT 1";

                    $dbhandle = mysql_select_db("ipi_tst",mysql_connect("201.7.201.173", "ipi_tst", "ipi_tst"));
                    $resultNovo = mysql_query($sqlNuevo);
                    //$conn = new mysqli("201.7.201.173", "ipi_tst", "ipi_tst", "ipi_tst");
                    //$rNew = $conn->query($sql);
                    //$rNew = System::element('db2')->query($sqlNuevo);

                    while ($row = mysql_fetch_array($resultNovo)) {
                        $rNew = $row{'TIPO_INVESTIDOR'};
                    }

                    if ($rNew == 'O'){
                        $sqlUpd = "UPDATE b2c.investidor SET office = '1' WHERE email = '$emailInv' AND ID <> 0";
                        $res = System::element('db')->query($sqlUpd);
                    }
                    else if ($rNew == 'A'){
                        $sqlUpd = "UPDATE b2c.investidor SET office = '2' WHERE email = '$emailInv' AND ID <> 0";
                        $res = System::element('db')->query($sqlUpd);
                    }
                    else {
                        $sqlUpd = "UPDATE b2c.investidor SET office = '0' WHERE email = '$emailInv' AND ID <> 0";
                        $res = System::element('db')->query($sqlUpd);
                    }
                    mysql_close($dbhandle);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.