Thread: SQL ERROR
View Single Post
  #8  
Old 3rd June 2021, 11:39
szaby szaby is offline
Senior Member
 
Join Date: Jul 2008
Posts: 34
Default
Hello!

PHP Code:
function sql_query($query) {
  
$result mysqli_query($GLOBALS["___mysqli_ston"], $query);
}

function 
htmlsafechars($txt '') {
  
$txt preg_replace("/&(?!#[0-9]+;)(?:amp;)?/s"'&'$txt);
  
$txt str_replace(["<",">",'"',"'",], ["&lt;","&gt;","&quot;",''',], $txt);
  return 
$txt;
}

function 
sqlesc($x) {
  if (
is_integer($x)) {
    return (int) 
$x;
  } elseif (
is_float($x)) {
    return (float) 
$x;
  }
  return 
sprintf('\'%s\'', ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $x) : ((trigger_error("Err"E_USER_ERROR)) ? "" "")));
}


$arrcom mysqli_fetch_row sql_query("SELECT COUNT(id) FROM comments WHERE user = ".(int)$user['id']) OR sqlerr(__FILE__,__LINE__) );
$torrentcomments $arrcom[0];

$arrposts mysqli_fetch_row sql_query("SELECT COUNT(id) FROM posts WHERE userid = ".(int)$user['id']) OR sqlerr(__FILE__,__LINE__) );
$forumposts $arrposts[0];

$row mysqli_fetch_array sql_query("SELECT name FROM clientselect WHERE id = ".sqlesc($user['clientselect'])." LIMIT 1") OR sqlerr(__FILE__,__LINE__) );
if (
$row) {
  
$clientselect htmlsafechars($row["name"]);

Why are you complicating too much? Use functions more and it will be much better and more beautiful.This is just my opinion.
Reply With Quote