doa24uk Posted June 15, 2007 Share Posted June 15, 2007 Thanks paul for your advice in my previous thread, however I can't seem to get it working. Could someone please take a look at the full code from the api file (there are several php files, but I think this is the one that does all the work!) I have applied the mods you gave in paul's previous post, but I just can't find where the 'call to it' is! Any help would be absolutely great! Thanks Adam <?php // ----- Queries --------------------------------------------------------------- function __checked($key, $val) { return (isset($_POST[$key]) && $_POST[$key] == $val) ? 'checked="checked"' : ""; } function __selected($key, $val) { return (isset($_POST[$key]) && $_POST[$key] == $val) ? 'selected="selected"' : ""; } // ----- URLs ------------------------------------------------------------------ function url_extension($url) { $url = parse_url($url); $url = isset($url['path']) ? end(explode('/', $url['path'])) : ''; $url = (strpos($url, '.') !== false) ? end(explode('.', $url)) : ''; return $url; } // ----- Enclose --------------------------------------------------------------- function enclose($start, $end1, $end2) { return "$start((?:[^$end1]|$end1(?!$end2))*)$end1$end2"; } // ----- Debug Query ----------------------------------------------------------- function mysql_query_debug($str) { $result = mysql_query($str); if (mysql_error()) echo "<hr /><b>Message:</b> " . mysql_error() . "<br /><b>Query:</b> $str<hr />"; return $result; } // ----- TMySQL_KeyVal --------------------------------------------------------- class TMySQL_KeyVal { var $tbl = null; var $prefix = null; var $ncnt = null; // ----- Init ----- function Init($tbl, $prefix, $ncnt) { $this->tbl = $tbl; $this->prefix = $prefix; $this->ncnt = $ncnt; } // ----- CreateTable ----- function CreateTable($drop = false) { if ($drop) mysql_query_debug("drop table {$this->tbl}"); $cnt = Array(); for ($i = 0; $i < $this->ncnt; $i++) $cnt[] = "{$this->prefix}cnt$i smallint unsigned not null"; $cnt = implode(", ", $cnt); mysql_query_debug( "create table {$this->tbl} ({$this->prefix}hash smallint unsigned not null, {$this->prefix}key varchar(255) not null unique, {$this->prefix}val text not null, $cnt, index {$this->prefix}hash ({$this->prefix}hash))"); } // ----- Set ----- function Set($key, $val, $profile_id) { $hash = '0x' . substr(md5($key), 0, 4); $key = mysql_real_escape_string($key); $val = mysql_real_escape_string($val); mysql_query( "insert into {$this->tbl} ({$this->prefix}hash, {$this->prefix}key, {$this->prefix}profile_id) values ('$hash', '$key', '$profile_id')"); mysql_query_debug( "update {$this->tbl} set {$this->prefix}val = '$val', {$this->prefix}cnt0 = {$this->prefix}cnt0+1 where {$this->prefix}hash = $hash && {$this->prefix}key = '$key'"); } // ----- Get ----- function Get($key, $start = 0, $end = 0) { $hash = '0x' . substr(md5($key), 0, 4); $key = mysql_real_escape_string($key); $start = ($start < 0 || $start >= $this->ncnt) ? 0 : $start; $end = ($end <= 0 || $end > $this->ncnt) ? $this->ncnt : $end; $cnt = Array(); for ($i = $start; $i < $end; $i++) $cnt[] = "{$this->prefix}cnt$i"; $cnt = implode("+", $cnt); $result = mysql_query_debug( "select {$this->prefix}key 'key', {$this->prefix}val 'val', $cnt cnt from {$this->tbl} where {$this->prefix}hash = $hash && {$this->prefix}key = '$key'"); $result = mysql_fetch_assoc($result); return $result ? $result['val'] : false; } // ----- GetAll ----- function GetAll($start = 0, $end = 0) { $start = ($start < 0 || $start >= $this->ncnt) ? 0 : $start; $end = ($end <= 0 || $end > $this->ncnt) ? $this->ncnt : $end; $cnt = Array(); for ($i = $start; $i < $end; $i++) $cnt[] = "{$this->prefix}cnt$i"; $cnt = implode("+", $cnt); $result = mysql_query_debug( "select {$this->prefix}key 'key', {$this->prefix}val 'val', $cnt 'cnt' from {$this->tbl} where {$this->prefix}key != '<< Time >>' && $cnt <> 0 order by 'cnt' desc, 'val', 'key'"); $data = Array(); while($row = mysql_fetch_assoc($result)) $data[] = $row; return $data; } // ----- Clear ----- function Clear($key) { $hash = '0x' . substr(md5($key), 0, 4); $key = mysql_real_escape_string($key); mysql_query_debug( "delete from {$this->tbl} where {$this->prefix}hash = $hash && {$this->prefix}key = '$key'"); } // ----- Clear All ----- function ClearAll($key) { mysql_query_debug("delete from {$this->tbl}"); } // ----- Shift ----- function Shift() { $time = (integer)(time()/24/3600); $shift = $time-(integer)$this->Get("<< Time >>"); $shift = ($shift > 0) ? $shift : 0; $shift = ($shift < $this->ncnt) ? $shift : $this->ncnt; if ($shift) { $this->Set("<< Time >>", $time); $cnt = Array(); for ($i = $this->ncnt-1; $i >= $shift; $i--) $cnt[] = "{$this->prefix}cnt$i = {$this->prefix}cnt" . ($i-$shift); for ($i = $shift-1; $i >= 0; $i--) $cnt[] = "{$this->prefix}cnt$i = 0"; $cnt = implode(", ", $cnt); mysql_query_debug("update {$this->tbl} set $cnt"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55749-same-insert-error-not-solved/ Share on other sites More sharing options...
fenway Posted June 17, 2007 Share Posted June 17, 2007 Post the SQL that is causing the error. Quote Link to comment https://forums.phpfreaks.com/topic/55749-same-insert-error-not-solved/#findComment-276333 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.