Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/topic.php on line 737
Форумы портала PHP.SU :: Помогите найти ошибку в коде(Генерация изображения)

 PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи


 Страниц (1): [1]   

> Без описания
Safok
Отправлено: 04 Июля, 2013 - 15:15:58
Post Id



Гость


Покинул форум
Сообщений всего: 96
Дата рег-ции: Март 2013  


Помог: 0 раз(а)

[+]


Есть пхп код который рисует юзербар, нужно найти ошибку и исправить:
Спойлер (Отобразить)


Изображение аватарки получаю тут http://minecraft[dot]industrialdelux[dot][dot][dot]=120&u=1[dot]png
 
 Top
Denkill
Отправлено: 04 Июля, 2013 - 15:23:17
Post Id



Посетитель


Покинул форум
Сообщений всего: 330
Дата рег-ции: Янв. 2013  
Откуда: Барнаул


Помог: 7 раз(а)




Ошибка? Какая? Картинка генерируется, ошибки не выводит.


-----
Хо-Хо-Хо
 
 Top
Safok
Отправлено: 04 Июля, 2013 - 15:25:28
Post Id



Гость


Покинул форум
Сообщений всего: 96
Дата рег-ции: Март 2013  


Помог: 0 раз(а)

[+]


Демо: http://minecraft[dot]industrialdelux[dot][dot][dot]r.php?name=Safok
Когда беру готовую картинку в коде(т.е avatar.png) то выводит нормально
 
 Top
dfcbkbq
Отправлено: 04 Июля, 2013 - 16:47:04
Post Id


Новичок


Покинул форум
Сообщений всего: 4
Дата рег-ции: Июль 2013  


Помог: 0 раз(а)




Здравствуйте!
У меня тоже шляпа какая-то:
помогите разобраться с ошибкой в коде!

PHP:
скопировать код в буфер обмена
  1. <?PHP // 6/6/02 4:28PM
  2.  
  3.  
  4.  
  5. if(isset($MYSQL_SESSION_INC)) return;
  6. $MYSQL_SESSION_INC=TRUE;
  7.  
  8.     // let the server know that you want to set your session handling yourself.
  9.     // The manual is kind of funny with this. According to the ini_set page, this shouldn't
  10.     // work, but it does (and a user has posted that fact). However, I've also noticed this
  11.     // script working with session.save_handler = files. According to the
  12.     // session_set_save_handler page, it shouldn't - I added a note on this.
  13.     ini_set('session.save_handler','user');
  14.  
  15.     // I don't like the idea of having stale sessions around. Having them removed may even
  16.     // enhance performance on the database table if it starts getting large. However, I don't
  17.     // think it is necessary to run it at 100 - unless you are _very_ paranoid.
  18.     ini_set('session.gc_probability','100');
  19.  
  20.     require dirname(__FILE__).'/class.phpMysqlConnection.php';
  21.     $SESS_SQL=FALSE;            // MySQL object to be used by sessions
  22.  
  23.     // How long the sessions last. Defaults to the value in the php.ini file.
  24.     ini_set('session.gc_maxlifetime','86400'); // сессия 24 часа    
  25.     $SESS_LIFE=ini_get('session.gc_maxlifetime');
  26.  
  27.  
  28.     function sess_open(){
  29.         global $PHPSECURITYADMIN_PATH,$SQL_HOST,$SQL_DB,$SQL_USER,$SQL_PASS,$SESS_SQL,$_SERVER;
  30.        
  31.         // Create the object to use in the sessions
  32.         $SESS_SQL=new phpMysqlConnection($SQL_USER,$SQL_PASS,$SQL_HOST);
  33.        
  34.         // Select the correct database on the server
  35.         $SESS_SQL->SelectDB($SQL_DB);
  36.         return TRUE;
  37.     }
  38.    
  39.     function sess_close(){
  40.         return TRUE;
  41.     }
  42.    
  43.     function sess_read($key){
  44.             global $PHPSECURITYADMIN_PATH,$SESS_SQL,$SESS_LIFE;
  45.            
  46.             $query="select value from ".sessions." where sesskey='$key' and expiry > ".time();
  47.             if($SESS_SQL->Exists($query))
  48.                 // If the requested session exists, get the data
  49.                 $retVal=$SESS_SQL->QueryItem($query);
  50.             if(isset($retVal)) return $retVal;
  51.             else return '';
  52.     }
  53.    
  54.     function sess_write($key,$val){
  55.             global $PHPSECURITYADMIN_PATH,$SESS_SQL,$SESS_LIFE;
  56.            
  57.             // Calculate the session end time
  58.             $expiry=time()+$SESS_LIFE;
  59.             $value=addslashes($val);
  60.             $query="select sesskey from ".sessions." where sesskey='$key'";
  61.             if($SESS_SQL->Exists($query)){
  62.             // If the session exists, update it
  63.             $query="update ".sessions." set expiry=$expiry, value='$value' where sesskey='$key' and expiry > ".time();
  64.             $SESS_SQL->Update($query);
  65.         }else{
  66.             // If the session doesn't exist, create it
  67.             $query="insert into ".sessions." values('$key',$expiry,'$value')";
  68.             $SESS_SQL->Insert($query);
  69.         }
  70.             return TRUE;
  71.     }
  72.    
  73.     function sess_destroy($sess_id){
  74.             global $PHPSECURITYADMIN_PATH,$SESS_SQL;
  75.            
  76.             // delete the existing session
  77.             $query="DELETE from ".sessions." where sesskey='$sess_id'";
  78.             $SESS_SQL->Delete($query);
  79.             return TRUE;
  80.     }
  81.    
  82.     function sess_gc(){
  83.             global $PHPSECURITYADMIN_PATH,$SESS_SQL;
  84.            
  85.             // delete all expired sessions
  86.             $query='DELETE from '.sessions.' where expiry < '.time();
  87.             $SESS_SQL->Delete($query);
  88.             return $SESS_SQL->a_rows;
  89.     }
  90.    
  91.     session_set_save_handler('sess_open','sess_close','sess_read','sess_write','sess_destroy','sess_gc');
  92. ?>


ошибка лезет следующая: Fatal error: Call to a member function Exists() on a non-object in /home/u123733/nw-spbru/www/manag er/include/_sessions.php on line 61

61 строка - if($SESS_SQL->Exists($query)){
в функции sess_write!

Очень прошу помочь!

Код писал не я, а тот кто писал совсем потерялся...
Я совсем не кумекаю в это. Совсем не разработчик. Но благодаря этой ошибке, я уже знаю несколько типов переменных РНР, посмотрел несколько уроков, и это очень много времени требует, поэтому параллельно пишу в некоторые форумы... осталось только дождаться что или кто поможет)

Спасибо за внимание, ребята! Ниндзя

(Отредактировано автором: 04 Июля, 2013 - 16:51:25)

 
 Top
dfcbkbq
Отправлено: 05 Июля, 2013 - 10:51:15
Post Id


Новичок


Покинул форум
Сообщений всего: 4
Дата рег-ции: Июль 2013  


Помог: 0 раз(а)




[quote=dfcbkbq][/quote]
 
 Top
Denkill
Отправлено: 05 Июля, 2013 - 11:00:09
Post Id



Посетитель


Покинул форум
Сообщений всего: 330
Дата рег-ции: Янв. 2013  
Откуда: Барнаул


Помог: 7 раз(а)




