I can not change records from a database table

2

It is the following, I need to make my site can change login data, registered in the database. I've made the codes, but when I click to change, nothing happens ... The files I'm using:

alteraadm.php

$conexao = @mysql_connect("localhost","root",""); 

if (!$conexao)

die ("Erro de conexão com localhost, o seguinte erro ocorreu -> ".mysql_error());

$banco = mysql_select_db("vidal",$conexao); 

if (!$banco)
die ("Erro de conexão com banco de dados, o seguinte erro ocorreu -> ".mysql_error());

$sql = mysql_query("SELECT * FROM loginadm");

$i = 1;

$loop = 3;

while ($list = mysql_fetch_array($sql)) {

    if ($i < $loop){

            echo
            '<tr align="justify" valign="middle" bgcolor="#FFFFFF"> 
            <td><a href="" >Usuario:'.$list['usuarioadm'].'</a><br></td>

            <form action="editar.php"><input type="submit" value="alterar" name="alterar"></form>  
            </tr>
        <tr>
            ';
    $i=0;
    }
    $i++;
}
?>  

edit.php

<form method="post" action="update.php" enctype="multipart/form-data">
Codigo:<input type="text" name="codigologin" size="30"><br>
Usuario:<input type="text" name="usuarioadm" size="30"><br>
Senha:<input type="text" name="senhaadm" size="30"><br><br><br>
 <input type="submit" name="concluir" value="concluir" class="botao2">
 </form>

update.php

$conexao = @mysql_connect("localhost","root",""); 

if (!$conexao)
die ("Erro de conexão com localhost, o seguinte erro ocorreu -> ".mysql_error());

$banco = mysql_select_db("vidal",$conexao); 

if (!$banco)
die ("Erro de conexão com banco de dados, o seguinte erro ocorreu -> ".mysql_error());

$codigologin= $_POST ["codigologin"];

$usuarioadm= $_POST["usuarioadm"];

$senhaadm= $_POST["senhaadm"];

$query = "UPDATE INTO 'loginadm' ( 'codigologin' , 'usuarioadm' , 'senhaadm') VALUES ('$codigologin', '$usuarioadm', '$senhaadm')";

mysql_query($query,$conexao);

echo "Alteracao Realizada com sucesso!!!";

?>

If someone helps me find the error, I appreciate it.

    
asked by anonymous 15.11.2015 / 03:24

1 answer

3

First, do not use the mysql_ * functions, have already been removed from php7, arrobas more hinder than they help they hide errors, an error message is better than 'nothing happen'.

The problem is the syntax of your update

$query = "UPDATE INTO 'loginadm' 

If it is an update it should be like the code below, never forget that most updates have WHERE to specify which records should be changed, otherwise all rows in that table will have the same values (in some cases this may be purposeful), backup, restorations or rollbacks will be required.

The correct syntax is:

UPDATE tabela SET 
   campo1 = valor1,
   campo2 = valor2,
   campo3 = valor3
WHERE id = valor_id

How to identify errors in the query:

To be able to identify syntax and other errors in database operations, use the function that returns the error, in which case it is mysql_error() in the query execution that is done by mysql_query() .

mysql_query($query,$conexao) or die(mysql_error());

Remember to remove the arrobas and treat the errors instead of hidden.

Recommended reading:

Why should not we use functions of type mysql_ *?

Why do you say that using @ atm to suppress errors is bad practice?

    
15.11.2015 / 03:32