What’s wrong with that code?

Asked

Viewed 48 times

0

all right?

I am a beginner in PHP and I am "side" in a simple code, in which I have seen numerous answers here in the forum, and I did exactly as it is in the answers (until CTRL+C CTRL+V) and it doesn’t work.

Is the following:

I need to capture the content of a variable (for $_GET[]) and delete that content from the database.

The capture is perfect. Really it recognizes the content, stores in the variable and tals... (I did several tests and gave right). But what’s tying me up is that you can’t delete the comic book.

The Code is this:

    <?php 

require_once "dbconfigurator.php";

$id = $_GET['emaillead'];

if(isset($id)) {

    $apaga = "DELETE FROM leads WHERE codlead=" . $id;

    $apagando = mysqli_query($apaga) or die ('Erro ao Apagar Email');

    $fechando = mysqli_close($conexaobd);

    echo "<h1>Sentiremos sua falta!</h1><br><h3>O email " . $id . " foi excluido de nosso banco de dados!</h3>";
    } else {
        echo "Email não encontrado!";
        }



?>

I need to know where the error is because it finds the contents of the variable, but does not delete from the bank. The dbconfigurator.php file is correct, because the same is used in the capture.php file and the same makes the insertion in the database perfectly.

I stand by!!

  • 1

    Copied wrong, the first argument of mysqli_query() always is the connection. Avoid sql Injection.

  • As I am new in PHP I didn’t understand it right. So let me understand: inside mysqli_query() I should not put the $delete variable but the connection. But how do I put the connection and what is this connection? From the databank (the same q is in require_once). Please explain it to me in more detail if you can.

  • In the.php capture file, you have the line: $recording = mysql_query("INSERT INTO leads(lead name, emaillead) VALUES ('$name', '$email')"); which works perfectly. So I put the same line only changing to DELETE FROM leads WHERE emaillead=$id, and even then, it doesn’t do the "promised"... Also there in require_once, I put inside a variable and this variable, put in mysql_query() and tbm nothing.

  • 1

    All functions that have the prefix mysql_ were removed from the newer versions php7, there is another API to connect in the database its functions has the prefix mysqli_ (note that you have a i at the end of Improved) and in most of them the first argument is the connection, see a simple example of how to use them here. If you have any more questions put an arroba before the user’s name, so you notify him, ex @rray.

  • Buddy, first of all, I want to thank you for the effort you’re putting into this project of mine... but unfortunately I haven’t yet... look.. the version of my server is PHP 5.6. I searched several blogs and forums and saw that the syntax is correct. My code is this: $deletes = "delete from leads Where emaillead=$id"; $deleting = mysql_query($deletes,$connected bd) or die (mysql_error(); $closing = mysql_close($connectedbd); Now I ask you. If the syntax is correct, where else there may be an error?

  • Send me the code;

  • This is the error: You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near '@molurefri.com.br' at line 1

  • codlead is a varchar? it says that your query has a syntax error. If it is to add single quotes in that value/variable.

  • codlead is an int(11) A.I.

  • So the problem is $_GET['emaillead'] should be a number and an email is coming. If this data comes through a link, it is going wrong.

  • but the emaillead and lead field, are varchar, only the codlead is integer. My intention is to rescue the email address of the client that comes by the url by the variable emaillead.

  • you should go through the url codlead, if you are going to pass the email in the query do: $apaga = "DELETE FROM leads WHERE codlead= '$id'"; In the sql query any value/variable must be in single quotes.

  • I have two things to say... the first one.. that mistake "damn" came out... ball show... goes through the IF and so on and comes to the end...

  • only that.... does not erase in the database... I went there in phpmyadmin and the record is still there...

  • then he’s just fooling users... what else could be wrong?

  • UUAAALLLLLLLL now that I understand you!!! IT WORKED! I changed the codlead to emaillead and it worked perfectly eeee

  • thank you very much friend.

  • Nice you managed to solve :)

Show 13 more comments
No answers

Browser other questions tagged

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