Что за класс phpMysqlConnection (если пользовательский то код в студию)
PHP:
скопировать код в буфер обмена
  1.  $SESS_SQL=new phpMysqlConnection($SQL_USER,$SQL_PASS,$SQL_HOST);


-----
Хо-Хо-Хо
 
 Top
dfcbkbq
Отправлено: 09 Июля, 2013 - 11:57:16
Post Id


Новичок


Покинул форум
Сообщений всего: 4
Дата рег-ции: Июль 2013  


Помог: 0 раз(а)




PHP:
скопировать код в буфер обмена
  1. <?
  2.  
  3.  
  4.  
  5. if(isset($PHPMYSQLCONNECTION_INC)) return;
  6.  
  7. $PHPMYSQLCONNECTION_INC=TRUE;
  8.  
  9.  
  10.  
  11. class phpMysqlConnection{
  12.  
  13.     var $result='';
  14.  
  15.     var $data='';
  16.  
  17.     var $rows='';
  18.  
  19.     var $user='';
  20.  
  21.     var $pass='';
  22.  
  23.     var $host='';
  24.  
  25.     var $port='';
  26.  
  27.     var $socket='';
  28.  
  29.     var $id='';
  30.  
  31.     var $a_rows='';
  32.  
  33.  
  34.  
  35.     function phpMysqlConnection($user="phpuser",$pass="php",$host="localhost",$port='',$socket_path=''){
  36.  
  37.         $this->user=$user;
  38.  
  39.         $this->pass=$pass;
  40.  
  41.         $this->host=$host;
  42.  
  43.         $this->port=$port;
  44.  
  45.         $this->socket=$socket_path;
  46.  
  47.         if($this->port) $host.=":".$this->port;
  48.  
  49.         if($this->socket) $host.=":".$this->socket;
  50.  
  51.         if($this->id=mysql_connect($this->host,$this->user,$this->pass))
  52.  
  53.             return TRUE;
  54.  
  55.         else
  56.  
  57.             return $this->errorMessage("Unable to connect to mysql server: ".$this->host);
  58.  
  59.     }
  60.  
  61.  
  62.  
  63.     function GetDatabases(){
  64.  
  65.         if($this->result=mysql_list_dbs()){
  66.  
  67.             $i=0;
  68.  
  69.             while($i<mysql_num_rows($this->result)){
  70.  
  71.                 $db_names[$i]=mysql_tablename($this->result,$i);
  72.  
  73.                 $i++;
  74.  
  75.             }
  76.  
  77.             return($db_names);
  78.  
  79.         }else
  80.  
  81.             return $this->errorMessage("Unable to find a database on server: ".$this->host);
  82.  
  83.     }
  84.  
  85.  
  86.  
  87.     function CreateDB($database){
  88.  
  89.         if($this->result=mysql_create_db($database)){
  90.  
  91.             return TRUE;
  92.  
  93.         }else
  94.  
  95.             return $this->errorMessage("Unable to create database: $database");
  96.  
  97.     }
  98.  
  99.  
  100.  
  101.     function DropDB($database){
  102.  
  103.         if($this->result=mysql_drop_db($database)){
  104.  
  105.             return TRUE;
  106.  
  107.         }else
  108.  
  109.             return $this->errorMessage("Unable to drop database: $database");
  110.  
  111.     }
  112.  
  113.  
  114.  
  115.     function CopyDB($database,$dest_db='',$drop_tables=0,$dest_host="localhost",$dest_user="phpuser",
  116.  
  117.             $dest_pass="php",$dest_port='',$dest_socket_path=''){
  118.  
  119.         set_time_limit(300);    // set time limit to 5 minutes (may not work!)
  120.  
  121.         // define the second server connection
  122.  
  123.         if($dest_port) $host.=":".$dest_port;
  124.  
  125.         if($dest_socket_path) $host.=":".$dest_socket_path;
  126.  
  127.  
  128.  
  129.         // Let's connect to the other server now
  130.  
  131.         $conn_id=mysql_connect($host,$dest_user,$dest_pass) or
  132.  
  133.             $retVal=$this->errorMessage("Unable to connect to mysql server: $dest_host");
  134.  
  135.         if(isset($retVal)) return $retVal;
  136.  
  137.  
  138.  
  139.         $dest_dbs=mysql_list_dbs($conn_id) or
  140.  
  141.             $retVal=$this->errorMessage("Unable to find a database on server: $dest_host");
  142.  
  143.  
  144.  
  145.         if(isset($retVal)) return $retVal;
  146.  
  147.  
  148.  
  149.         // check if the database exists on the destination server
  150.  
  151.         $EXISTS=FALSE;
  152.  
  153.         while($i<mysql_num_rows($dest_dbs)){
  154.  
  155.             if(mysql_tablename($dest_dbs,$i)==$dest_db)
  156.  
  157.                 $EXISTS=TRUE;
  158.  
  159.             $i++;
  160.  
  161.         }
  162.  
  163.         if(!$EXISTS){
  164.  
  165.             // if the database doesn't exist, create it
  166.  
  167.             $result=mysql_create_db($dest_db,$conn_id)  or
  168.  
  169.                 $retVal=$this->errorMessage("Unable to create database: $dest_db");
  170.  
  171.             if(isset($retVal)) return $retVal;
  172.  
  173.         }
  174.  
  175.         // at this point the remote database exists
  176.  
  177.  
  178.  
  179.         // get a list of the available tables on the source database
  180.  
  181.         $tables=mysql_list_tables($database,$this->id);
  182.  
  183.         $num_tables=mysql_num_rows($tables) or
  184.  
  185.             $retVal=$this->errorMessage("No tables found on database: $database, host: $this->host");
  186.  
  187.         if(isset($retVal)) return $retVal;
  188.  
  189.  
  190.  
  191.  
  192.  
  193.         // dump the data
  194.  
  195.         for($i=0;$i<$num_tables;$i++){    // for each table
  196.  
  197.             set_time_limit(60);
  198.  
  199.             $table=mysql_tablename($tables,$i);    // get the name
  200.  
  201.                 "$dest_user,$dest_pass,$dest_port,$dest_socket_path);<br>";
  202.  
  203.             // copy this table
  204.  
  205.             $this->CopyTable($table,$table,$database,$dest_db,$drop_tables,$conn_id,$dest_host,
  206.  
  207.                 $dest_user,$dest_pass,$dest_port,$dest_socket_path);
  208.  
  209.         }
  210.  
  211.         return TRUE;
  212.  
  213.     }
  214.  
  215.  
  216.  
  217.     function CopyTable($table,$dest_table,$database,$dest_db,$drop_table='',$conn_id='',$dest_host='',
  218.  
  219.             $dest_user='',$dest_pass='',$dest_port='',$dest_socket_path=''){
  220.  
  221.         // first, let's check to see if we are connected to a server already, if not, connect
  222.  
  223.         if(empty($conn_id)){
  224.  
  225.             $host=$dest_host;
  226.  
  227.             if($dest_port) $host.=":".$dest_port;
  228.  
  229.             if($dest_socket_path) $host.=":".$dest_socket_path;
  230.  
  231.             $conn_id=mysql_connect($dest_host,$dest_user,$dest_pass)  or
  232.  
  233.                 $retVal=$this->errorMessage("Unable to connect to mysql server: ".$dest_host);
  234.  
  235.             if(isset($retVal)) return $retVal;
  236.  
  237.  
  238.  
  239.         }
  240.  
  241.  
  242.  
  243.         if($drop_table){
  244.  
  245.             $drop="DROP TABLE IF EXISTS $dest_table;";
  246.  
  247.             mysql_select_db($dest_db);
  248.  
  249.             $result=mysql_query($drop,$conn_id)  or
  250.  
  251.                 $retVal=$this->errorMessage("Unable to perform query (drop $table) on database: $dest_host:".
  252.  
  253.                     "$dest_db<br><br>$drop<br><br>");
  254.  
  255.             if(isset($retVal)) return $retVal;
  256.  
  257.         }
  258.  
  259.  
  260.  
  261.         $struc="CREATE TABLE ".$dest_table." (\n";
  262.  
  263.         mysql_select_db($database);
  264.  
  265.         $result=mysql_query("SHOW FIELDS FROM $table",$this->id)  or
  266.  
  267.             $retVal=$this->errorMessage("Unable to copy table (fields): $table from database $database");
  268.  
  269.  
  270.  
  271.         if(isset($retVal)) return $retVal;
  272.  
  273.  
  274.  
  275.         while($row=mysql_fetch_array($result)){
  276.  
  277.             $struc.=" $row[Field] $row[Type]";
  278.  
  279.             if(isset($row['Default']) && (!empty($row['Default']) || $row['Default']=="0"))
  280.  
  281.                 $struc.=" DEFAULT '$row[Default]'";
  282.  
  283.             if($row['Null']!="YES")
  284.  
  285.                 $struc.=" NOT NULL";
  286.  
  287.             if($row['Extra']!="")
  288.  
  289.                 $struc.=" $row[Extra]";
  290.  
  291.             $struc.=",\n";
  292.  
  293.         }
  294.  
  295.         // remove the last comma
  296.  
  297.         $struc=ereg_replace(",\n$","",$struc);
  298.  
  299.  
  300.  
  301.         mysql_select_db($database);
  302.  
  303.         $result=mysql_query("SHOW KEYS FROM $table",$this->id)  or
  304.  
  305.             $retVal=$this->errorMessage("Unable to copy table (keys): $table from database $database");
  306.  
  307.         if(isset($retVal)) return $retVal;
  308.  
  309.  
  310.  
  311.         while($row=mysql_fetch_array($result)){
  312.  
  313.             $key_name=$row['Key_name'];
  314.  
  315.             if(($key_name!='PRIMARY') && ($row['Non_unique']==0))
  316.  
  317.                 $key_name="UNIQUE|$key_name";
  318.  
  319.             if(!isset($index[$key_name]))
  320.  
  321.                 $index[$key_name]=array();
  322.  
  323.             $index[$key_name][]=$row['Column_name'];
  324.  
  325.         }
  326.  
  327.  
  328.  
  329.         while(list($x,$columns)=@each($index)){
  330.  
  331.             $struc.=",\n";
  332.  
  333.             if($x=="PRIMARY")
  334.  
  335.                 $struc.=" PRIMARY KEY (".implode($columns,", ").")";
  336.  
  337.             else if(substr($x,0,6)=="UNIQUE")
  338.  
  339.                 $struc.=" UNIQUE ".substr($x,7)." (".implode($columns, ", ").")";
  340.  
  341.             else
  342.  
  343.                 $struc.=" KEY $x (".implode($columns, ", ").")";
  344.  
  345.         }
  346.  
  347.  
  348.  
  349.         $struc.="\n);";
  350.  
  351.         $struc=stripslashes(trim($struc));
  352.  
  353.  
  354.  
  355.         // do structure query
  356.  
  357.         mysql_select_db($databse);
  358.  
  359.         $result=mysql_query($dest_db,$struc,$conn_id)  or
  360.  
  361.             $retVal=$this->errorMessage("Unable to create $dest_host: ".$dest_db.".".$dest_table);
  362.  
  363.         if(isset($retVal)) return $retVal;
  364.  
  365.  
  366.  
  367.  
  368.  
  369.         // get data
  370.  
  371.         mysql_select_db($database);
  372.  
  373.         $result=mysql_query("SELECT * FROM $table",$this->id)  or
  374.  
  375.             $retVal=$this->errorMessage("Unable to perform query: $query");
  376.  
  377.         if(isset($retVal)) return $retVal;
  378.  
  379.  
  380.  
  381.         $num_rows=mysql_num_rows($result);
  382.  
  383.         $insert_data=array();
  384.  
  385.         for($i=0;$i<$num_rows;$i++){
  386.  
  387.             mysql_data_seek($result,$i) or $retVal=$this->errorMessage("Unable to seek data row: $row");
  388.  
  389.             if(isset($retVal)) return $retVal;
  390.  
  391.  
  392.  
  393.             $data=mysql_fetch_array($result) or $retVal=$this->errorMessage("Unable to fetch row: $row");
  394.  
  395.             if(isset($retVal)) return $retVal;
  396.  
  397.  
  398.  
  399.             $values='';
  400.  
  401.             while(list($key,$val)=@each($data)){
  402.  
  403.                 if(!is_int($key)){
  404.  
  405.                     $values.="$key = ";
  406.  
  407.                     $values.="'".addslashes($val)."', ";
  408.  
  409.                 }
  410.  
  411.             }
  412.  
  413.             $values=ereg_replace(", $","",$values);
  414.  
  415.             $insert_data[]="INSERT INTO $dest_table set $values";
  416.  
  417.         }
  418.  
  419.  
  420.  
  421.         while(list($k,$query)=@each($insert_data)){
  422.  
  423.             mysql_select_db($dest_db);
  424.  
  425.             $result=mysql_query($query,$conn_id)  or
  426.  
  427.                 $retVal=$this->errorMessage("Unable to perform query (data $table) on database: $dest_host: $dest_db");
  428.  
  429.             if(isset($retVal)) return $retVal;
  430.  
  431.         }
  432.  
  433.         return TRUE;
  434.  
  435.     }
  436.  
  437.  
  438.  
  439.     function SelectDB($db){
  440.  
  441.         $this->db=$db;
  442.  
  443.         if(mysql_select_db($db,$this->id))
  444.  
  445.             return TRUE;
  446.  
  447.         else
  448.  
  449.             return $this->errorMessage("Unable to select database: $db");
  450.  
  451.     }
  452.  
  453.  
  454.  
  455.     function GetTableList(){
  456.  
  457.         if($this->result=mysql_list_tables($this->db,$this->id)){
  458.  
  459.             $i=0;
  460.  
  461.             while($i < mysql_num_rows($this->result)){
  462.  
  463.                 $tb_names[$i]=mysql_tablename($this->result,$i);
  464.  
  465.                 $i++;
  466.  
  467.             }
  468.  
  469.             return($tb_names);
  470.  
  471.         }else
  472.  
  473.             return $this->errorMessage("Unable to find any tables in database: $this->db");
  474.  
  475.     }
  476.  
  477.  
  478.  
  479.     function GetFieldList($tbl_name){
  480.  
  481.         if($this->result=mysql_list_fields($this->db,$tbl_name,$this->id)){
  482.  
  483.             $i=0;
  484.  
  485.             while($i < mysql_num_fields($this->result)){
  486.  
  487.                 $fd_names[$i]=mysql_field_name($this->result,$i);
  488.  
  489.                 $i++;
  490.  
  491.             }
  492.  
  493.             return($fd_names);
  494.  
  495.         }else
  496.  
  497.             return $this->errorMessage("Unable to find any field list in table: $tbl_name");
  498.  
  499.     }
  500.  
  501.  
  502.  
  503.     function Delete($query){
  504.  
  505.         if($this->result=mysql_query($query,$this->id)){
  506.  
  507.             $this->a_rows=mysql_affected_rows($this->id);
  508.  
  509.             return TRUE;
  510.  
  511.         }else
  512.  
  513.             return $this->errorMessage("Unable to perform Delete: $query");
  514.  
  515.     }
  516.  
  517.  
  518.  
  519.     function Update($query){
  520.  
  521.         if($this->result=mysql_query($query,$this->id)){
  522.  
  523.             $this->a_rows=mysql_affected_rows($this->id);
  524.  
  525.             return TRUE;
  526.  
  527.         }else
  528.  
  529.             return $this->errorMessage("Unable to perform update: $query");
  530.  
  531.     }
  532.  
  533.  
  534.  
  535.     function Insert($query){
  536.  
  537.         if($this->result=mysql_query($query,$this->id)){
  538.  
  539.             $this->a_rows=mysql_affected_rows($this->id);
  540.  
  541.             return TRUE;
  542.  
  543.         }else
  544.  
  545.             return $this->errorMessage("Unable to perform insert: $query");
  546.  
  547.     }
  548.  
  549.  
  550.  
  551.     function InsertID(){
  552.  
  553.         if($this->result=mysql_insert_id($this->id)){
  554.  
  555.             return($this->result);
  556.  
  557.         }else
  558.  
  559.             return $this->errorMessage("Cannot retrieve auto_increment value: $this->id");
  560.  
  561.     }
  562.  
  563.  
  564.  
  565.     function Query($query){
  566.  
  567.         if($this->result=mysql_query($query,$this->id)){
  568.  
  569.             if(@mysql_num_rows($this->result))
  570.  
  571.                 $this->rows=mysql_num_rows($this->result);
  572.  
  573.             else
  574.  
  575.                 $this->rows=0;
  576.  
  577.             return TRUE;
  578.  
  579.         }else
  580.  
  581.             return $this->errorMessage("Unable to perform query: $query");
  582.  
  583.     }
  584.  
  585.  
  586.  
  587.     function GetRow($row){
  588.  
  589.         if(mysql_data_seek($this->result,$row)){
  590.  
  591.             if($this->data=mysql_fetch_array($this->result))
  592.  
  593.                 return TRUE;
  594.  
  595.             else
  596.  
  597.                 return $this->errorMessage("Unable to fetch row: $row");
  598.  
  599.         }else
  600.  
  601.             return $this->errorMessage("Unable to seek data row: $row");
  602.  
  603.     }
  604.  
  605.  
  606.  
  607.     function QueryRow($query){
  608.  
  609.         if($this->result=mysql_query($query,$this->id)){
  610.  
  611.             $this->rows=mysql_num_rows($this->result);
  612.  
  613.             if($this->data=mysql_fetch_array($this->result))
  614.  
  615.                 return($this->data);
  616.  
  617.             else
  618.  
  619.                 return $this->errorMessage("Unable to fetch data from query: $query");
  620.  
  621.         }else
  622.  
  623.             return $this->errorMessage("Unable to perform query: $query");
  624.  
  625.     }
  626.  
  627.  
  628.  
  629.     function QueryItem($query){
  630.  
  631.         if($this->result=mysql_query($query,$this->id)){
  632.  
  633.             $this->rows=mysql_num_rows($this->result);
  634.  
  635.             if($this->data=mysql_fetch_array($this->result))
  636.  
  637.                 return($this->data[0]);
  638.  
  639.             else
  640.  
  641.                 return $this->errorMessage("Unable to fetch data from query: $query");
  642.  
  643.         }else
  644.  
  645.             return $this->errorMessage("Unable to perform query: $query");
  646.  
  647.     }
  648.  
  649.  
  650.  
  651.     // returns XML-formatted record rows from query results.
  652.  
  653.     // $this->data holds the XML only, and the function returns the XML header + the data
  654.  
  655.     //  example:
  656.  
  657.     //  header("Content-type: text/xml");
  658.  
  659.     //  echo $sql->XML_Output("SELECT * FROM yourTable");
  660.  
  661.     // Thanks to Renй Moser <r.moser@meesly.ch>
  662.  
  663.     function XML_DataOutput($query, $tags = array('dataset','record')) {
  664.  
  665.         if($this->result=mysql_query($query,$this->id)) {
  666.  
  667.             $this->fields=mysql_num_fields($this->result);
  668.  
  669.             $xmlheader='<?xml version="1.0" ?>'."\n";
  670.  
  671.             $this->data.='<'.$tags[0].'>'."\n";
  672.  
  673.             while($this->rows = mysql_fetch_array($this->result)) {
  674.  
  675.                 $this->data.= "\t".'<'.$tags[1].'>'."\n";
  676.  
  677.                 for($i=0; $i<$this->fields; $i++) {
  678.  
  679.                     $tag = mysql_field_name($this->result,$i);
  680.  
  681.                     $this->data.="\t\t".'<'.$tag.'>'. preg_replace("/([\r\n])/", '', strip_tags($this->rows[$i])). '</'.$tag.'>'."\n";
  682.  
  683.                 }
  684.  
  685.                 $this->data.= "\t".'</'.$tags[1].'>'."\n";
  686.  
  687.              }
  688.  
  689.             $this->data.= '</'.$tags[0].'>';
  690.  
  691.             return $xmlheader.$this->data;
  692.  
  693.         }else
  694.  
  695.             return $this->errorMessage("Unable to perform query: $query; in XML output");
  696.  
  697.     }
  698.  
  699.  
  700.  
  701.     // Thanks to Andrew Collington <amnuts@talker.com> for the update
  702.  
  703.     function Exists($query){
  704.  
  705.         if ($this->result=mysql_query($query,$this->id)){
  706.  
  707.             if(mysql_num_rows($this->result))
  708.  
  709.                 return TRUE;
  710.  
  711.             else
  712.  
  713.                 return FALSE;
  714.  
  715.         }else
  716.  
  717.             return $this->errorMessage("Unable to perform query: $query");
  718.  
  719.     }
  720.  
  721.  
  722.  
  723.     // Thanks to Andrew Collington <amnuts@talker.com>
  724.  
  725.     function GetSetList($table,$field){
  726.  
  727.         $query="SHOW COLUMNS FROM $table LIKE '$field'";
  728.  
  729.         if($this->result=mysql_query($query,$this->id)){
  730.  
  731.             if($this->data=mysql_fetch_array($this->result)){
  732.  
  733.                 while(list($key,$val)=@each($this->data)){
  734.  
  735.                     $this->data[$key]=stripslashes($val);
  736.  
  737.                 }
  738.  
  739.                 $mySet=split("','",substr($this->data[1],5,-2));
  740.  
  741.                 return $mySet;
  742.  
  743.             }else
  744.  
  745.                 return $this->errorMessage("Unable to fetch data set from: $query");
  746.  
  747.         }else
  748.  
  749.             return $this->errorMessage("Unable to perform set fetch: $query");
  750.  
  751.     }
  752.  
  753.  
  754.  
  755.     // Thanks to Andrew Collington <amnuts@talker.com>
  756.  
  757.     function GetEnumList($table,$field){
  758.  
  759.         $query="SHOW COLUMNS FROM $table LIKE '$field'";
  760.  
  761.         if($this->result=mysql_query($query,$this->id)){
  762.  
  763.             if($this->data=mysql_fetch_array($this->result)){
  764.  
  765.                 while(list($key,$val)=@each($this->data)){
  766.  
  767.                     $this->data[$key]=stripslashes($val);
  768.  
  769.                 }
  770.  
  771.                 $myEnum=split("','",substr($this->data[1],6,-2));
  772.  
  773.                 return $myEnum;
  774.  
  775.             }else
  776.  
  777.                 return $this->errorMessage("Unable to fetch data enum from: $query");
  778.  
  779.         }else
  780.  
  781.             return $this->errorMessage("Unable to perform enum fetch: $query");
  782.  
  783.     }
  784.  
  785.  
  786.  
  787.     // Use this function to insert the binary image data of a picrutre into a database
  788.  
  789.     function InsertImage($image,$table,$blob_field,$num_att_cols,$atts1,$atts2='',$atts3='',$where_clause){
  790.  
  791.         // Examples of using this function
  792.  
  793.         // $sql->InsertImage($_FILES['userfile'],'my_table','my_blob_field',1,'attributes',0,"id = '1'");
  794.  
  795.         // $sql->InsertImage($_FILES['userfile'],'my_table','my_blob_field',2,'image_width','image_height',"id = '1'");
  796.  
  797.         $size=getimagesize($image['tmp_name']);
  798.  
  799.         switch($size[2]){
  800.  
  801.             case 1:  $type = 'GIF'; break;
  802.  
  803.             case 2:  $type = 'JPG'; break;
  804.  
  805.             case 3:  $type = 'PNG'; break;
  806.  
  807.             case 4:  $type = 'SWF'; break;
  808.  
  809.             case 5:  $type = 'PSD'; break;
  810.  
  811.             case 6:  $type = 'BMP'; break;
  812.  
  813.             case 7:  $type = 'TIFF(intel byte order)'; break;
  814.  
  815.             case 8:  $type = 'TIFF(motorola byte order)'; break;
  816.  
  817.             case 9:  $type = 'JPC'; break;
  818.  
  819.             case 10: $type = 'JP2'; break;
  820.  
  821.             case 11: $type = 'JPX'; break;
  822.  
  823.         }
  824.  
  825.  
  826.  
  827.                 $fd=fopen($image['tmp_name'],"r");
  828.  
  829.                 $data=addslashes(fread($fd,$image['size']));
  830.  
  831.                 fclose($fd);
  832.  
  833.  
  834.  
  835.         $q="UPDATE `".$table."` SET `".$blob_field."` = '".$data."'";
  836.  
  837.         switch($num_att_cols){
  838.  
  839.             case 1: $q.=", `".$atts1."` = '".$size[3]."'";
  840.  
  841.                     break; // width and height HTML attribute string
  842.  
  843.             case 2: if($atts2)
  844.  
  845.                         $q.=", `".$atts1."` = '".$size[0]."', `".$atts2."` = '".$size[1]."'"; // width integer, height integer
  846.  
  847.                     else if($atts3){
  848.  
  849.                         $q.=", `".$atts1."` = '".$size[0]."', `".$atts3."` = '".$type."'"; // HTML attribute string, image type
  850.  
  851.                     }
  852.  
  853.                     break;
  854.  
  855.             case 3: $q.=", `".$atts1."` = '".$size[0]."', `".$atts2."` = '".$size[1]."', `".$atts3."` = '".$size[1]."'";
  856.  
  857.                     break; // width integer, height integer, image type
  858.  
  859.         }
  860.  
  861.         $q.=" WHERE ".$where_clause;
  862.  
  863.  
  864.  
  865.         return $this->Update($q);
  866.  
  867.     }
  868.  
  869.  
  870.  
  871.     // use this function to get the binary data from the database
  872.  
  873.     function GetImage($table,$blob_field,$num_att_cols,$atts1,$atts2='',$atts3='',$where_clause){
  874.  
  875.         $q="select `".$blob_field."`";
  876.  
  877.         switch($num_att_cols){
  878.  
  879.             case 1: $q.=", `".$atts1."`";
  880.  
  881.                     break; // width and height HTML attribute string
  882.  
  883.             case 2: if($atts2)
  884.  
  885.                         $q.=", `".$atts1."`, `".$atts2."`"; // width integer, height integer
  886.  
  887.                     else if($atts3){
  888.  
  889.                         $q.=", `".$atts1."`, `".$atts3."`"; // HTML attribute string, image type
  890.  
  891.                     }
  892.  
  893.                     break;
  894.  
  895.             case 3: $q.=", `".$atts1."`, `".$atts2."`, `".$atts3."`";
  896.  
  897.                     break; // width integer, height integer, image type
  898.  
  899.         }
  900.  
  901.         $q.=" from `".$table."` where ".$where_clause;
  902.  
  903.         if(!$this->Query($q))
  904.  
  905.             return $this->errorMessage('Error selecting image');
  906.  
  907.         if($this->rows < 2){
  908.  
  909.             if(!$this->GetRow(0))
  910.  
  911.                 return $this->errorMessage('Error selecting image');
  912.  
  913.          }
  914.  
  915.         return $this->data;
  916.  
  917.     }
  918.  
  919.  
  920.  
  921.     function errorMessage($msg){
  922.  
  923.         return "Error: $msg : ".mysql_error();
  924.  
  925.     }
  926.  
  927. }
  928.  
  929. ?>
  930.  
  931.  

