UPDATE SET in a record

Asked

Viewed 79 times

-3

Guys I have a table that lists records in the database and in front of each record has a button like this

<a href="index.php?mod=pedidos&funcao=editar&id=<?=$lnped['protocolo']?>" class="ls-btn-primary ls-ico-user"></a>

$lnped['protocolo'] comes from the database is the registration number

and I need that by clicking this button it changes the field "PRODUCED" of the selected record to '1' only that when I click it changes all that are in the table and not only what I clicked

here is my code

<?php
    $idget = isset($_GET['id']) ? $_GET['id'] : '';
    $produzir = isset($_GET['funcao']) ? $_GET['funcao'] : '';
    $consultapedidos = mysql_query("SELECT * FROM pedidos WHERE protocolo = '".$idget."'");
    if(mysql_num_rows($consultapedidos)==true){
    if($produzir == "editar"){

$sql = mysql_query("UPDATE pedidos SET produzido = '1'") ;  

echo "<meta http-equiv='refresh' content='1;' URL= index.php?mod=pedidos>";
    }
    }
?>
  • 1

    Use stacksnippets only for codes that can be reproduced, if you don’t know how to format the question, click the question mark button that appears when you are editing or writing a question and you will see the hints, I’m sure it will take my comment as a constructive criticism.

  • It’s in PHP, if I put snippets n will show the right code.

  • This is not only the question of showing something, it is the question of whether something runs or not, I recommend you to read: http://meta.pt.stackoverflow.com/questions/js-css-e-html-executables-no-corpo-da-question-ou-resposta and http://meta.pt.stackoverflow.com/questions/1084/how-towe must-format-questions-and-answers and http://meta.pt.stackoverflow.com/questions/2363/howto make our use-do-snippet-more intuitive. . I’m sure you’ll take my tips as constructive and understand that I’m just guiding you :)

  • On the table requests there is also the field protocol ?

  • But the protocol field only exists in the requested table.

2 answers

5


The problem is that your UPDATE there is no clause WHERE, that is, will update all records in the bank.

For this to work change your UPDATE for:

mysql_query("UPDATE pedidos SET produzido = '1' WHERE protocolo = '".$idget."'");
  • Welcome to Stack Overflow, Diego! Take a look at the formatting options for your posts here - and here are some tips on how to answer questions here. :)

2

UPDATE pedidos SET produzido = '1' WHERE protocolo = '".$idget."'"
  • It would be helpful if you added an explanation of how this Update is a valid answer to the question.

  • I didn’t have the capacity for it, so if you’ll be so kind I’m grateful.

  • 1

    He gave no explanation or anything but gave to understand, so anyway thank you, it worked correctly..

Browser other questions tagged

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