0

so i m trying to delete a row in mysql with php code and it doesnt gets deleted

the code:

<?php
    if (isset($_POST['zbrisi']))
    {
        $ime = $_POST['imeDatoteke'];
        mysql_connect("localhost","root","");
        mysql_select_db("upload");
        mysql_query("DELETE FROM datoteke WHERE imeDatoteke=$ime");
        mysql_close();
        echo "<strong>Podatki so bili zbrisani!</strong>";
    }
?>



<input name="imeDatoteke" type="text" />

<input type="submit" name="zbrisi" value="Zbriši" />

and the database: enter image description here

3
  • 1
    try as imeDatoteke='$ime' Commented Apr 21, 2014 at 7:18
  • 2
    Use mysqli_* functions or PDO instead of using mysql_* functions(deprecated)!!! Commented Apr 21, 2014 at 7:21
  • 1
    No to mention your code is wide open to SQL Injection which is more reason to move into MySQLi or PDO using prepared statements. Commented Apr 21, 2014 at 7:32

2 Answers 2

2

try this

mysql_query("DELETE FROM datoteke WHERE imeDatoteke='$ime'");
Sign up to request clarification or add additional context in comments.

1 Comment

Use mysqli_* functions or PDO statements instead of using mysql_* functions(deprecated)!!!
1

If the value in the where - condition to be deleted is a string, it must be enclosed in ':

...
mysql_query("DELETE FROM datoteke WHERE imeDatoteke = '" . $ime. "' ");
...

4 Comments

yes that id work thanks alot i will rate as an answers as soon as i can
At least point out SQL injection and answer with a prepared statement or so instead of just encouraging people to use posted variables literally.
@Blizz: You know that this is the entire code ready for production, do you? And why not posting all the rest of programming rules related to database queries? I'm tired of these smartass recommendations not serving any purpose.
Save the sarcasm. People come here to ask questions and if there is a possible improvement or a security issue with it, it is the duty of the more experienced programmers to point that out. I'm so tired of people just sitting here for the reputation instead of doing what this site was built to do: Help others improve their code. If you view this single possible injection point (which is enough to hack the entire site) as not important enough to point out, perhaps you should consider not replying anymore. My $0.02.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.