(Добавление)
Denkill пишет:
Что за класс phpMysqlConnection (если пользовательский то код в студию)
PHP:
скопировать код в буфер обмена
  1.  $SESS_SQL=new phpMysqlConnection($SQL_USER,$SQL_PASS,$SQL_HOST);


Denkill, надеюсь, я верно выполнил твое поручение. Прошу прощения за свое невежество, я к сожалению совсем нуб в РНР, но вещь интересная, и хотелось бы разбираться, а для этой ошибки, похоже мне еще очень очень далеко, поэтому обращаюсь к гуру РНР.
Спасибо!
(Добавление)
Denkill пишет:
Что за класс phpMysqlConnection (если пользовательский то код в студию)
PHP:
скопировать код в буфер обмена
  1.  $SESS_SQL=new phpMysqlConnection($SQL_USER,$SQL_PASS,$SQL_HOST);


Denkill, надеюсь, я верно выполнил твое поручение. Прошу прощения за свое невежество, я к сожалению совсем нуб в РНР, но вещь интересная, и хотелось бы разбираться, а для этой ошибки, похоже мне еще очень очень далеко, поэтому обращаюсь к гуру РНР.
Спасибо!
(Добавление)
PHP:
скопировать код в буфер обмена
  1.  // To use the class, you will first need to include the class file
  2.     include "class.phpMysqlConnection.php";
  3.  
  4.     // The next step will be to set up a variable to represent the object
  5.     // created. I usually use the name 'sql' for clarity, but it can be whatever.
  6.     $sql=new phpMysqlConnection($sql_user,$sql_pass,$sql_host);
  7.  
  8.     // I usually use this format, and store the variables in a different
  9.     // include file with other site-wide config settings. If you leave out
  10.     // $sql_host from the above line, "localhost" (when MySQL server and web
  11.     // server are on the same machine) is assumed.

