0

I use a PHP-Script to submit my IPv4 Address to my own PowerDNS-Server using that link:

script.php?domain=test.dns.com&ipaddr=11.22.33.44&passwd=auth-phrase

Therefore I modified the link in a way that the IPv4 and IPv6 are being updated simultaneously. I modified the update script, but then only one version will be updated (IPv4):

script.php?domain=test.dns.com&ipaddr=11.22.33.44&passwd=auth-phrase&ip6addr=2001:0db8:1234:0000:0000:0000:0000:0000

Here is the script I'm using:

<?php

// DynDNS-Service für PowerDNS

// @author Simon "cmon2k" Lauger <simon@lauger.name
// @date   06.09.2012

$dsn     = 'mysql:dbname=pdns;host=127.0.0.1'; // Datenbank DSN
$user    = 'pdns'; // Name der Datenbank
$pass    = 'password'; // Datenbank Passwort

// Auth-String der als GET-Parameter übermittelt werden muss
$auth    = 'auth-phrase';

// Für alle im Array enthaltenen Records dürfen Updates gefahren werden
$allowed = array('ip4.test.dns.tld');

$domain  = (isset($_GET['domain'])) ? $_GET['domain'] : null;
$ip      = (isset($_GET['ipaddr'])) ? $_GET['ipaddr'] : null;
$ip6     = (isset($_GET['ip6addr'])) ? $_GET['ip6addr'] : null;
$domain6 = 'ip6.test.dns.tld';


if ((empty($domain) || is_null($domain)) || (empty($ip6) || is_null($ip6))) {
    die('missing parameter');
    exit;
}

if (!in_array($domain, $allowed)) {
    die('forbidden domain name');
    exit;
}

if (!isset($_GET['passwd']) || $_GET['passwd'] != $auth) {
    die('authentification failed');
    exit;
}

try {
    $dbh = new PDO($dsn, $user, $pass);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

// HERE THE PROBLEM STARTS

//IPv4 UPDATE

$check = $dbh->prepare('SELECT id FROM records WHERE name = :name AND type = :type');
$check->bindParam(':name', $domain);
$check->bindValue(':type', 'A');
$check->execute();
$result = $check->fetch(PDO::FETCH_ASSOC);

if (empty($result)) {
    die('record not found');
    exit;
} else {
    $update = $dbh->prepare('UPDATE records SET content = :content WHERE id = :id LIMIT 1');
    $update->bindParam(':content', $ip);
    $update->bindParam(':id', $result['id']);

    // if ($update->execute()) {
         // die('update successful (' . htmlentities($ip, ENT_QUOTES) . ')');
         // exit;
    // }
    // die('update returned false');
    // exit;
}

//IPv6 UPDATE

$check2 = $dbh->prepare('SELECT id FROM records WHERE name = :name AND type = :type');
$check2->bindParam2(':name', $domain6);
$check2->bindValue2(':type', 'AAAA');
$check2->execute2();
$result2 = $check2->fetch(PDO::FETCH_ASSOC);

if (empty($result2)) {
    die('record not found');
    exit;
} else {
    $update2 = $dbh->prepare('UPDATE records SET content = :content WHERE id = :id LIMIT 1');
    $update2->bindParam2(':content', $ip6);
    $update2->bindParam2(':id',      $result2['id']);
    if ($update2->execute2()) {
          die('update successful (' . htmlentities($ip, ENT_QUOTES) . ')');
          exit;
    }
    die('update returned false');
    exit;
}
?>

I already removed the die(); part in the first part of the code. I also tried to rename the variable of the second part (check -> check2). But it's still not working. What did I do wrong? Why isn't it possible to write two times in the mysql-database?

I receive a blank site without any errors. But still: The update didn't work. There is no new updated IPv6 entry in my database.

Studocwho
  • 2,290
  • 3
  • 20
  • 27
hans717
  • 11
  • 1
  • Note: The domain being used in the link is "ip4.test.dns.tld", not "test.dns.com". – hans717 Aug 21 '19 at 18:20
  • 1
    You need to find errors. A blank page usually means your code crashed. – tadman Aug 21 '19 at 18:33
  • Thanks. The thing is: the first part works (IPv4 Update). What can't I use it two times? – hans717 Aug 21 '19 at 18:36
  • 1
    See: [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – Paul Spiegel Aug 21 '19 at 18:49
  • 1
    What are `bindParam2`, `bindValue2`, and `execute2`? The names of the methods are just `bindParam`, `bindValue`, and `execute`. – Barmar Aug 21 '19 at 18:59
  • A blank page really doesn't help us diagnose the problem, that's basically zero information. PHP if configured correctly logs the issues it has. If you don't know where that log file is, or it's not capturing errors, have a look at what Paul suggested as this is a critical part of the diagnostic process. – tadman Aug 21 '19 at 19:05
  • why you write `bindParam2` or `execute2`? – Giacomo M Aug 21 '19 at 19:33
  • It works if I use `bindParam` instead of `bindParam2`. THANKS! – hans717 Sep 26 '19 at 06:11

0 Answers0