本文介绍了如何在数据库中插入游戏的当前ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我的问题是,如何将我的游戏ID的当前ID插入数据库。 这是我的桌子: 创建表如果不存在`game_review`( `id`int(11)NOT NULL, `user_id`int(11)NOT NULL, `game_id`int(11)NOT NULL, ` rating` int(10)NOT NULL, `title` varchar(100)NOT NULL, `review`文本NOT NULL )ENGINE = InnoDB DEFAULT CHARSET = latin1; ALTER TABLE`game_review` 添加PRIMARY KEY(`id`); ALTER TABLE`game_review` MODIFY`id`int(11)NOT NULL AUTO_INCREMENT; 我想插入当前的user_id和标题和描述,我已经知道该怎么做了。 (我不担心错误检查或安全性。)我只是无法插入我点击的游戏的当前ID。 这是我的代码: <?php require_once $ _SERVER [' DOCUMENT_ROOT']。' / Gamesite / core / init.php'; include(' head.php'); include(' navigation.php'); ?> < div class = 容器 样式 = padding-removed 200px; > <? php // 获取游戏的当前ID $ game_id = $ _GET [' id']; $ errors = array(); // 从init.php获取用户ID $ user_id = $ user_data [' id']; if (isset($ _ POST [' submit'])){ // 清理表单字段。 $ title =((isset($ _ POST [' title'])&& $ _POST [' title']!= ' ')?sanitize($ _ POST [' title']):' '); $ review =((isset($ _ POST [' 审核])&& $ _POST [' review'] != ' ')?sanitize($ _ POST [' review']):' '); $ rating =((isset($ _ POST [' 评级])&& $ _POST [' rating'] != ' ')?sanitize($ _ POST [' rating']):' '); if (!empty($ errors)){ display_errors($ errors); } else { $ SQL_INSERT = 插入到game_review(`user_id`,`game_id`,`rating`,`title`,`review`)VALUES('$ user_id ','$ game_id','$ rating','$ title','$ review'); $ QUERY = $ db-> query($ SQL_INSERT); // header('Location:Review.php'); } } ?> 当我点击表单中的提交时,会显示此错误消息。 注意:未定义的索引:第14行的C:\ xampp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ _SERVER [' DOCUMENT_ROOT']。' / Gamesite / core / init.php'; include(' head.php'); include(' navigation.php'); ?> < div class = 容器 样式 = padding-removed 200px; > <? php // 获取游戏的当前ID game_id = _GET [' id']; My question is, how do I insert the current ID of my Game ID into the database.Here is my table:CREATE TABLE IF NOT EXISTS `game_review` (`id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `game_id` int(11) NOT NULL, `rating` int(10) NOT NULL, `title` varchar(100) NOT NULL, `review` text NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;ALTER TABLE `game_review` ADD PRIMARY KEY (`id`);ALTER TABLE `game_review`MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;I want to insert the current user_id and title and description, which i already know how to do. (I'm not worrying about errors checking or security yet.) I just cannot insert the current ID of the game that I clicked on.Here is my code:<?php require_once $_SERVER['DOCUMENT_ROOT'].'/Gamesite/core/init.php'; include('head.php'); include('navigation.php'); ?> <div class="container" style="padding-removed 200px;"> <?php // Get the current ID of the game $game_id = $_GET['id']; $errors = array(); // Get the user ID from init.php $user_id = $user_data['id']; if (isset($_POST['submit'])) { // Sanitize form fields. $title = ((isset($_POST['title']) && $_POST['title'] != '') ? sanitize($_POST['title']) : ''); $review = ((isset($_POST['review']) && $_POST['review'] != '') ? sanitize($_POST['review']) : ''); $rating = ((isset($_POST['rating']) && $_POST['rating'] != '') ? sanitize($_POST['rating']) : ''); if (!empty($errors)) { display_errors($errors); } else { $SQL_INSERT = "insert into game_review (`user_id`, `game_id`, `rating`, `title`, `review`) VALUES ('$user_id', '$game_id', '$rating', '$title', '$review')"; $QUERY = $db->query($SQL_INSERT); //header('Location: Review.php'); } } ?>When I click submit in the form, this error message show up.Notice: Undefined index: id in C:\xampp\htdocs\Gamesite\game_includes\Review.php on line 14 解决方案 _SERVER['DOCUMENT_ROOT'].'/Gamesite/core/init.php'; include('head.php'); include('navigation.php'); ?> <div class="container" style="padding-removed 200px;"> <?php // Get the current ID of the game game_id =_GET['id']; 这篇关于如何在数据库中插入游戏的当前ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 21:05