2016-07-22 4 views
-3

몇 년 전에 내 친구가 내 joomla 사이트 사용자를위한 학습 진행을 녹음하는 간단한 기능을 수행하는 코드 조각을 작성했습니다. PHP7에서 Joomla를 3.6으로 업데이트 했으므로이 사이트는 저를 놀라게하지 않는 비추천 쿼리를보고합니다. 쿼리를 mysqli로 대체하려고했지만 함수를 작동시키지 못했습니다. 누군가 나를 찾아 볼까? 정말 고맙습니다.더 이상 사용되지 않는 mysql_query 및 mysql_connect - 코드 업데이트

<?php 
/*  $host = "localhost"; 
$user = "administrator"; 
$pass = "web-Test";//enter here your sql password 
$db_name = "e-learning"; 
$link = mysql_connect($host, $user,$pass); 
mysql_select_db($db_name, $link)or die("unable to select database"); */ 
include'const.php'; 
$link = mysql_connect($host, $user,$pass); 
if (!$link) { 
echo('Could not connect'); 
} 
else { 
mysql_select_db($db, $link) or die("can not select database").mysql_error();  
} 
$ip=getenv('REMOTE_ADDR'); 
//$new_array_without_nulls = array_filter($_POST, 'strlen'); 

if($_POST) 
{ 

// --------comment 
$uid = $_POST['uid']; 
unset($_POST['uid']); 
$cmt = array(); 
foreach($_POST as $key => $value) 
    { 
     if ($value != 'true' && $value != 'Progress' && $value != 'false') 
     { 
      $cmt[$key] = $value; 
     } 
    } 
foreach ($cmt as $key => $value) 
$cmt_value = implode(',' , $cmt); 
// --------Check 
$check = array(); 
foreach($_POST as $key => $value) 
    { 
     if ($value == 'true') 
     { 
      $check[$key] = $value; 
     } 
    } 
//finding key 
$check_key = array(); 
foreach ($check as $key => $value){ 
    array_push($check_key,$key); 
} 
foreach ($check_key as $key => $value) 
$check_value = implode(',' , $check_key); 

//$uid = $user->get('id'); 
$content_name = $_POST['contentname']; 
function CheckExistContentName($content_name,$uid){ 
    $name_exist = mysql_query("select * from Progress where content_name = '$content_name' and User_id = $uid "); 
    $arr = array(); 
    while($row = mysql_fetch_array($name_exist)) 
    { 
    $arr = $row; 
    } 
    return $arr; 
} 
if(CheckExistContentName($content_name,$uid)) 
{ 
    $sql = "update Progress set User_id = '".$uid."', ip = '".$ip."',content_name = '".$content_name."',arr_check = '".$check_value."',arr_cmt = '".$cmt_value."' where content_name = '$content_name' and User_id = $uid"; 
    $rs_result = mysql_query($sql); 
    echo "<h2> Your learning progress has been updated </h2>"; 
} 
else 
{ 
    $sql = "insert into Progress(User_id,ip,content_name,arr_check,arr_cmt) values ('".$uid."','".$ip."','".$content_name."','".$check_value."','".$cmt_value."')"; 
    $rs_result = mysql_query($sql); 
    echo "<h2> Your learning progress has been saved </h2>"; 
} 
} 
//} 
?> 
+0

mysqli 쿼리 구조를 사용해야합니다. – Codebrekers

+1

코드에서 여전히 mysql_ 함수를 사용하고 있습니다. 시도한 코드와 정확한 오류 메시지 또는 잘못된 동작에 대한 설명을 표시하십시오. – JJJ

답변

0

친구가 Joomla의 관점에서 완전히 잘못했습니다. 그는 Joomla 데이터베이스 클래스를 사용하는 대신 MySQL 연결 (암호 포함)을 파일에 하드 코딩했습니다.

그는 MySQL 쿼리에서 안전하지 않은 변수를 직접 사용하고 있으므로 사이트가 해킹 될 위험이 매우 높습니다.

내가 너라면,이 문제를 올바르게 해결할 전문가를 얻을 것입니다.

+0

도움을 주셔서 감사합니다. 우리는 이것을 완전히 없애고 처음부터 시작해야 할 것 같습니다. –

관련 문제