(Отредактировано автором: 09 Июля, 2013 - 11:57:58)

 
 Top
imya
Отправлено: 09 Июля, 2013 - 12:22:35
Post Id



Участник


Покинул форум
Сообщений всего: 1472
Дата рег-ции: Сент. 2012  
Откуда: Запорожье, Украина


Помог: 19 раз(а)




dfcbkbq , а зачем сразу в такие дебри лезть, если нуб ? Хм


-----
PHP:
скопировать код в буфер обмена
  1. do {box != cat;} while (cat != box);


Когда нормальный человек, уезжая из дома одевает на жену пояс верности, веб-дизайнер ставит на нее счетчик...
 
My status
 Top
dfcbkbq
Отправлено: 09 Июля, 2013 - 12:25:16
Post Id


Новичок


Покинул форум
Сообщений всего: 4
Дата рег-ции: Июль 2013  


Помог: 0 раз(а)




на сайте нужно произвести некоторые изменения, а я войти на него не могу... Огорчение
 
 Top
FOMINTIMUR
Отправлено: 04 Августа, 2013 - 18:48:27
Post Id


Новичок


Покинул форум
Сообщений всего: 6
Дата рег-ции: Авг. 2013  


Помог: 0 раз(а)




А у меня выводит Fatal error: Call to undefined function mysqli_connect() in C:\apache\test.ru\www\php\dbcontroller.php on line 15. Библиотека стоит и раскомментированна и в среде путь прописан.
PHP:
скопировать код в буфер обмена
  1. <?PHP
  2. /*
  3. ** Class for connecting and manage the mysql database
  4. */
  5. require_once("constants.php");
  6. require_once("utils.php");
  7.  
  8. class DBController{
  9.        
  10.         private $link;
  11.        
  12.         public function __construct(){
  13.                 mb_internal_encoding("UTF-8");
  14.                 mb_regex_encoding("UTF-8");
  15.                 $this->link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS,DB_NAME);
  16.                 if (mysqli_connect_errno()) {
  17.                     exit();
  18.                 }
  19.         }
  20.        
  21.         public function __destruct() {
  22.                 $this->disconnect();
  23.         }
  24.        
  25.         /*
  26.          * checks if user with email "$username" and password "$password" exists
  27.          * */
  28.         public function confirmUserPass($username, $password){
  29.                 $username = mysqli_real_escape_string($this->link,$username);
  30.                 /* Verify that user is in database */
  31.                 $q = "SELECT password FROM users WHERE email = '$username'";
  32.                 $results = mysqli_query($this->link,$q);
  33.                 if(!$results || (mysqli_num_rows($results) < 1)){
  34.                         mysqli_free_result($results);
  35.                         return -1; //Indicates username failure
  36.                 }
  37.                 $dbarray = mysqli_fetch_array($results,MYSQLI_ASSOC);
  38.                 $dbarray['password'] = stripslashes($dbarray['password']);
  39.                 $password = stripslashes($password);
  40.                 mysqli_free_result($results);
  41.                
  42.                 if($password == $dbarray['password']){
  43.                         return 1; //Success, Username and password confirmed
  44.                 }
  45.                 else{
  46.                         return -2; //Indicates password failure
  47.                 }
  48.         }
  49.  
  50.    
  51.         /**
  52.     * confirmUserID - Checks whether or not the given
  53.     * username is in the database, if so it checks if the
  54.     * given userid is the same userid in the database
  55.     * for that user. If the user doesn't exist or if the
  56.     * userids don't match up, it returns an error code
  57.     */
  58.         public function confirmUserID($username, $userid){
  59.                 $username = mysqli_real_escape_string($this->link,$username);
  60.  
  61.                 /* Verify that user is in database */
  62.                 $q = "SELECT usr_userid FROM users WHERE pk_user = '$username'";
  63.                
  64.                 $results = mysqli_query($this->link,$q);
  65.                  
  66.                 if(!$results || (mysqli_num_rows($results) < 1)){
  67.                         mysqli_free_result($results);
  68.                         return -1; //Indicates username failure
  69.                 }
  70.  
  71.                 /* Retrieve userid from result, strip slashes */
  72.                 $dbarray = mysqli_fetch_array($results,MYSQLI_ASSOC);
  73.                 $dbarray['usr_userid'] = stripslashes($dbarray['usr_userid']);
  74.                 $userid = stripslashes($userid);
  75.                 mysqli_free_result($results);  
  76.                 /* Validate that userid is correct */
  77.  
  78.                 if($userid == $dbarray['usr_userid']){
  79.                         return 1; //Success! Username and userid confirmed
  80.                 }
  81.                 else{
  82.                         return -2; //Indicates userid invalid
  83.                 }
  84.    }
  85.    
  86.         /*
  87.         * dbemailTaken - Returns true if the email has
  88.         * been taken by another user, false otherwise.
  89.         */
  90.         public function dbemailTaken($email){
  91.                 $email = mysqli_real_escape_string($this->link,$email);
  92.                 $q = "SELECT email FROM users WHERE email = '$email'";
  93.                 $results = mysqli_query($this->link,$q);
  94.                 $numr = mysqli_num_rows($results);
  95.                 mysqli_free_result($results);  
  96.                 return ($numr > 0);
  97.         }
  98.    
  99.    
  100.         /*
  101.         ** registers a user in the system, and returns user key if successfull
  102.         */
  103.         public function dbregister($email, $pass, $flname, $hash, $country_code){
  104.                
  105.                 $email                  = mysqli_real_escape_string($this->link,$email);
  106.                 $pass                   = mysqli_real_escape_string($this->link,$pass);
  107.                 $flname                 = mysqli_real_escape_string($this->link,$flname);
  108.                 $country_code   = mysqli_real_escape_string($this->link,$country_code);
  109.                
  110.                 $ip = getRealIpAddr();
  111.                
  112.                 //############### INSERTION ###############    
  113.                 mysqli_autocommit($this->link,FALSE);
  114.                 mysqli_query($this->link,"SET NAMES 'utf8'");
  115.                 $q = "insert into users(pk_user,email,flname,password,usr_confirm_hash,country_code,usr_ip) values('NULL','$email','$flname','$pass','$hash','$country_code','$ip')";
  116.            
  117.                 mysqli_query($this->link,$q);
  118.                 if(mysqli_errno($this->link)){
  119.                         mysqli_rollback($this->link);
  120.                         return -1;
  121.                 }
  122.                 else{
  123.                         mysqli_commit($this->link);
  124.                         $result = mysqli_query($this->link,'SELECT LAST_INSERT_ID() as lid');
  125.                         $obj = $result->fetch_object();
  126.                         $lastinsertedid = $obj->lid;
  127.                         $result->close();
  128.                         unset($obj);
  129.                         return $lastinsertedid;
  130.                 }
  131.                 return -1;
  132.         }  
  133.    
  134.  
  135.    
  136.         /*
  137.          * checks if user with email "$email" did already the confirmation of the account
  138.          * */
  139.     public function is_confirmed($username){
  140.                 $q = "SELECT usr_is_confirmed FROM users WHERE email = '$username'";           
  141.                 $results = mysqli_query($this->link,$q);
  142.                 $dbarray = mysqli_fetch_array($results,MYSQLI_ASSOC);
  143.                 $is_confirmed = $dbarray['usr_is_confirmed'];
  144.                 mysqli_free_result($results);
  145.                 if($is_confirmed == 1){
  146.                         return 1; //Success!
  147.                 }
  148.                 else{
  149.                         return -1; //Indicates failure
  150.                 }
  151.         }
  152.  
  153.         /*
  154.         * checks if user with email "$email" is blocked
  155.         * */
  156.     public function is_blocked($username){
  157.                 $q = "SELECT usr_is_blocked FROM users WHERE email = '$username'";             
  158.                 $results = mysqli_query($this->link,$q);
  159.                 $dbarray = mysqli_fetch_array($results,MYSQLI_ASSOC);
  160.                 $usr_is_blocked = $dbarray['usr_is_blocked'];
  161.                 mysqli_free_result($results);
  162.                 if($usr_is_blocked == 1){
  163.                         return 1; //blocked
  164.                 }
  165.                 else{
  166.                         return -1; //Indicates failure
  167.                 }
  168.         }
  169.        
  170.     /*
  171.      * checks if the resethash is associated with the email in the users table
  172.      */
  173.         public function dbconfirmResetPasswordHash($email,$hash){
  174.                 $email = mysqli_real_escape_string($this->link,$email);
  175.                 $q = "SELECT pk_user FROM users WHERE email = '$email' and usr_resetpassword_hash = '$hash'";  
  176.                 $results = mysqli_query($this->link,$q);
  177.                
  178.                 $numr = mysqli_num_rows($results);
  179.                 mysqli_free_result($results);  
  180.                 if($numr > 0)
  181.                         return 1;
  182.                 else
  183.                         return -1;
  184.         }
  185.  
  186.         /**
  187.     * updateUserField - Updates a field, specified by the field
  188.     * parameter, in the user's row of the database, given the pk_user
  189.     */
  190.         public function updateUserField($userkey, $field, $value){
  191.                 $q = "UPDATE users SET ".$field." = '$value' WHERE pk_user = '$userkey'";      
  192.                 mysqli_query($this->link,$q);
  193.                 if(mysqli_errno($this->link)){
  194.                         return -1;
  195.                 }
  196.                 return 1;
  197.         }
  198.        
  199.         /**
  200.     * deleteUser - Deletes a User
  201.     */
  202.         public function deleteUser($userkey){
  203.                 $q = "DELETE from users WHERE pk_user = '$userkey'";   
  204.                 mysqli_query($this->link,$q);
  205.                 if(mysqli_errno($this->link)){
  206.                         return -1;
  207.                 }
  208.                 return 1;
  209.         }
  210.        
  211.         /**
  212.     * updateUserFieldEmail - Updates a field, in the user's row of the database, given the email
  213.     */
  214.         public function updateUserFieldEmail($email, $field, $value){
  215.                 $email = mysqli_real_escape_string($this->link,$email);
  216.                 $q = "UPDATE users SET ".$field." = '$value' WHERE email = '$email'";  
  217.                 return mysqli_query($this->link,$q);
  218.         }
  219.        
  220.         /**
  221.     * dbgetUserInfo - Returns the result array from a mysql
  222.     * query asking for some data regarding
  223.     * the given username(email). If query fails, NULL is returned.
  224.     */
  225.         public function dbgetUserInfoEmail($email){
  226.                 $email = mysqli_real_escape_string($this->link,$email);
  227.                 $q = "SELECT pk_user,email,usr_userid FROM users WHERE email = '$email'";              
  228.                 $results = mysqli_query($this->link,$q);
  229.                 /* Error occurred, return given name by default */
  230.                 if(!$results || (mysqli_num_rows($results) < 1)){
  231.                         mysqli_free_result($results);
  232.                         return NULL;
  233.                 }
  234.                 /* Return result array */
  235.                 $dbarray = mysqli_fetch_array($results,MYSQLI_ASSOC);
  236.                 mysqli_free_result($results);
  237.                 return $dbarray;
  238.         }
  239.        
  240.         /**
  241.     * dbgetUserInfo - Returns the result array from a mysql
  242.     * query asking for some data regarding
  243.     * the given username(pk_user). If query fails, NULL is returned.
  244.     */
  245.         public function dbgetUserInfo($username){
  246.                 $username = mysqli_real_escape_string($this->link,$username);
  247.                 $q = "SELECT pk_user,email,usr_userid FROM users WHERE pk_user = '$username'";         
  248.                 $results = mysqli_query($this->link,$q);
  249.                 /* Error occurred, return given name by default */
  250.                 if(!$results || (mysqli_num_rows($results) < 1)){
  251.                         mysqli_free_result($results);
  252.                         return NULL;
  253.                 }
  254.                 /* Return result array */
  255.                 $dbarray = mysqli_fetch_array($results,MYSQLI_ASSOC);
  256.                 mysqli_free_result($results);
  257.                 return $dbarray;
  258.         }
  259.  
  260.         /**
  261.     * dbgetUserAccountDetails - Returns the result array from a mysql
  262.     * query asking for some data regarding
  263.     * the given username(email). If query fails, NULL is returned.
  264.     */
  265.         public function dbgetUserAccountDetails($userkey){
  266.                 $q = "SELECT U.*,C.country_name FROM users U,Country C WHERE U.pk_user = '$userkey' AND C.country_code = U.country_code";
  267.                        
  268.                 $results = mysqli_query($this->link,$q);
  269.                 /* Error occurred, return given name by default */
  270.                 if(!$results || (mysqli_num_rows($results) < 1)){
  271.                         mysqli_free_result($results);
  272.                         return NULL;
  273.                 }
  274.                 /* Return result array */
  275.                 $dbarray = mysqli_fetch_array($results,MYSQLI_ASSOC);
  276.                 mysqli_free_result($results);
  277.                 return $dbarray;
  278.         }      
  279.        
  280.         public function user_confirm($urlemail,$urlhash) {
  281.                 $new_hash = sha1($urlemail.supersecret_hash_padding);
  282.                 if ($new_hash && ($new_hash == $urlhash)) {
  283.                         $q = "SELECT email FROM users WHERE usr_confirm_hash = '$new_hash'";
  284.                         $results = mysqli_query($this->link,$q);
  285.                        
  286.                         if (!$results || (mysqli_num_rows($results) < 1)) {
  287.                                 $feedback = 'ERROR -- Hash not found';
  288.                                 mysqli_free_result($results);
  289.                                 return $feedback;
  290.                         }
  291.                         else {
  292.                         // Confirm the email and set account to active
  293.                         $email = $urlemail;
  294.                         $hash = $urlhash;
  295.  
  296.                         $query = "UPDATE users SET usr_is_confirmed='1' WHERE usr_confirm_hash='$hash'";
  297.                         mysqli_query($this->link,$query);
  298.                         return 1;
  299.                         }
  300.                 }
  301.                 else {
  302.                         $feedback = 'ERROR -- Values do not match';
  303.                         return $feedback;
  304.                 }
  305.         }
  306.  
  307.         /*
  308.         * checks if value matches a field in the table users
  309.         */
  310.         public function matchUserField($value,$field,$userkey){
  311.                 $value                  = mysqli_real_escape_string($this->link,$value);
  312.                 $q = "SELECT pk_user FROM users WHERE ".$field." = '$value' and pk_user = '$userkey'";
  313.                
  314.                 $results = mysqli_query($this->link,$q);
  315.                 $numr = mysqli_num_rows($results);
  316.                 mysqli_free_result($results);  
  317.                 return ($numr > 0);
  318.         }
  319.        
  320.         /*
  321.         ** changes the user account details, and returns 1 successfull
  322.         */
  323.         public function dbeditaccount($email, $flname, $country_code, $pass, $userkey){
  324.                
  325.                 $email                  = mysqli_real_escape_string($this->link,$email);
  326.                 $pass                   = mysqli_real_escape_string($this->link,$pass);
  327.                 $flname                 = mysqli_real_escape_string($this->link,$flname);
  328.                 $country_code   = mysqli_real_escape_string($this->link,$country_code);
  329.                
  330.                 //############### UPDATE ###############       
  331.                 mysqli_autocommit($this->link,FALSE);
  332.                 mysqli_query($this->link,"SET NAMES 'utf8'");
  333.                 $q="";
  334.                 if($pass)
  335.                         $q = "UPDATE users SET email='$email',flname='$flname',password='$pass',country_code='$country_code' where pk_user = '$userkey'";
  336.             else
  337.                 $q = "UPDATE users SET email='$email',flname='$flname',country_code='$country_code' where pk_user = '$userkey'";
  338.                
  339.             mysqli_query($this->link,$q);
  340.                 if(mysqli_errno($this->link)){
  341.                         mysqli_rollback($this->link);
  342.                         return -1;
  343.                 }
  344.                 else{
  345.                         mysqli_commit($this->link);
  346.                         return 1;
  347.                 }
  348.                 return -1;
  349.         }  
  350.        
  351.         /*
  352.         * checks if a country typed by the user exists in the table country. Returns the id of the country, or null
  353.         */
  354.         public function dbexistsCountry($country_name){
  355.                 $country_name_lower = mb_strtolower(html_entity_decode($country_name,ENT_NOQUOTES, 'UTF-8'));
  356.                 $q = "SELECT country_code FROM Country WHERE LOWER(country_name) = '$country_name_lower'";     
  357.                 $results = mysqli_query($this->link,$q);               
  358.                 if(!$results || (mysqli_num_rows($results) < 1)){
  359.                         mysqli_free_result($results);
  360.                         return null; //Indicates country check failure
  361.                 }
  362.                 $dbarray = mysqli_fetch_array($results,MYSQLI_ASSOC);
  363.                 $dbarray['country_code'] = stripslashes($dbarray['country_code']);
  364.                 mysqli_free_result($results);  
  365.                 return $dbarray['country_code'];
  366.         }  
  367.        
  368.         /**
  369.         *       Increments the number of logins of a user
  370.         **/
  371.         public function incrementLogins($userkey){
  372.                 $q = "SELECT usr_nmb_logins FROM users WHERE pk_user = '$userkey'";
  373.                 $results = mysqli_query($this->link,$q);
  374.                 if(!$results || (mysqli_num_rows($results) < 1)){
  375.                         mysqli_free_result($results);
  376.                         return -1;
  377.                 }
  378.                 else{
  379.                         $dbarray = mysqli_fetch_array($results,MYSQLI_ASSOC);
  380.                         $nmb_logins = $dbarray['usr_nmb_logins'];
  381.                         $nmb_logins_inc = $nmb_logins + 1 ;
  382.                         mysqli_free_result($results);
  383.                        
  384.                         mysqli_autocommit($this->link,FALSE);
  385.                         $qu = "update users set usr_nmb_logins = '$nmb_logins_inc' WHERE pk_user = '$userkey'";
  386.                         mysqli_query($this->link,$qu);
  387.                        
  388.                         if(mysqli_errno($this->link)){
  389.                                 mysqli_rollback($this->link);
  390.                                 return -2;//Indicates error updating row
  391.                         }
  392.                         else{
  393.                                 mysqli_commit($this->link);
  394.                                 return 1;
  395.                         }
  396.                 }
  397.                 return -3;
  398.         }
  399.        
  400.         /*
  401.          * returns the array with the users per country info
  402.          * note: it just includes the users that have their accounts confirmed!
  403.          * It does not includes the user viewing this (admin)
  404.          * */
  405.         public function getUsersPerCountry($userkey){
  406.                 $q = "SELECT COUNT(*) AS value,users.country_code,country_name FROM users INNER JOIN Country ON Country.country_code = users.country_code WHERE usr_is_confirmed=1 and pk_user <> '$userkey' GROUP BY users.country_code";             
  407.                 $results = mysqli_query($this->link,$q);
  408.                 /* Error occurred, return given name by default */
  409.                 if(!$results || (mysqli_num_rows($results) < 1)){
  410.                         mysqli_free_result($results);
  411.                         return NULL;
  412.                 }
  413.                 /* Return result array */
  414.                
  415.                 $aResults = array();
  416.                 while ($row = $results->fetch_assoc()) {
  417.                         $aResults[] = array( "country_name"=>$row['country_name'] ,"value"=>$row['value']);
  418.                 }
  419.                 mysqli_free_result($results);
  420.                 return $aResults;
  421.         }
  422.  
  423.         /*
  424.          * returns the array with the users data
  425.          * */
  426.         public function getUsersData($userkey){
  427.                 mysqli_query($this->link,"SET NAMES 'utf8'");  
  428.                 $q = "SELECT pk_user,country_name,email,flname,usr_ip,usr_nmb_logins,usr_signup_date,usr_is_blocked,usr_is_admin FROM users INNER JOIN Country ON Country.country_code=users.country_code WHERE usr_is_confirmed=1 and pk_user <> '$userkey'";         
  429.                
  430.                 $results = mysqli_query($this->link,$q);
  431.                 /* Error occurred, return given name by default */
  432.                 if(!$results || (mysqli_num_rows($results) < 1)){
  433.                         mysqli_free_result($results);
  434.                         return NULL;
  435.                 }
  436.                 /* Return result array */
  437.                 $aResults = array();
  438.                 while ($row = $results->fetch_assoc()) {
  439.                         $aResults[] = array( "pk_user"=>$row['pk_user'] ,"country_name"=>$row['country_name'] ,"email"=>$row['email'],"flname"=>$row['flname'],"usr_ip"=>$row['usr_ip'],"usr_nmb_logins"=>$row['usr_nmb_logins'],"usr_signup_date"=>$row['usr_signup_date'],"usr_is_blocked"=>$row['usr_is_blocked'],"usr_is_admin"=>$row['usr_is_admin']);
  440.                 }
  441.                 mysqli_free_result($results);
  442.                 return $aResults;
  443.         }
  444.        
  445.         /**
  446.     * query - Performs the given query on the database and
  447.     * returns the result, which may be false, true or a
  448.     * resource identifier.
  449.     */
  450.         public function query($query){
  451.                 return mysqli_query($this->link,$query);
  452.         }
  453.    
  454.         public function disconnect(){
  455.                 mysqli_close($this->link);
  456.         }  
  457.    
  458.  
  459. };
  460. ?>
  461.  
 
 Top
Страниц (1): [1]
Сейчас эту тему просматривают: 0 (гостей: 0, зарегистрированных: 0)
« Если скрипт не работает »


Все гости форума могут просматривать этот раздел.
Только зарегистрированные пользователи могут создавать новые темы в этом разделе.
Только зарегистрированные пользователи могут отвечать на сообщения в этом разделе.
 



Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB