不知何故,我的 mysql 数据库只为每个用户存储一次请求。
我打算为我的网站创建一个票务系统,我已经创建了表格并创建了一个表单和一个 php 类,如下所示。
在这种情况下,我想创建 2 个不同的票据,它只会存储第一张票而不是第二张票。
Screenshot of the submitted form
SQL代码:
CREATE TABLE IF NOT EXISTS `Comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`comment` varchar(255) NOT NULL,
`comment_creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `Conversation` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ticket_id` varchar(30) NOT NULL,
`comment_id` int(11) NOT NULL,
`conversation_creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `ticket_id` (`ticket_id`,`comment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `Tickets` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`email` varchar(50) NOT NULL,
`ticket_id` varchar(30) NOT NULL,
`ticket_question` varchar(255) NOT NULL,
`ticket_status` tinyint(1) NOT NULL DEFAULT '1',
`ticket_subject` varchar(50) NOT NULL,
`ticket_creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`ticket_id`),
UNIQUE KEY `id` (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ;
PHP 类:
<?php
class ticket_create extends database {
// Ticket class constructor storing the class variables
function __construct($username, $email, $ticket_id, $ticket_subject, $ticket_question){
$this->username = $username;
$this->email = $email;
$this->ticket_id = $ticket_id;
$this->ticket_subject = $ticket_subject;
$this->ticket_question = $ticket_question;
}
// Function to add the ticket to the database
function create_ticket(){
$this->connect();
$this->execute_query("INSERT INTO Tickets (username, email, ticket_id, ticket_subject, ticket_question) VALUES ('" . $this->username . "', '" . $this->email . "', '" . $this->ticket_id . "', '" . $this->ticket_subject . "', '" . $this->ticket_question . "')");
}
// Function to handle the class and execute their functions
function class_handler(){
$this->create_ticket();
return 'The ticket: ' . $this->ticket_id . ' was successfull created.';
}
}
?>
调用 php 类:
<?php
if(!empty($_POST)){
require_once('../handling/ticket_create.php');
$ticket_question = $_POST['ticket_question'];
$create_ticket = new ticket_create($user->username, $user->email, md5(uniqid($user->username, true)), $ticket_question);
$ticket_response = $create_ticket->class_handler();
echo $ticket_response;
}
?>
我如何让它工作,每张票都会被存储?
最佳答案
问题是这一行:
UNIQUE KEY `username` (`username`)
用户名是唯一的,这意味着如果您将banana作为用户名保存一次,您将无法再次保存banana。曾经。
从表中的用户名中删除唯一键,一切都会起作用。
ALTER TABLE Tickets DROP INDEX username;
或
CREATE TABLE IF NOT EXISTS `Tickets` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`email` varchar(50) NOT NULL,
`ticket_id` varchar(30) NOT NULL,
`ticket_question` varchar(255) NOT NULL,
`ticket_status` tinyint(1) NOT NULL DEFAULT '1',
`ticket_subject` varchar(50) NOT NULL,
`ticket_creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`ticket_id`),
UNIQUE KEY `id` (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ;
关于php - sql 只存储每个用户 1 个请求,忽略其他请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35084626/
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数
我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
我在新的Debian6VirtualBoxVM上安装RVM时遇到问题。我已经安装了所有需要的包并使用下载了安装脚本(curl-shttps://rvm.beginrescueend.com/install/rvm)>rvm,但以单个用户身份运行时bashrvm我收到以下错误消息:ERROR:Unabletocheckoutbranch.安装在这里停止,并且(据我所知)没有安装RVM的任何文件。如果我以root身份运行脚本(对于多用户安装),我会收到另一条消息:Successfullycheckedoutbranch''安装程序继续并指示成功,但未添加.rvm目录,甚至在修改我的.bas