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 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#的问题,如何解决?