douhe5092 2016-09-24 06:36
浏览 40
已采纳

php上的My Query Update错误

i have query update on my php file. but when i run this file, my query error.but when i already on trial in a database query is not an error

<?php
session_start();

$conn = pg_connect("host=localhost port=5432 dbname=alc user=postgres password=postgres");

$training_id= "SELECT m.training_mst_id FROM tbl_user u, training_mst m WHERE u.user_id = m.trainer_id AND m.start_traning >= now() AND m.end_traning <= now() AND m.trainer_id = ".$_SESSION['user_id'];
$result = pg_query($conn,$training_id);
$query = "UPDATE training_mst set status='TRUE' where training_mst_id= ".$training_id;
$result2 = pg_query($conn,$query);

?>

my error :

Warning: pg_query(): Query failed: ERROR: syntax error at or near "SELECT" LINE 1: ...ning_mst set status='TRUE' where training_mst_id= SELECT m.t... ^ in D:\xampp\htdocs\FeedbackALC\sistemuser\open_feedback.php on line 9

  • 写回答

1条回答 默认 最新

  • dqpdb82600 2016-09-24 06:46
    关注

    As @Geral Schneider pointed out, the variable you are using as a value in the second sql statement is the original sql query rather than the result. You need to retrieve the value you need from the initial recordset - the following is not tested but might give an indication as to how to proceed.

    <?php
        session_start();
    
        $conn = pg_connect("host=localhost port=5432 dbname=alc user=postgres password=postgres");
    
        $training_id= "SELECT m.training_mst_id FROM tbl_user u, training_mst m WHERE u.user_id = m.trainer_id AND m.start_traning >= now() AND m.end_traning <= now() AND m.trainer_id = ".$_SESSION['user_id'];
        $result = pg_query($conn,$training_id);
    
        if( $result ){
    
            $data=pg_fetch_object( $result );
            $id=$data->training_mst_id;
    
            $query = "UPDATE training_mst set status='TRUE' where training_mst_id= ".$id;
            $result2 = pg_query($conn,$query);
        }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?