Update in database not working

Asked

Viewed 133 times

-2

Man update in the bank does not work, follows codes:

php student.

<form method="post" action="?acao=save&id_aluno=<?php echo $id; ?>">
    <?php echo $pegaid; ?>
    <input type="text" name="ID" class="txt-medium bradius" value="<?php echo $id; ?>"/>
    <input type="text" name="Nome_completo" class="txt-medium bradius" value="<?php echo $full_name; ?>"/>
    <input type="submit" value=" Salvar " class="btn-save-medium" />
</form>

header.php

if($_GET["acao"] == ("save")) {
     $startaction = 6;
}

php Inserts.

include 'header.php';

  if($startaction == 6){
    if($acao == "save") {
      $pegaid = $_GET['id_aluno'];
            $pegaidpost = $_POST['ID'];
       $update_full_name = $_POST['Nome_completo'];
              $update_data = "UPDATE alunos SET Nome_completo = '$update_full_name' WHERE ID = '$pegaid'";
        if($update_data) {
          echo"<script> alert('Dados atualizados com sucesso'); </script>";
        } else {
          echo"<script> alert('Dados NÃO atualizados'); </script>";
        }
    }
}

I looked up the name of the field in my database, it’s Nome_completo normal, just like this in the parameter name="Nome_completo";

  • You are missing all connection scripts with the Bank, which might just be causing your problem.

3 answers

1


SUGGESTION :

  • First : The ID is an integer value ... Check if '$pegaid' return a character or an integer value here : "... WHERE ID = '$pegaid'".

  • Second : Its connection to the BD is well made ?

  • The connection to the bank is normal, all other parts of the system works normally, login, logoff, database search, while

  • My $pegaid variable is returning me a GET value of the url, it is working also because the data on the screen only appear according to this ID, and the data is working

  • @Williamdepaula "... WHERE ID = '$pegaid'" tries to take out the '' in the '$pegaid' and see what !

  • Is returning an integer number normally the $pegaid variable

  • 1

    Now it worked, I just took the simple quotes and updated in the database, thank you very much for your help

  • @Williamdepaula of nothing bro !!

  • I would like to reopen this issue, because happened another problem, one of the data is being sent that in the case is the full name, more when I edit the person’s CPF continues with problems, does not send to the bank

  • @Williamdepaula you’d better publish another question explaining yourself better ... !

Show 3 more comments

0

Your connection to the bank is in that header.php?

And on that line if($update_data) { it should be like this if(mysql_query($update_data)) {

I hope I’ve helped :)

0

In your code, besides not having the code for the connection, mysql_connect there is the mysql_query who would be responsible for taking your variable $update_data and pass it as SQL command to your base.

Browser other questions tagged

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