PHP . SU
Программирование на PHP, MySQL и другие веб-технологии
Без описания
Поиск в теме | Версия для печати
Safok
Отправлено: 04 Июля, 2013 - 15:15:58
Гость
Покинул форум
Сообщений всего: 96
Дата рег-ции: Март 2013
Помог: 0 раз(а)
[+]
Есть пхп код который рисует юзербар, нужно найти ошибку и исправить:
Спойлер (Отобразить ) PHP:
скопировать код в буфер обмена
<?PHP
header ( 'Cache-Control: public, max-age=900, must-revalidate' ) ; define ( 'DATALIFEENGINE' , true ) ; define ( 'ENGINE_DIR' , ROOT_DIR
. '/engine' ) ; define ( 'UB_DIR' , ROOT_DIR
. '/engine/modules/userbar/' ) ;
require_once ENGINE_DIR . '/classes/mysql.php' ;
require_once ENGINE_DIR . '/data/dbconfig.php' ;
require_once ENGINE_DIR . '/data/config.php' ;
require_once ENGINE_DIR . '/modules/functions.php' ;
require_once ENGINE_DIR . '/data/ub_config.php' ;
if ( preg_match ( "/[\||\'|\<|\>|\" |\!|\?|\$ |\@|\/|\\ \|\&\~\*\+]/" , $_GET [ 'name' ] ) ) die ( "Not allowed user name!" ) ;
$name = $db -> safesql ( iconv ( "utf-8" , "cp1251//IGNORE" , urldecode ( $_GET [ 'name' ] ) ) ) ;
if ( $ub_cfg [ 'repa_on' ] == 0)
$query = $db -> query ( "SELECT comm_num, foto, news_num FROM " . USERPREFIX . "_users where name='$name ' LIMIT 1" ) ;
else
$query = $db -> query ( "SELECT comm_num, foto, news_num FROM " . USERPREFIX . "_users where name='$name ' LIMIT 1" ) ;
if ( $db -> num_rows ( $query ) == 0)
die ( 'Пользователя не существует' ) ; $row = $db -> get_row ( $query ) ;
header ( 'Content-type: image/png' ) ;
$colorsDef = explode ( ',' , $ub_cfg [ 'color_font' ] ) ; foreach ( $colorsDef as $colorDef )
$colors [ ] = trim ( $colorDef ) ;
$font = UB_DIR . $ub_cfg [ 'font' ] ;
if ( $ub_cfg [ 'ava_on' ] == 1)
$ubsize = 120 ;
if ( $ub_cfg [ 'name_on' ] == 1)
$textn = iconv ( "cp1251" , "utf-8//IGNORE" , $name ) ; if ( $ub_cfg [ 'comm_on' ] == 1)
$textc = $row [ 'comm_num' ] ;
if ( $ub_cfg [ 'news_on' ] == 1)
$textne = $row [ 'news_num' ] ;
if ( $ub_cfg [ 'ava_on' ] == 1)
$textf = $row [ 'foto' ] ;
$photo = ROOT_DIR . "/skins/avatar.php?s=120&u=1.png" ;
function imagecreatefromjpg( $arg )
{
}
if ( $ub_cfg [ 'ava_on' ] == 1)
$funct = 'imagecreatefrom' . end ( explode ( '.' , $photo ) ) ; if ( $ub_cfg [ 'ava_on' ] == 1)
$src = $funct ( $photo ) ;
if ( $ub_cfg [ 'ava_on' ] == 1)
$height = $size [ 1] ;
$width = $size [ 0] ;
$maxheight = $ub_cfg [ 'maxheight' ] ;
$maxwidth = $ub_cfg [ 'maxwidth' ] ;
if ( $height > $maxheight ) {
$diff = $height / ( $height - 100) ;
$height = $maxheight ;
$width = $width - ( $width / $diff ) ;
}
if ( $width > $maxwidth ) {
$diff = $width / ( $width - 100) ;
$height = $height - ( $height / $diff ) ;
$width = $maxwidth ;
}
if ( $ub_cfg [ 'ava_on' ] == 1)
$destY = ( $ubsize - $height ) / 2 ;
if ( $ub_cfg [ 'ava_on' ] == 1)
imagecopyresized ( $im , $src , $ub_cfg [ 'ava_x' ] , $destY , 0
, 0
, $width , $height , $size [ 0
] , $size [ 1
] ) ; if ( $ub_cfg [ 'name_on' ] == 1)
imagettftext ( $im , $ub_cfg [ 'font_size' ] , 0
, $ub_cfg [ 'name_x' ] , $ub_cfg [ 'name_y' ] , $color , $font , $textn ) ;
if ( $ub_cfg [ 'comm_on' ] == 1)
imagettftext ( $im , $ub_cfg [ 'font_size' ] , 0
, $ub_cfg [ 'comm_x' ] , $ub_cfg [ 'comm_y' ] , $color , $font , $textc ) ;
if ( $ub_cfg [ 'repa_on' ] == 1)
imagettftext ( $im , $ub_cfg [ 'font_size' ] , 0
, $ub_cfg [ 'repa_x' ] , $ub_cfg [ 'repa_y' ] , $color , $font , $textr ) ;
if ( $ub_cfg [ 'news_on' ] == 1)
imagettftext ( $im , $ub_cfg [ 'font_size' ] , 0
, $ub_cfg [ 'news_x' ] , $ub_cfg [ 'news_y' ] , $color , $font , $textne ) ;
$db -> close ( ) ;
?>
Изображение аватарки получаю тут http://minecraft[dot]industrialdelux[dot][dot][dot]=120&u=1[dot]png
dfcbkbq
Отправлено: 04 Июля, 2013 - 16:47:04
Новичок
Покинул форум
Сообщений всего: 4
Дата рег-ции: Июль 2013
Помог: 0 раз(а)
Здравствуйте!
У меня тоже шляпа какая-то:
помогите разобраться с ошибкой в коде!
PHP:
скопировать код в буфер обмена
<?PHP // 6/6/02 4:28PM
if ( isset ( $MYSQL_SESSION_INC ) ) return ; $MYSQL_SESSION_INC = TRUE ;
// let the server know that you want to set your session handling yourself.
// The manual is kind of funny with this. According to the ini_set page, this shouldn't
// work, but it does (and a user has posted that fact). However, I've also noticed this
// script working with session.save_handler = files. According to the
// session_set_save_handler page, it shouldn't - I added a note on this.
ini_set ( 'session.save_handler' , 'user' ) ;
// I don't like the idea of having stale sessions around. Having them removed may even
// enhance performance on the database table if it starts getting large. However, I don't
// think it is necessary to run it at 100 - unless you are _very_ paranoid.
ini_set ( 'session.gc_probability' , '100' ) ;
require dirname ( __FILE__ ) . '/class.phpMysqlConnection.php' ; $SESS_SQL = FALSE ; // MySQL object to be used by sessions
// How long the sessions last. Defaults to the value in the php.ini file.
ini_set ( 'session.gc_maxlifetime' , '86400' ) ; // сессия 24 часа $SESS_LIFE = ini_get ( 'session.gc_maxlifetime' ) ;
function sess_open( ) {
global $PHPSECURITYADMIN_PATH , $SQL_HOST , $SQL_DB , $SQL_USER , $SQL_PASS , $SESS_SQL , $_SERVER ;
// Create the object to use in the sessions
$SESS_SQL = new phpMysqlConnection( $SQL_USER , $SQL_PASS , $SQL_HOST ) ;
// Select the correct database on the server
$SESS_SQL -> SelectDB ( $SQL_DB ) ;
return TRUE ;
}
function sess_close( ) {
return TRUE ;
}
function sess_read( $key ) {
global $PHPSECURITYADMIN_PATH , $SESS_SQL , $SESS_LIFE ;
$query = "select value from " . sessions
. " where sesskey='$key ' and expiry > " . time ( ) ; if ( $SESS_SQL -> Exists ( $query ) )
// If the requested session exists, get the data
$retVal = $SESS_SQL -> QueryItem ( $query ) ;
if ( isset ( $retVal ) ) return $retVal ; else return '' ;
}
function sess_write( $key , $val ) {
global $PHPSECURITYADMIN_PATH , $SESS_SQL , $SESS_LIFE ;
// Calculate the session end time
$expiry = time ( ) + $SESS_LIFE ; $query = "select sesskey from " . sessions. " where sesskey='$key '" ;
if ( $SESS_SQL -> Exists ( $query ) ) {
// If the session exists, update it
$query = "update " . sessions
. " set expiry=$expiry , value='$value ' where sesskey='$key ' and expiry > " . time ( ) ; $SESS_SQL -> Update ( $query ) ;
} else {
// If the session doesn't exist, create it
$query = "insert into " . sessions. " values('$key ',$expiry ,'$value ')" ;
$SESS_SQL -> Insert ( $query ) ;
}
return TRUE ;
}
function sess_destroy( $sess_id ) {
global $PHPSECURITYADMIN_PATH , $SESS_SQL ;
// delete the existing session
$query = "DELETE from " . sessions. " where sesskey='$sess_id '" ;
$SESS_SQL -> Delete ( $query ) ;
return TRUE ;
}
function sess_gc( ) {
global $PHPSECURITYADMIN_PATH , $SESS_SQL ;
// delete all expired sessions
$query = 'DELETE from ' . sessions
. ' where expiry < ' . time ( ) ; $SESS_SQL -> Delete ( $query ) ;
return $SESS_SQL -> a_rows ;
}
?>
ошибка лезет следующая: 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)
dfcbkbq
Отправлено: 09 Июля, 2013 - 11:57:16
Новичок
Покинул форум
Сообщений всего: 4
Дата рег-ции: Июль 2013
Помог: 0 раз(а)
PHP:
скопировать код в буфер обмена
<?
if ( isset ( $PHPMYSQLCONNECTION_INC ) ) return ;
$PHPMYSQLCONNECTION_INC = TRUE ;
class phpMysqlConnection{
var $result = '' ;
var $data = '' ;
var $rows = '' ;
var $user = '' ;
var $pass = '' ;
var $host = '' ;
var $port = '' ;
var $socket = '' ;
var $id = '' ;
var $a_rows = '' ;
function phpMysqlConnection( $user = "phpuser" , $pass = "php" , $host = "localhost" , $port = '' , $socket_path = '' ) {
$this -> user = $user ;
$this -> pass = $pass ;
$this -> host = $host ;
$this -> port = $port ;
$this -> socket = $socket_path ;
if ( $this -> port ) $host .= ":" . $this -> port ;
if ( $this -> socket ) $host .= ":" . $this -> socket ;
return TRUE ;
else
return $this -> errorMessage ( "Unable to connect to mysql server: " . $this -> host ) ;
}
function GetDatabases( ) {
$i = 0 ;
while ( $i < mysql_num_rows( $this -> result ) ) {
$i ++;
}
return ( $db_names ) ;
} else
return $this -> errorMessage ( "Unable to find a database on server: " . $this -> host ) ;
}
function CreateDB( $database ) {
return TRUE ;
} else
return $this -> errorMessage ( "Unable to create database: $database " ) ;
}
function DropDB( $database ) {
return TRUE ;
} else
return $this -> errorMessage ( "Unable to drop database: $database " ) ;
}
function CopyDB( $database , $dest_db = '' , $drop_tables = 0, $dest_host = "localhost" , $dest_user = "phpuser" ,
$dest_pass = "php" , $dest_port = '' , $dest_socket_path = '' ) {
// define the second server connection
if ( $dest_port ) $host .= ":" . $dest_port ;
if ( $dest_socket_path ) $host .= ":" . $dest_socket_path ;
// Let's connect to the other server now
$retVal = $this -> errorMessage ( "Unable to connect to mysql server: $dest_host " ) ;
if ( isset ( $retVal ) ) return $retVal ;
$retVal = $this -> errorMessage ( "Unable to find a database on server: $dest_host " ) ;
if ( isset ( $retVal ) ) return $retVal ;
// check if the database exists on the destination server
$EXISTS = FALSE ;
while ( $i < mysql_num_rows( $dest_dbs ) ) {
$EXISTS = TRUE ;
$i ++;
}
if ( ! $EXISTS ) {
// if the database doesn't exist, create it
$retVal = $this -> errorMessage ( "Unable to create database: $dest_db " ) ;
if ( isset ( $retVal ) ) return $retVal ;
}
// at this point the remote database exists
// get a list of the available tables on the source database
$retVal = $this -> errorMessage ( "No tables found on database: $database , host: $this->host " ) ;
if ( isset ( $retVal ) ) return $retVal ;
// dump the data
for ( $i = 0 ; $i < $num_tables ; $i ++ ) { // for each table
"$dest_user ,$dest_pass ,$dest_port ,$dest_socket_path );<br>" ;
// copy this table
$this -> CopyTable ( $table , $table , $database , $dest_db , $drop_tables , $conn_id , $dest_host ,
$dest_user , $dest_pass , $dest_port , $dest_socket_path ) ;
}
return TRUE ;
}
function CopyTable( $table , $dest_table , $database , $dest_db , $drop_table = '' , $conn_id = '' , $dest_host = '' ,
$dest_user = '' , $dest_pass = '' , $dest_port = '' , $dest_socket_path = '' ) {
// first, let's check to see if we are connected to a server already, if not, connect
$host = $dest_host ;
if ( $dest_port ) $host .= ":" . $dest_port ;
if ( $dest_socket_path ) $host .= ":" . $dest_socket_path ;
$retVal = $this -> errorMessage ( "Unable to connect to mysql server: " . $dest_host ) ;
if ( isset ( $retVal ) ) return $retVal ;
}
if ( $drop_table ) {
$drop = "DROP TABLE IF EXISTS $dest_table ;" ;
$retVal = $this -> errorMessage ( "Unable to perform query (drop $table ) on database: $dest_host :" .
"$dest_db <br><br>$drop <br><br>" ) ;
if ( isset ( $retVal ) ) return $retVal ;
}
$struc = "CREATE TABLE " . $dest_table . " (\n " ;
$result = mysql_query ( "SHOW FIELDS FROM $table " , $this -> id ) or
$retVal = $this -> errorMessage ( "Unable to copy table (fields): $table from database $database " ) ;
if ( isset ( $retVal ) ) return $retVal ;
$struc .= " $row[Field] $row[Type] " ;
if ( isset ( $row [ 'Default' ] ) && ( ! empty ( $row [ 'Default' ] ) || $row [ 'Default' ] == "0" ) )
$struc .= " DEFAULT '$row[Default] '" ;
if ( $row [ 'Null' ] != "YES" )
$struc .= " NOT NULL" ;
if ( $row [ 'Extra' ] != "" )
$struc .= " $row[Extra] " ;
$struc .= ",\n " ;
}
// remove the last comma
$result = mysql_query ( "SHOW KEYS FROM $table " , $this -> id ) or
$retVal = $this -> errorMessage ( "Unable to copy table (keys): $table from database $database " ) ;
if ( isset ( $retVal ) ) return $retVal ;
$key_name = $row [ 'Key_name' ] ;
if ( ( $key_name != 'PRIMARY' ) && ( $row [ 'Non_unique' ] == 0) )
$key_name = "UNIQUE|$key_name " ;
if ( ! isset ( $index [ $key_name ] ) )
$index [ $key_name ] = array ( ) ;
$index [ $key_name ] [ ] = $row [ 'Column_name' ] ;
}
$struc .= ",\n " ;
if ( $x == "PRIMARY" )
$struc .= " PRIMARY KEY (" . implode ( $columns , ", " ) . ")" ;
else if ( substr ( $x , 0 , 6 ) == "UNIQUE" )
$struc .= " UNIQUE " . substr ( $x , 7 ) . " (" . implode ( $columns , ", " ) . ")" ;
else
$struc .= " KEY $x (" . implode ( $columns , ", " ) . ")" ;
}
$struc .= "\n );" ;
// do structure query
$retVal = $this -> errorMessage ( "Unable to create $dest_host : " . $dest_db . "." . $dest_table ) ;
if ( isset ( $retVal ) ) return $retVal ;
// get data
$result = mysql_query ( "SELECT * FROM $table " , $this -> id ) or
$retVal = $this -> errorMessage ( "Unable to perform query: $query " ) ;
if ( isset ( $retVal ) ) return $retVal ;
for ( $i = 0 ; $i < $num_rows ; $i ++ ) {
mysql_data_seek ( $result , $i ) or
$retVal = $this -> errorMessage ( "Unable to seek data row: $row " ) ;
if ( isset ( $retVal ) ) return $retVal ;
$data = mysql_fetch_array ( $result ) or
$retVal = $this -> errorMessage ( "Unable to fetch row: $row " ) ;
if ( isset ( $retVal ) ) return $retVal ;
$values = '' ;
$values .= "$key = " ;
}
}
$insert_data [ ] = "INSERT INTO $dest_table set $values " ;
}
while ( list ( $k , $query ) =@ each ( $insert_data ) ) {
$retVal = $this -> errorMessage ( "Unable to perform query (data $table ) on database: $dest_host : $dest_db " ) ;
if ( isset ( $retVal ) ) return $retVal ;
}
return TRUE ;
}
function SelectDB( $db ) {
$this -> db = $db ;
return TRUE ;
else
return $this -> errorMessage ( "Unable to select database: $db " ) ;
}
function GetTableList( ) {
$i = 0 ;
$i ++;
}
return ( $tb_names ) ;
} else
return $this -> errorMessage ( "Unable to find any tables in database: $this->db " ) ;
}
function GetFieldList( $tbl_name ) {
$i = 0 ;
$i ++;
}
return ( $fd_names ) ;
} else
return $this -> errorMessage ( "Unable to find any field list in table: $tbl_name " ) ;
}
function Delete( $query ) {
return TRUE ;
} else
return $this -> errorMessage ( "Unable to perform Delete: $query " ) ;
}
function Update( $query ) {
return TRUE ;
} else
return $this -> errorMessage ( "Unable to perform update: $query " ) ;
}
function Insert( $query ) {
return TRUE ;
} else
return $this -> errorMessage ( "Unable to perform insert: $query " ) ;
}
function InsertID( ) {
return ( $this -> result ) ;
} else
return $this -> errorMessage ( "Cannot retrieve auto_increment value: $this->id " ) ;
}
function Query( $query ) {
else
$this -> rows = 0 ;
return TRUE ;
} else
return $this -> errorMessage ( "Unable to perform query: $query " ) ;
}
function GetRow( $row ) {
return TRUE ;
else
return $this -> errorMessage ( "Unable to fetch row: $row " ) ;
} else
return $this -> errorMessage ( "Unable to seek data row: $row " ) ;
}
function QueryRow( $query ) {
return ( $this -> data ) ;
else
return $this -> errorMessage ( "Unable to fetch data from query: $query " ) ;
} else
return $this -> errorMessage ( "Unable to perform query: $query " ) ;
}
function QueryItem( $query ) {
return ( $this -> data [ 0] ) ;
else
return $this -> errorMessage ( "Unable to fetch data from query: $query " ) ;
} else
return $this -> errorMessage ( "Unable to perform query: $query " ) ;
}
// returns XML-formatted record rows from query results.
// $this->data holds the XML only, and the function returns the XML header + the data
// example:
// header("Content-type: text/xml");
// echo $sql->XML_Output("SELECT * FROM yourTable");
// Thanks to Renй Moser <r.moser@meesly.ch>
function XML_DataOutput
( $query , $tags = array ( 'dataset' , 'record' ) ) {
$xmlheader = '<?xml version="1.0" ?>' . "\n " ;
$this -> data .= '<' . $tags [ 0 ] . '>' . "\n " ;
$this -> data .= "\t " . '<' . $tags [ 1 ] . '>' . "\n " ;
for ( $i = 0 ; $i < $this -> fields ; $i ++ ) {
$this -> data .= "\t \t " . '<' . $tag . '>' . preg_replace ( "/([\r \n ])/" , '' , strip_tags ( $this -> rows [ $i ] ) ) . '</' . $tag . '>' . "\n " ;
}
$this -> data .= "\t " . '</' . $tags [ 1 ] . '>' . "\n " ;
}
$this -> data .= '</' . $tags [ 0 ] . '>' ;
return $xmlheader . $this -> data ;
} else
return $this -> errorMessage ( "Unable to perform query: $query ; in XML output" ) ;
}
// Thanks to Andrew Collington <amnuts@talker.com> for the update
function Exists( $query ) {
return TRUE ;
else
return FALSE ;
} else
return $this -> errorMessage ( "Unable to perform query: $query " ) ;
}
// Thanks to Andrew Collington <amnuts@talker.com>
function GetSetList( $table , $field ) {
$query = "SHOW COLUMNS FROM $table LIKE '$field '" ;
while ( list ( $key , $val ) =@ each ( $this -> data ) ) {
}
return $mySet ;
} else
return $this -> errorMessage ( "Unable to fetch data set from: $query " ) ;
} else
return $this -> errorMessage ( "Unable to perform set fetch: $query " ) ;
}
// Thanks to Andrew Collington <amnuts@talker.com>
function GetEnumList( $table , $field ) {
$query = "SHOW COLUMNS FROM $table LIKE '$field '" ;
while ( list ( $key , $val ) =@ each ( $this -> data ) ) {
}
return $myEnum ;
} else
return $this -> errorMessage ( "Unable to fetch data enum from: $query " ) ;
} else
return $this -> errorMessage ( "Unable to perform enum fetch: $query " ) ;
}
// Use this function to insert the binary image data of a picrutre into a database
function InsertImage( $image , $table , $blob_field , $num_att_cols , $atts1 , $atts2 = '' , $atts3 = '' , $where_clause ) {
// Examples of using this function
// $sql->InsertImage($_FILES['userfile'],'my_table','my_blob_field',1,'attributes',0,"id = '1'");
// $sql->InsertImage($_FILES['userfile'],'my_table','my_blob_field',2,'image_width','image_height',"id = '1'");
switch ( $size [ 2] ) {
case 1: $type = 'GIF' ; break ;
case 2: $type = 'JPG' ; break ;
case 3: $type = 'PNG' ; break ;
case 4: $type = 'SWF' ; break ;
case 5: $type = 'PSD' ; break ;
case 6: $type = 'BMP' ; break ;
case 7: $type = 'TIFF(intel byte order)' ; break ;
case 8: $type = 'TIFF(motorola byte order)' ; break ;
case 9: $type = 'JPC' ; break ;
case 10: $type = 'JP2' ; break ;
case 11: $type = 'JPX' ; break ;
}
$fd = fopen ( $image [ 'tmp_name' ] , "r" ) ;
$q = "UPDATE `" . $table . "` SET `" . $blob_field . "` = '" . $data . "'" ;
switch ( $num_att_cols ) {
case 1: $q .= ", `" . $atts1 . "` = '" . $size [ 3 ] . "'" ;
break ; // width and height HTML attribute string
case 2: if ( $atts2 )
$q .= ", `" . $atts1 . "` = '" . $size [ 0 ] . "', `" . $atts2 . "` = '" . $size [ 1 ] . "'" ; // width integer, height integer
else if ( $atts3 ) {
$q .= ", `" . $atts1 . "` = '" . $size [ 0 ] . "', `" . $atts3 . "` = '" . $type . "'" ; // HTML attribute string, image type
}
break ;
case 3: $q .= ", `" . $atts1 . "` = '" . $size [ 0 ] . "', `" . $atts2 . "` = '" . $size [ 1 ] . "', `" . $atts3 . "` = '" . $size [ 1 ] . "'" ;
break ; // width integer, height integer, image type
}
$q .= " WHERE " . $where_clause ;
return $this -> Update ( $q ) ;
}
// use this function to get the binary data from the database
function GetImage( $table , $blob_field , $num_att_cols , $atts1 , $atts2 = '' , $atts3 = '' , $where_clause ) {
$q = "select `" . $blob_field . "`" ;
switch ( $num_att_cols ) {
case 1: $q .= ", `" . $atts1 . "`" ;
break ; // width and height HTML attribute string
case 2: if ( $atts2 )
$q .= ", `" . $atts1 . "`, `" . $atts2 . "`" ; // width integer, height integer
else if ( $atts3 ) {
$q .= ", `" . $atts1 . "`, `" . $atts3 . "`" ; // HTML attribute string, image type
}
break ;
case 3: $q .= ", `" . $atts1 . "`, `" . $atts2 . "`, `" . $atts3 . "`" ;
break ; // width integer, height integer, image type
}
$q .= " from `" . $table . "` where " . $where_clause ;
if ( ! $this -> Query ( $q ) )
return $this -> errorMessage ( 'Error selecting image' ) ;
if ( $this -> rows < 2) {
if ( ! $this -> GetRow ( 0) )
return $this -> errorMessage ( 'Error selecting image' ) ;
}
return $this -> data ;
}
function errorMessage( $msg ) {
}
}
?>
(Добавление)
Denkill пишет: Что за класс
phpMysqlConnection (если пользовательский то код в студию)
Denkill, надеюсь, я верно выполнил твое поручение. Прошу прощения за свое невежество, я к сожалению совсем нуб в РНР, но вещь интересная, и хотелось бы разбираться, а для этой ошибки, похоже мне еще очень очень далеко, поэтому обращаюсь к гуру РНР.
Спасибо!
(Добавление)
Denkill пишет: Что за класс
phpMysqlConnection (если пользовательский то код в студию)
Denkill, надеюсь, я верно выполнил твое поручение. Прошу прощения за свое невежество, я к сожалению совсем нуб в РНР, но вещь интересная, и хотелось бы разбираться, а для этой ошибки, похоже мне еще очень очень далеко, поэтому обращаюсь к гуру РНР.
Спасибо!
(Добавление)
PHP:
скопировать код в буфер обмена
// To use the class, you will first need to include the class file
include "class.phpMysqlConnection.php" ;
// The next step will be to set up a variable to represent the object
// created. I usually use the name 'sql' for clarity, but it can be whatever.
$sql = new phpMysqlConnection( $sql_user , $sql_pass , $sql_host ) ;
// I usually use this format, and store the variables in a different
// include file with other site-wide config settings. If you leave out
// $sql_host from the above line, "localhost" (when MySQL server and web
// server are on the same machine) is assumed.
(Отредактировано автором: 09 Июля, 2013 - 11:57:58)
FOMINTIMUR
Отправлено: 04 Августа, 2013 - 18:48:27
Новичок
Покинул форум
Сообщений всего: 6
Дата рег-ции: Авг. 2013
Помог: 0 раз(а)
А у меня выводит Fatal error: Call to undefined function mysqli_connect() in C:\apache\test.ru\www\php\dbcontroller.php on line 15. Библиотека стоит и раскомментированна и в среде путь прописан.
PHP:
скопировать код в буфер обмена
<?PHP
/*
** Class for connecting and manage the mysql database
*/
require_once ( "constants.php" ) ;
require_once ( "utils.php" ) ;
class DBController{
private $link ;
public function __construct( ) {
}
}
public function __destruct( ) {
$this -> disconnect ( ) ;
}
/*
* checks if user with email "$username" and password "$password" exists
* */
public function confirmUserPass( $username , $password ) {
/* Verify that user is in database */
$q = "SELECT password FROM users WHERE email = '$username '" ;
return - 1 ; //Indicates username failure
}
if ( $password == $dbarray [ 'password' ] ) {
return 1 ; //Success, Username and password confirmed
}
else {
return - 2 ; //Indicates password failure
}
}
/**
* confirmUserID - Checks whether or not the given
* username is in the database, if so it checks if the
* given userid is the same userid in the database
* for that user. If the user doesn't exist or if the
* userids don't match up, it returns an error code
*/
public function confirmUserID( $username , $userid ) {
/* Verify that user is in database */
$q = "SELECT usr_userid FROM users WHERE pk_user = '$username '" ;
return - 1 ; //Indicates username failure
}
/* Retrieve userid from result, strip slashes */
$dbarray [ 'usr_userid' ] = stripslashes ( $dbarray [ 'usr_userid' ] ) ; /* Validate that userid is correct */
if ( $userid == $dbarray [ 'usr_userid' ] ) {
return 1 ; //Success! Username and userid confirmed
}
else {
return - 2 ; //Indicates userid invalid
}
}
/*
* dbemailTaken - Returns true if the email has
* been taken by another user, false otherwise.
*/
public function dbemailTaken( $email ) {
$q = "SELECT email FROM users WHERE email = '$email '" ;
return ( $numr > 0) ;
}
/*
** registers a user in the system, and returns user key if successfull
*/
public function dbregister( $email , $pass , $flname , $hash , $country_code ) {
$ip = getRealIpAddr( ) ;
//############### INSERTION ###############
$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 ')" ;
return - 1 ;
}
else {
$result = mysqli_query ( $this -> link , 'SELECT LAST_INSERT_ID() as lid' ) ; $obj = $result -> fetch_object ( ) ;
$lastinsertedid = $obj -> lid ;
$result -> close ( ) ;
return $lastinsertedid ;
}
return - 1 ;
}
/*
* checks if user with email "$email" did already the confirmation of the account
* */
public function is_confirmed( $username ) {
$q = "SELECT usr_is_confirmed FROM users WHERE email = '$username '" ;
$is_confirmed = $dbarray [ 'usr_is_confirmed' ] ;
if ( $is_confirmed == 1) {
return 1 ; //Success!
}
else {
return - 1 ; //Indicates failure
}
}
/*
* checks if user with email "$email" is blocked
* */
public function is_blocked( $username ) {
$q = "SELECT usr_is_blocked FROM users WHERE email = '$username '" ;
$usr_is_blocked = $dbarray [ 'usr_is_blocked' ] ;
if ( $usr_is_blocked == 1) {
return 1 ; //blocked
}
else {
return - 1 ; //Indicates failure
}
}
/*
* checks if the resethash is associated with the email in the users table
*/
public function dbconfirmResetPasswordHash( $email , $hash ) {
$q = "SELECT pk_user FROM users WHERE email = '$email ' and usr_resetpassword_hash = '$hash '" ;
if ( $numr > 0)
return 1 ;
else
return - 1 ;
}
/**
* updateUserField - Updates a field, specified by the field
* parameter, in the user's row of the database, given the pk_user
*/
public function updateUserField( $userkey , $field , $value ) {
$q = "UPDATE users SET " . $field . " = '$value ' WHERE pk_user = '$userkey '" ;
return - 1 ;
}
return 1 ;
}
/**
* deleteUser - Deletes a User
*/
public function deleteUser( $userkey ) {
$q = "DELETE from users WHERE pk_user = '$userkey '" ;
return - 1 ;
}
return 1 ;
}
/**
* updateUserFieldEmail - Updates a field, in the user's row of the database, given the email
*/
public function updateUserFieldEmail( $email , $field , $value ) {
$q = "UPDATE users SET " . $field . " = '$value ' WHERE email = '$email '" ;
}
/**
* dbgetUserInfo - Returns the result array from a mysql
* query asking for some data regarding
* the given username(email). If query fails, NULL is returned.
*/
public function dbgetUserInfoEmail( $email ) {
$q = "SELECT pk_user,email,usr_userid FROM users WHERE email = '$email '" ;
/* Error occurred, return given name by default */
return NULL ;
}
/* Return result array */
return $dbarray ;
}
/**
* dbgetUserInfo - Returns the result array from a mysql
* query asking for some data regarding
* the given username(pk_user). If query fails, NULL is returned.
*/
public function dbgetUserInfo( $username ) {
$q = "SELECT pk_user,email,usr_userid FROM users WHERE pk_user = '$username '" ;
/* Error occurred, return given name by default */
return NULL ;
}
/* Return result array */
return $dbarray ;
}
/**
* dbgetUserAccountDetails - Returns the result array from a mysql
* query asking for some data regarding
* the given username(email). If query fails, NULL is returned.
*/
public function dbgetUserAccountDetails( $userkey ) {
$q = "SELECT U.*,C.country_name FROM users U,Country C WHERE U.pk_user = '$userkey ' AND C.country_code = U.country_code" ;
/* Error occurred, return given name by default */
return NULL ;
}
/* Return result array */
return $dbarray ;
}
public function user_confirm( $urlemail , $urlhash ) {
$new_hash = sha1 ( $urlemail . supersecret_hash_padding
) ; if ( $new_hash && ( $new_hash == $urlhash ) ) {
$q = "SELECT email FROM users WHERE usr_confirm_hash = '$new_hash '" ;
$feedback = 'ERROR -- Hash not found' ;
return $feedback ;
}
else {
// Confirm the email and set account to active
$email = $urlemail ;
$hash = $urlhash ;
$query = "UPDATE users SET usr_is_confirmed='1' WHERE usr_confirm_hash='$hash '" ;
return 1 ;
}
}
else {
$feedback = 'ERROR -- Values do not match' ;
return $feedback ;
}
}
/*
* checks if value matches a field in the table users
*/
public function matchUserField( $value , $field , $userkey ) {
$q = "SELECT pk_user FROM users WHERE " . $field . " = '$value ' and pk_user = '$userkey '" ;
return ( $numr > 0) ;
}
/*
** changes the user account details, and returns 1 successfull
*/
public function dbeditaccount( $email , $flname , $country_code , $pass , $userkey ) {
//############### UPDATE ###############
$q = "" ;
if ( $pass )
$q = "UPDATE users SET email='$email ',flname='$flname ',password='$pass ',country_code='$country_code ' where pk_user = '$userkey '" ;
else
$q = "UPDATE users SET email='$email ',flname='$flname ',country_code='$country_code ' where pk_user = '$userkey '" ;
return - 1 ;
}
else {
return 1 ;
}
return - 1 ;
}
/*
* checks if a country typed by the user exists in the table country. Returns the id of the country, or null
*/
public function dbexistsCountry( $country_name ) {
$q = "SELECT country_code FROM Country WHERE LOWER(country_name) = '$country_name_lower '" ;
return null ; //Indicates country check failure
}
$dbarray [ 'country_code' ] = stripslashes ( $dbarray [ 'country_code' ] ) ; return $dbarray [ 'country_code' ] ;
}
/**
* Increments the number of logins of a user
**/
public function incrementLogins( $userkey ) {
$q = "SELECT usr_nmb_logins FROM users WHERE pk_user = '$userkey '" ;
return - 1 ;
}
else {
$nmb_logins = $dbarray [ 'usr_nmb_logins' ] ;
$nmb_logins_inc = $nmb_logins + 1 ;
$qu = "update users set usr_nmb_logins = '$nmb_logins_inc ' WHERE pk_user = '$userkey '" ;
return - 2 ; //Indicates error updating row
}
else {
return 1 ;
}
}
return - 3 ;
}
/*
* returns the array with the users per country info
* note: it just includes the users that have their accounts confirmed!
* It does not includes the user viewing this (admin)
* */
public function getUsersPerCountry( $userkey ) {
$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" ;
/* Error occurred, return given name by default */
return NULL ;
}
/* Return result array */
while ( $row = $results -> fetch_assoc ( ) ) {
$aResults [ ] = array ( "country_name" => $row [ 'country_name' ] , "value" => $row [ 'value' ] ) ; }
return $aResults ;
}
/*
* returns the array with the users data
* */
public function getUsersData( $userkey ) {
$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 '" ;
/* Error occurred, return given name by default */
return NULL ;
}
/* Return result array */
while ( $row = $results -> fetch_assoc ( ) ) {
$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' ] ) ; }
return $aResults ;
}
/**
* query - Performs the given query on the database and
* returns the result, which may be false, true or a
* resource identifier.
*/
public function query( $query ) {
}
public function disconnect( ) {
}
} ;
?>
Поиск в теме | Версия для печати
Страниц (1): [1]
Сейчас эту тему просматривают: 0 (гостей: 0, зарегистрированных: 0)
« Если скрипт не работает »
Все гости форума могут просматривать этот раздел. Только зарегистрированные пользователи могут создавать новые темы в этом разделе. Только зарегистрированные пользователи могут отвечать на сообщения в этом разделе.
Powered by ExBB FM 1.0 RC1. InvisionExBB