MySQL code passed to MySQLi does not generate desired actions

1

I have a code that is for inserting / changing / deleting Columns and rows from a database table, it worked very well when it was for MySQL, I tried to make some changes to MySQLi, at first it does not show any errors, more also does not perform actions. I would ask the help of the staff to give a verified so that I can change and fix this problem, follow the code used. Thanks in advance for the help ...

<?php
session_start();
include_once("conexao com meu db");

// NOME DESSE DOCUMENTO
$pagina = "manipulation_data.php";

// NOME DA TABELA USADA
$tabela = "tabela";

// INSERIR COLUNA
if(isset($_GET['acao']) && @$_GET['acao']=="inserir_coluna") {
mysqli_query($conn, "ALTER TABLE '".$tabela."' ADD '".$_GET['coluna']."' 
VARCHAR(10) NOT NULL COMMENT '".$_GET['comentario']."' AFTER '".$_GET['apos']."'");
echo "<script>location.href='".$pagina."'</script>";
exit;
}


// EXCLUIR COLUNA
if(isset($_GET['excluir_coluna']) && @$_GET['excluir_coluna']!="") {
mysqli_query($conn, "ALTER TABLE '".$tabela."' DROP '{$_GET['excluir_coluna']}'");
echo "<script>location.href='".$pagina."'</script>";
exit;
}


// EXCLUIR LINHA
if(isset($_GET['acao']) && @$_GET['acao']=="excluir") {
mysqli_query($conn, "DELETE FROM '".$tabela."' WHERE id='{$_GET['id']}'");
echo "<script>location.href='".$pagina."'</script>";
exit;
}

// INSERIR LINHA
if(isset($_POST['inserir']) && @$_POST['inserir']!="") {
$colunas = Array(); $valores = Array();
foreach($_POST['linhas'] AS $l1 => $l2) {
$colunas[] = $l1;
$valores[] = "'$l2'";
}
mysqli_query($conn, "INSERT INTO ".$tabela." (".implode(",", $colunas).") 
VALUES(".implode(",", $valores).")");
echo "<script>location.href='".$pagina."'</script>";
exit;
}

// SALVAR OS DADOS
if(isset($_POST['salvar']) && @$_POST['salvar']=="salvar") {
$update = "";
$up = Array();
foreach($_POST['linhas'] AS $l1 => $l2) {
$up[]="$l1='$l2'";
}
$update.= implode(",", $up);
mysqli_query($conn, "UPDATE ".$tabela." SET ".$update." WHERE 
id='".array_values($_POST['linhas'])[0]."'");
echo "<script>location.href='".$pagina."'</script>";
exit;
}
echo "<form action=\"".$pagina."\" method=\"post\"><table border=\"1\">

<tr>
<td>Editar</td>
<td>Excluir</td>";

$valorcolumn = "SELECT a.COLUMN_NAME, a.COLUMN_COMMENT FROM 
information_schema.COLUMNS a WHERE a.TABLE_NAME = '".$tabela."'";
$query = mysqli_query($conn, $valorcolumn);
$array_colunas = Array();
while($dados = mysqli_fetch_array($query)) {
extract($dados);
$array_colunas[] = $COLUMN_NAME;
echo "<td>$COLUMN_COMMENT <a href=\"".$pagina."? 
excluir_coluna=$COLUMN_NAME\">excluir coluna</td>";
}
echo "</tr>";

$valorcoluna = "SELECT COUNT(*) AS colunas FROM information_schema.COLUMNS a 
WHERE a.TABLE_NAME = '".$tabela."'";
$colunas = mysqli_query($conn, $valorcoluna);

$valortable = "SELECT * FROM tabela";
$query = mysqli_query($conn, $valortable);
while($dados = $query->fetch_array()){
echo "<tr>
<td><a href=\"".$pagina."?acao=editar&id={$dados[0]}\">Editar</a></td>
<td><a href=\"".$pagina."?acao=excluir&id={$dados[0]}\">Excluir</a></td>";

while ($data = mysqli_fetch_array($colunas, MYSQLI_ASSOC)) { 
$data['colunas'];}

for($i = 0; $i < $data; $i++) {
    echo "<td>{$dados[$i]}</td>";
}
echo "</tr>";
}
echo "<tr>
<td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"inserir\" 
value=\"Inserir Nova Linha\"></td>";
while ($data = mysqli_fetch_array($colunas, MYSQLI_ASSOC)) { 
$data['colunas'];}

for($i = 0; $i < $data; $i++) {
echo "<td><input type=\"text\" name=\"linhas[{$array_colunas[$i]}]\" 
value=\"\" placeholder=\"valores, coluna id = vazio\"></td>";
}
echo "</tr>";

echo "</table></form>";
?>
<a href="<?php echo $pagina; ?>? 
acao=inserir_coluna&coluna=coluna3&comentario=Coluna três&apos=coluna2">INSERIR NOVA COLUNA</a>

<br /><br />
<?php
if(isset($_GET['acao']) && @$_GET['acao']=="editar") {

echo "<form action=\"".$pagina."\" method=\"post\"><table>
<tr>";
$query = mysqli_query($conn, "SELECT a.COLUMN_NAME, a.COLUMN_COMMENT FROM 
information_schema.COLUMNS a WHERE a.TABLE_NAME = '".$tabela."'");
while($dados = $query->fetch_array()) {
    extract($dados);
    echo "<td>$COLUMN_COMMENT</td>";
}
echo "</tr>";
$query = mysqli_query($conn, "SELECT * FROM ".$tabela." WHERE 
id='{$_GET['id']}'");
while ($dados = $query->fetch_array()) {
    echo "<tr>";
    while ($data = mysqli_fetch_array($colunas, MYSQLI_ASSOC)) { 
$data['colunas'];}
    for($i = 0; $i < $data; $i++) {
        echo "<td><input type=\"text\" name=\"linhas[{$array_colunas[$i]}]\" 
value=\"{$dados[$i]}\"></td>";
    }
echo "</tr>";
}
echo "</table><input type=\"submit\" name=\"salvar\" value=\"salvar\"> 
</form>";
}
?>

MySQL code the old one ...

<?php
include("conexao com meu db");

// NOME DESSE DOCUMENTO
$pagina = "manipulation_data.php";

// NOME DA TABELA USADA
$tabela = "tabela";

// INSERIR COLUNA
if(isset($_GET['acao']) && @$_GET['acao']=="inserir_coluna") {
mysql_query("ALTER TABLE '".$tabela."' ADD '".$_GET['coluna']."' VARCHAR(10) 
NOT NULL COMMENT '".$_GET['comentario']."' AFTER '".$_GET['apos']."'");
echo "<script>location.href='".$pagina."'</script>";
exit;
}


// EXCLUIR COLUNA
if(isset($_GET['excluir_coluna']) && @$_GET['excluir_coluna']!="") {
mysql_query("ALTER TABLE '".$tabela."' DROP '{$_GET['excluir_coluna']}'");
echo "<script>location.href='".$pagina."'</script>";
exit;
}


// EXCLUIR LINHA
if(isset($_GET['acao']) && @$_GET['acao']=="excluir") {
mysql_query("DELETE FROM '".$tabela."' WHERE id='{$_GET['id']}'");
echo "<script>location.href='".$pagina."'</script>";
exit;
}


// INSERIR LINHA
if(isset($_POST['inserir']) && @$_POST['inserir']!="") {
$colunas = Array(); $valores = Array();
foreach($_POST['linhas'] AS $l1 => $l2) {
$colunas[] = $l1;
$valores[] = "'$l2'";
}
mysql_query("INSERT INTO ".$tabela." (".implode(",", $colunas).") 
VALUES(".implode(",", $valores).")");
echo "<script>location.href='".$pagina."'</script>";
exit;
}

// SALVAR OS DADOS
if(isset($_POST['salvar']) && @$_POST['salvar']=="salvar") {
$update = "";
$up = Array();
foreach($_POST['linhas'] AS $l1 => $l2) {
$up[]="$l1='$l2'";
}
$update.=implode(",", $up);
mysql_query("UPDATE ".$tabela." SET ".$update." WHERE 
id='".array_values($_POST['linhas'])[0]."'");
echo "<script>location.href='".$pagina."'</script>";
exit;
}


echo "<form action=\"".$pagina."\" method=\"post\">
<table border=\"1\">

<tr>
<td>Editar</td>
<td>Excluir</td>";
$query=mysql_query("SELECT a.COLUMN_NAME, a.COLUMN_COMMENT
FROM information_schema.COLUMNS a
WHERE a.TABLE_NAME = '".$tabela."'");
$array_colunas = Array();
while($dados=mysql_fetch_array($query)) {
extract($dados);
$array_colunas[] = $COLUMN_NAME;
echo "<td>$COLUMN_COMMENT <a href=\"".$pagina."? 
excluir_coluna=$COLUMN_NAME\">excluir coluna</td>";
}
echo "</tr>";

$colunas = mysql_query("SELECT COUNT(*) AS colunas FROM 
information_schema.COLUMNS a WHERE a.TABLE_NAME = '".$tabela."'");

$query=mysql_query("SELECT * FROM ".$tabela."");
while($dados=mysql_fetch_array($query)) {
echo "<tr>
<td><a href=\"".$pagina."?acao=editar&id={$dados[0]}\">Editar</a></td>
<td><a href=\"".$pagina."?acao=excluir&id={$dados[0]}\">Excluir</a></td>";

for($i = 0; $i < mysql_result($colunas , 0, "colunas"); $i++) {
echo "<td>{$dados[$i]}</td>";
}

echo "</tr>";
}

echo "<tr>
<td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"inserir\" 
value=\"Inserir Nova Linha\"></td>";
for($i = 0; $i < mysql_result($colunas , 0, "colunas"); $i++) {
echo "<td><input type=\"text\" name=\"linhas[{$array_colunas[$i]}]\" 
value=\"\" placeholder=\"valores, coluna id = vazio\"></td>";
}
echo "</tr>";

echo "</table></form>";
?>

<a href="<?php echo $pagina; ?>? 
acao=inserir_coluna&coluna=coluna3&comentario=Coluna 
três&apos=coluna2">INSERIR NOVA COLUNA</a>

<br /><br />

<?php
if(isset($_GET['acao']) && @$_GET['acao']=="editar") {

echo "<form action=\"".$pagina."\" method=\"post\"><table>
<tr>";
$query=mysql_query("SELECT a.COLUMN_NAME, a.COLUMN_COMMENT
FROM information_schema.COLUMNS a
WHERE a.TABLE_NAME = '".$tabela."'");
while($dados=mysql_fetch_array($query)) {
extract($dados);
echo "<td>$COLUMN_COMMENT</td>";
}
echo "</tr>";
$query=mysql_query("SELECT * FROM ".$tabela." WHERE id='{$_GET['id']}'");
while($dados=mysql_fetch_array($query)) {
echo "<tr>";
for($i = 0; $i < mysql_result($colunas , 0, "colunas"); $i++) {
echo "<td><input type=\"text\" name=\"linhas[{$array_colunas[$i]}]\" 
value=\"{$dados[$i]}\"></td>";
}
echo "</tr>";
}

echo "</table><input type=\"submit\" name=\"salvar\" value=\"salvar\"> 
</form>";
}
?>
    
asked by anonymous 07.06.2018 / 06:28

0 answers