dongxingchang9345 2016-09-22 13:10
浏览 30
已采纳

INSERT / UPDATE Mysql单一表单

I have 2 database tables

tbl1 users ---------- tbl2 gamesystems
uid field ------------- gs_uid field

the 2 tables are tied together by the user_id..

now i want tbl2 to only be updated able and fields are not required.. with the exception of the gs_uid when they update there system.

my only issue is i need to insert the user_id into the gs_uid.

function game_system()
{    
   if(isset($_POST['game_system'])) {


            $user_id = $_SESSION['uid'];
            $motherboard = escape($_POST['motherboard']);
            $processor = escape($_POST['processor']);            
            $memory = escape($_POST['memory']);
            $graphics = escape($_POST['graphics']);
            $harddrive = escape($_POST['harddrive']);
            $power = escape($_POST['powersupply']);
            $cooling = escape($_POST['cooling']);
            $towercase = escape($_POST['towercase']);


            $sql = "INSERT INTO gamesystem(gs_uid, motherboard, processor, memory, graphics, harddrive, powersupply, cooling, towercase) ";
            $sql .= "VALUES('{$user_id}','{$motherboard}','{$processor}','{$memory}','{$graphics}','{$harddrive}','{$power}','{$cooling}','{$towercase}') ";
            $result = query($sql);   


        }
   }
  • 写回答

1条回答 默认 最新

  • dshmkgq558192365 2016-09-22 13:48
    关注

    If gs_uid is the primary key of table 'gamesystem' , then this field should not accept empty data.

    Otherwise, if gs_uid is NOT the key, what's the primary key of this table? In case of UPDATE, you'll need to specify which row you'd like to update, otherwise the system will not know how to do so.

    the SQL should looks like below

    UPDATE "gamesystem"
    SET "gs_uid" = $user_id
    WHERE YOUR_PRIMARY_KEY_COLUMN = SPECIFIC VALUE;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用