我想将数据插入到 Image_Question 表中。但它不会在 Image_Question 表中执行插入。
我收到两个错误:
这是您可以使用的应用程序:Application
要使用应用程序查看发生了什么,请执行以下操作:
点击 Add Question 按钮两次以附加两个文件输入
现在一次上传一个文件,但要这样做。在第 1 行的文件输入中上传一个文件,然后在第 2 行上传一个文件,然后再次在第 1 行上传文件,最后在第 2 行上传文件。
下面是mysqli代码:
// Prepare your statements ahead of time
$questionsql = "INSERT INTO Question (QuestionNo) VALUES (?)";
if (!$insert = $mysqli->prepare($questionsql)) {
// Handle errors with prepare operation here
echo __LINE__.': '.$mysqli->error;
}
$imagequestionsql = "INSERT INTO Image_Question (ImageId, QuestionId)
VALUES (?, ?)";
if (!$insertimagequestion = $mysqli->prepare($imagequestionsql)) {
// Handle errors with prepare operation here
echo __LINE__.': '.$mysqli->error;
}
//make sure both prepared statements succeeded before proceeding
if( $insert && $insertimagequestion) {
$c = count($_POST['numQuestion']);
$question_ids = array();
for($i = 0; $i < $c; $i++ ) {
$questionNo = $_POST['numQuestion'][$i];
$insert->bind_param("i", $questionNo);
$insert->execute();
if ($insert->errno) {
// Handle query error here
echo __LINE__.': '.$insert->error;
break 1;
}
$questionId = $mysqli->insert_id;
$question_ids[$questionNo] = $questionId;
}
$imgresults = $_POST['imgid'];
foreach($imgresults as $imgid => $imgvalue) {
$image = $imgvalue;
$imgquesid = $question_ids[$imgid]; //LINE 305 where error is
foreach($imgvalue as $image) {
$insertimagequestion->bind_param("ii",$image, $imgquesid);
$insertimagequestion->execute();
if ($insertimagequestion->errno) {
// Handle query error here
echo __LINE__.': '.$insertimagequestion->error;
break 2;
}
}
}
$insertimagequestion->close();
$insert->close();
}
?>
下面是设置演示的代码:
function GetFormImageCount(){
return $('.imageuploadform').length + 1;
}
var qnum = 1;
var qremain = 5;
function insertQuestion(form) {
if (qnum > 5)
return;
var $tbody = $('#qandatbl_onthefly > tbody');
var $tr = $("<tr class='optionAndAnswer' align='center'>");
var $qid = $("<td width='5%' class='qid'></td>").text(qnum);
var $image = $("<td width='17%' class='image'></td>");
$('.num_questions').each( function() {
var $this = $(this);
var $questionNumber = $("<input type='hidden' class='num_questionsRow'>").attr('name',$this.attr('name')+"[]").attr('value',$this.val());
$qid.append($questionNumber);
++qnum;
$(".questionNum").text(qnum);
$(".num_questions").val(qnum);
--qremain;
$(".questionRemain").text(qremain);
});
var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target_image' onsubmit='return imageClickHandler(this);' class='imageuploadform' >" +
"<p class='imagef1_upload_form'><label>" +
"Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><br/><label class='imagelbl'>" +
"<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" +
"<p class='imagef1_upload_process'>Loading...<br/><img src='Images/loader.gif' /></p>" +
"<input type='hidden' class='numimage' name='numimage' value='" + GetFormImageCount() + "' />" +
"</p><p class='imagemsg'></p><p class='listImage'></p>" +
"<iframe class='upload_target_image' name='upload_target_image' src='/' style='width:0px;height:0px;border:0px;solid;#fff;'></iframe></form>");
$image.append($fileImage);
$tr.append($qid);
$tr.append($image);
$tbody.append($tr);
}
function imageValidation(imageuploadform) {
var val = $(imageuploadform).find(".fileImage").val();
switch(val.substring(val.lastIndexOf('.') + 1).toLowerCase()){
case 'gif':
case 'jpg':
case 'jpeg':
case 'pjpeg':
case 'png':
return true;
case '':
$(imageuploadform).find(".fileImage").val();
alert("To upload an image, please select an Image File");
return false;
default:
alert("To upload an image, please select an Image File");
return false;
}
return false;
}
function htmlEncode(value) { return $('<div/>').text(value).html(); }
function startImageUpload(imageuploadform){
$(imageuploadform).find('.imagef1_upload_process').show()
$(imageuploadform).find('.imagef1_upload_form').hide();
$(imageuploadform).find('.imagemsg').hide();
sourceImageForm = imageuploadform;
return true;
}
var imagecounter = 0;
function stopImageUpload(success, imageID, imagefilename) {
var result = '';
imagecounter++;
if (success == 1){
result = '<span class="imagemsg'+imagecounter+'">The file was uploaded successfully</span>';
$('.hiddenimg').eq(window.lastUploadImageIndex).append('<input type="text" name="imgid[]" id="'+imageID+'" value="' + imageID + '" />');
$('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage" data-imageID="'+imageID+'" data-image_file_name="' + imagefilename + '" value="'+imageID+'">Remove</button><br/><hr/></div>');
}
$(sourceImageForm).find('.imagef1_upload_process').hide();
$(sourceImageForm).find('.imagemsg').html(result);
$(sourceImageForm).find('.imagemsg').show();
$(sourceImageForm).find(".fileImage").replaceWith("<input type='file' class='fileImage' name='fileImage' />");
$(sourceImageForm).find('.imagef1_upload_form').show();
var _imagecounter = imagecounter;
$('.listImage').eq(window.lastUploadImageIndex).find(".deletefileimage").on("click", function(event) {
jQuery.ajax("deleteimage.php?imagefilename=" + $(this).attr('data-image_file_name')).done(function(data) {
$(".imagemsg" + _imagecounter).html(data);
});
var buttonid = $(this).attr('value');
$(this).parent().remove();
$("#"+ buttonid +"").remove();
});
return true;
}
function imageClickHandler(imageuploadform){
if(imageValidation(imageuploadform)){
window.lastUploadImageIndex = $('.imageuploadform').index(imageuploadform);
return startImageUpload(imageuploadform);
}
return false;
}
</script>
</head>
<body>
<form id="QandA" action="insertQuestion.php" method="post">
<table id="question">
<tr>
<th colspan="2">
Question Number <span class="questionNum">1</span>
<input type="hidden" class="num_questions" name="numQuestion" value="1">
</th>
</tr>
</table>
<table id="questionBtn" align="center">
<tr>
<th>
<input id="addQuestionBtn" name="addQuestion" type="button" value="Add Question" onClick="insertQuestion(this.form)" />
</th>
</tr>
</table>
</div><hr/><!-- This Divide close tag has no open tag!-->
<table id="qandatbl" align="center" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th width="5%" class="qid">Question Number</th>
<th width="17%" class="image">Image</th>
</tr>
</thead>
</table>
<div id="qandatbl_onthefly_container">
<table id="qandatbl_onthefly" align="center" cellpadding="0" cellspacing="0" border="0">
<tbody>
</tbody>
</table>
</div>
<div class="hiddenimg"><!-- All uploaded image file ids go here --></div>
</form>
</body>
通过执行以下 var_dumps:
var_dump($question_ids);
var_dump($imgresults);
我得到这些结果:
array(2) {
[1]=> int(159)
[2]=> int(160)
}
array(2) {
[0]=> string(3) "129"
[1]=> string(3) "130"
}
奇怪的是 imgresult 的数字从 0 然后 1 开始,我也不知道为什么它是字符串,它应该是一个 int。但是,如果它来自输入,我是否将 bind_param i 或 s 称为 db 中的 int?
额外细节:
我没有得到的是在这个 mysqli 下面,我生成了一个类似的 mysqli 作为答案,奇怪的是它正确地插入,即使它像上面的 image_question 插入一样以 0 开头:
$results = $_POST['value'];
foreach($results as $id => $value)
{
$answer = $value;
$quesid = $question_ids[$id];
foreach($value as $answer)
{
$insertanswer->bind_param("is", $quesid, $answer);
$insertanswer->execute();
if ($insertanswer->errno) {
// Handle query error here
echo __LINE__.': '.$insertanswer->error;
break 5;
}
}
}
var_dump($result) 显示 1 个问题的先前 var 转储:
array(1) { //var_dump($question_ids);
[1]=> int(171)
} array(1) { //var_dump($imgresults);
[0]=> string(3) "130"
} array(1) {
[1]=> array(1) { //var_dump($results);
[0]=> string(1) "B" } }
最佳答案
我的回答不会针对特定问题,而是针对更广泛的主题。
这是关于您一般的工作方式。
你需要改变它。
看,您所有的问题都很重要 需要回答。并且变得更大。却得到更少的答案。
它会让你做绝望的事情——在问题、赏金、账户上作弊——但都是徒劳的。
那是无路可走的路。
您需要改变您学习事物的方式以及您使用这个出色网站的方式。
了解他们正在使用的工具对任何人来说都非常重要。您必须自己编写代码,只有在真正解决问题时才寻求帮助。
因此,您将了解您的代码。这很重要 - 了解您的代码的作用。它的每一行。因此,您将能够自己解决问题并修复代码。
否则你注定要为每一个打字错误寻求帮助,就像在这种情况下一样。
此外,由于您无法深入挖掘问题的根源,您必须将大量代码与您的问题一起发布,这使得回答变得复杂。
您的问题中有三个独立的领域 - JavaScript、PHP 和 Mysql。而问题只属于其中一个。你必须学会将你的问题至少分离到这些领域的限制。
是 JS 从客户端发送了错误的(意外的)数据吗?好了,把所有PHP和Mysql代码都收起来,只剩下JS了。它将帮助 Stackoverflowers 甚至您自己调查问题。
这个数据好吗?你确定吗?打印出来并确保它正是您所期望的。
如果没问题 - 转到 PHP 部分(但不要忘记从问题中删除所有 JS)。
等等。
不要笼统地问你的问题,比如“它没有插入”,而是根据特定的数据流:“我期待这样的数据进入程序,但我有另一个。”
一旦开始使用它,您将不需要 Stackoverflow 来回答:您将能够将问题追溯到数据意外出错的地方。所以 - 你找到了错误的地方。
运行问题代码也很重要。并在您遇到问题的环境中运行它。
运行代码并检查实际结果比用眼睛看代码更有效率。
甚至有些情况只属于你的服务器而其他人不知道,导致他们根本无法回答你的问题。
此外,人类 不应该在头脑中运行 PHP 代码。它可以用于几行,但从某种程度上来说,它不可能在脑子里运行所有代码并找到错误。
这就是为什么运行您的代码并打印出所有值、函数结果、检查变量状态等并查找其中的不一致如此重要的原因。
当然,要使用这种技术,您必须了解哪些数据正确,哪些不正确。
这就是为什么从头开始编写代码并自行规划如此重要的原因。
如果是您决定,哪些数据应该来自 JS - 您可以判断它是好是坏。如果是其他人 - 你就陷入了死胡同,注定要再次询问,让事情变得更糟。
你需要打破这个恶性循环。
这就是为什么它如此重要 - 自己编写代码,而不是让别人为你做。
希望对你有所帮助,祝学习顺利。
关于php - 它不是将数据插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14554847/
我主要使用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
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD
本教程将在Unity3D中混合Optitrack与数据手套的数据流,在人体运动的基础上,添加双手手指部分的运动。双手手背的角度仍由Optitrack提供,数据手套提供双手手指的角度。 01 客户端软件分别安装MotiveBody与MotionVenus并校准人体与数据手套。MotiveBodyMotionVenus数据手套使用、校准流程参照:https://gitee.com/foheart_1/foheart-h1-data-summary.git02 数据转发打开MotiveBody软件的Streaming,开始向Unity3D广播数据;MotionVenus中设置->选项选择Unit
文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co
HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候
我正在尝试在Rails上安装ruby,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf
文章目录1.开发板选择*用到的资源2.串口通信(个人理解)3.代码分析(注释比较详细)1.主函数2.串口1配置3.串口2配置以及中断函数4.注意问题5.源码链接1.开发板选择我用的是STM32F103RCT6的板子,不过代码大概在F103系列的板子上都可以运行,我试过在野火103的霸道板上也可以,主要看一下串口对应的引脚一不一样就行了,不一样的就更改一下。*用到的资源keil5软件这里用到了两个串口资源,采集数据一个,串口通信一个,板子对应引脚如下:串口1,TX:PA9,RX:PA10串口2,TX:PA2,RX:PA32.串口通信(个人理解)我就从串口采集传感器数据这个过程说一下我自己的理解,
SPI接收数据左移一位问题目录SPI接收数据左移一位问题一、问题描述二、问题分析三、探究原理四、经验总结最近在工作在学习调试SPI的过程中遇到一个问题——接收数据整体向左移了一位(1bit)。SPI数据收发是数据交换,因此接收数据时从第二个字节开始才是有效数据,也就是数据整体向右移一个字节(1byte)。请教前辈之后也没有得到解决,通过在网上查阅前人经验终于解决问题,所以写一个避坑经验总结。实际背景:MCU与一款芯片使用spi通信,MCU作为主机,芯片作为从机。这款芯片采用的是它规定的六线SPI,多了两根线:RDY和INT,这样从机就可以主动请求主机给主机发送数据了。一、问题描述根据从机芯片手