diff --git a/index.php b/index.php index a9e6818..5e0c5f0 100644 --- a/index.php +++ b/index.php @@ -62,11 +62,13 @@ function generate_short($url, $dbh) { $sth->execute(); $loop++; } - $sth = $dbh->prepare("INSERT INTO " . DB_TABLE . " (id, url, ip, count) VALUES (?, ?, ?, '0')"); - $sth->bindParam(1, $hash, PDO::PARAM_STR, HASH_LENGTH); - $sth->bindParam(2, $url, PDO::PARAM_STR); - $sth->bindParam(3, $clientip, PDO::PARAM_STR, 255); - if (!$sth->execute()) { + try { + $sth = $dbh->prepare("INSERT INTO " . DB_TABLE . " (id, url, ip, count) VALUES (?, ?, ?, '0')"); + $sth->bindParam(1, $hash, PDO::PARAM_STR, HASH_LENGTH); + $sth->bindParam(2, $url, PDO::PARAM_STR); + $sth->bindParam(3, $clientip, PDO::PARAM_STR, 255); + $sth->execute(); + } catch (PDOException $e) { $hash = "ERROR
Failed to insert hash!"; } }