dongzipu7517 2013-09-11 09:27
浏览 34
已采纳

我的代码上的BUG我花了几个小时没找到问题所在

Hi please see this code, I am using this code to update current project, $current_project_id using the i am getting the current project to edit I have checked the data to post variables i am getting it while doing a echo statement. there may be some issue while i pass this to my class function using the object.

ALSO: Help appreciated, If you find some security issue on my code :)

User Side:

<?php 
    $current_project_id = (int)$_GET["pid"]; //Getting current project to Update from URL parameter.

    $currentproject = $touchObj->get_projects_by_id($current_project_id); // Using  project id to update, we are taking all project data.
?>


<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if(isset($_POST['project_name']) && isset($_POST['project_location'] )) { 

    include('inc/handleUpload.php'); // Image uplaod class
    $up->config('20000000','jpg,gif,png,pdf,txt,doc,docx,xls,xlsx,zip,rar');
    $up->upload('project_file','xxxxxxxxxxxxxxxxxxxxxxxxx/'); //Server file location for upload folder.


    $project_investor_id = implode(",",$_POST["project_investor_id"]); // Our table field store data as comma seperated separated

    $project_name = mysql_real_escape_string($_POST['project_name']);

    $project_location = mysql_real_escape_string($_POST['project_location']);

    $project_phase = mysql_real_escape_string($_POST['project_phase']);

    $project_capital = mysql_real_escape_string($_POST['project_capital']);

    $project_total = mysql_real_escape_string($_POST['project_total']);

    $project_notes = mysql_real_escape_string($_POST['project_notes']);

    $file = $up->fileInfo['fname'];



    $touchObj->update_project(
        $current_project_id,
        $project_investor_id,
        $project_name, 
        $project_location,
        $$project_phase,
        $project_capital,
        $project_total,
        $project_notes,
        $file
        );
}
else 
{

    echo '<div class="alert alert-info"><h6>Please fill datas...</h6></div>';
}

}
?>  

My function of this particular Class:

 public function update_project($project_id, $project_investor_id, $project_name, $project_location, $project_phase, $project_capital, $project_total, $project_notes, $file){

    $result = mysql_query("UPDATE project_table SET 
    project_investor_id = $project_investor_id, 
    project_name = $project_name,    
    project_location = $project_location,
    project_phase = $project_phase,
    project_capital = $project_capital,
    project_total = $project_total,
    project_notes = $project_notes,
    project_file = $file
    WHERE project_id =$project_id");

    if($result) {
    echo '<div class="alert alert-success"><h6>Project updates... Do not refresh window...</h6></div>';
    }
    else {
    echo '<div class="alert alert-error"><b>Some error while updating the project. Please try again...</b></div>';
    }

}

Result: Some error while updating the project. Please try again...

I am not able to update data usig this function Please reviwe it and let me know what i missed? any ideas?

Thank You very much for your valuable time

  • 写回答

1条回答 默认 最新

  • douquan9826 2013-09-11 09:30
    关注

    I'm pretty certain character based fields will need to be surrounded by ' marks, such as:

    project_notes = '$project_notes',
    

    rather than:

    project_notes = $project_notes,
    

    And you should investigate the term "SQL injection" to see why it's a bad idea to just shove values entered by the user into your queries. All they have to do is somehow enter something like

    ', salary = salary * 1.5, project_notes = 'actual project notes

    into the $project_notes text entry box (or whatever you're using) and you're in for some interesting times.

    Parameterised queries are much safer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c