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!!
Copied wrong, the first argument of
mysqli_query()
always is the connection. Avoid sql Injection.– rray
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.
– Jardel Dint
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.
– Jardel Dint
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 prefixmysqli_
(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.– 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?
– Jardel Dint
Send me the code;
– rray
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
– Jardel Dint
codlead
is avarchar
? it says that your query has a syntax error. If it is to add single quotes in that value/variable.– rray
codlead is an int(11) A.I.
– Jardel Dint
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.– rray
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.
– Jardel Dint
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.– rray
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...
– Jardel Dint
only that.... does not erase in the database... I went there in phpmyadmin and the record is still there...
– Jardel Dint
then he’s just fooling users... what else could be wrong?
– Jardel Dint
UUAAALLLLLLLL now that I understand you!!! IT WORKED! I changed the codlead to emaillead and it worked perfectly eeee
– Jardel Dint
thank you very much friend.
– Jardel Dint
Nice you managed to solve :)
– rray