0

Im makeing something new but i want to make delete file where you can type ID and then click on submit and this function deletes the data from mysql.

Delete.php

<?php
  ob_start();
  include("db.php");
  if(isset($_GET['id'])!="")
  {
  $delete=$_GET['id'];
  $delete=mysql_query("DELETE FROM Osebe WHERE id='$OsebaID'");
  if($delete)
  {
      header("Location:index.php");
  }
  else
  {
      echo mysql_error();
  }
  }
  ob_end_flush();
?>

html file with form

<html>
	<head>
	
		<meta charset="UTF-8">
		<title> TEST </title>
		<style>
</style>
	
		<!-- STYLES -->
		<link href="css/dodaj.css" rel="stylesheet">
	
	</head>
<body>

	
<div class="login">
<h1> IZBRIŠI VNOS </h1>
		<FORM ACTION="brisi.php" method="post"><br>
		ID: <input type=text name="id"><br>
		<input type=submit value"Delete"><input type=reset value="Ponastavi>
		</form>
		
		
		</div>
		


</body>

</html>

Can somebody help me please?

4
  • This if(isset($_GET['id'])!="") will probably work not like you expect. Isset returns boolean true or false which is then compared to an empty string. Commented Apr 22, 2015 at 11:32
  • and do not use deprecated mysql_* functions Commented Apr 22, 2015 at 11:33
  • Debug you code using check where the problem is and mention here if you have an particular error. Commented Apr 22, 2015 at 11:44
  • In addition to the mismatch between submission methods described in the answers from sgt BOSE and Viky. .... do you really mean WHERE id='$OsebaID'" or do you want to delete the ID passed from the form? (in which case, in addition to the logic error there is an SQL injection vuln). Commented Apr 22, 2015 at 11:55

2 Answers 2

2

You are passing value in post and getting that value in get you have typo within your query

Try

if(!empty($_POST['id']))
  {
  $delete = $_POST['id'];
  $delete=mysql_query("DELETE FROM Osebe WHERE id='$OsebaID'");
}

You were using deprecated mysql switch to PDO or mysqli

Sign up to request clarification or add additional context in comments.

Comments

0

It should be post not get as your form method is set to post. Try this -

if(isset($_POST['id'])!="")
{
  $delete=$_POST['id'];
  $delete=mysql_query("DELETE FROM Osebe WHERE id='$OsebaID'");

  ...............

Try to use mysqli or PDO instead of mysql extension.

Comments

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.