0

I have a problem when I want to delete a record from query which uses a bound variable. It worked before I moved to PDO.

<?php
require_once "konversi.php";

$server="localhost";
$user="root";
$password="";
$db_personalia="personalia";

try{
$id_mysql=new PDO("mysql:host=$server;dbname=$db_personalia",$user,$password);
}catch (PDOException $e) {
echo $e->getMessage("MySQL Error");
}

//Get code passed by user
$kode = $_GET['kode'];
if (empty($kode))
die("Invalid");

//convert value
$kode = turn_text($kode);

//value in variable
$kode=$_GET['kode'];

try{
$sql=$id_mysql->prepare("delete from member where nip =:kode");
$sql->bindValue(':kode',$kode);
$sql->execute();
}catch (PDOException $e)
{
print ("The statement failed.\n");
print ("getCode: ". $e->getCode (). "\n");
print ("getMessage: ".$e->getMessage (). "\n");
}

$id_mysql=null;
?>
2
  • @EatPeanutButter new PDO come on... Commented Jan 17, 2015 at 20:26
  • Any concrete error message you want to tell us about? Or perhaps the table structure, contents and $kode value. Commented Jan 17, 2015 at 20:26

1 Answer 1

1

There is something that I don't really understand what you are trying to do. This part:

$kode = $_GET['kode'];
if (empty($kode))
die("Invalid");
//convert value
$kode = turn_text($kode);

//value in variable
$kode=$_GET['kode'];

So let me guess what could be wrong here:

  1. The $_GET['kode'] is undefined and in your SQL, you declared NOT NULL on that column. Also the empty() method is for an array. Instead, use isset() method.

  2. I don't know what the method turn_text() does in your code, but its useless if you OVERRIDE the var $kode in your next line :)

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

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.