我已经挠头好一个小时左右了,但我不知道我在这里做错了什么。我希望有人能指出我正确的方向。
我正在尝试使用 INSERT INTO 方法将一些数据插入到 SQL 数据库中,但它似乎不起作用。我包含了很多 echo 来尝试查看错误的确切位置。由此我知道在调用 INSERT INTO 部分之前代码是可以的。此外,检查在线数据库发现没有添加任何信息......在线数据库有 3 个表,'noise'、'wave' 和 'pulse'。此外,所有字段都存在,所以我真的不明白为什么这段代码会失败。
<?php
//Connect To Database
$hostname='myhostname';
$username='myusername';
$password='mypassword';
$dbname='dbname';
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
// test to see what kind of instrument is being uploaded.
$type=strip_tags($_GET['TYPE']);
if($type == 'noise') {
$audio=strip_tags($_GET['AUDIO']);
echo $audio;
$automate=strip_tags($_GET['AUTOMATE']);
echo $automate;
$by=strip_tags($_GET['BY']);
echo $by;
$envelope=strip_tags($_GET['ENVELOPE']);
echo $envelope;
$length=strip_tags($_GET['LENGTH']);
echo $length;
$name=strip_tags($_GET['NAME']);
echo $name;
$notes=strip_tags($_GET['NOTES']);
echo $notes;
$output=strip_tags($_GET['OUTPUT']);
echo $output;
$patchname=strip_tags($_GET['PATCH_NAME']);
echo $patchname;
$s_cmd=strip_tags($_GET['S_CMD']);
echo $s_cmd;
$shape=strip_tags($_GET['SHAPE']);
echo $shape;
$table=strip_tags($_GET['TABLE']);
echo $table;
$table0=strip_tags($_GET['table0']);
echo $table0;
$table1=strip_tags($_GET['table1']);
echo $table1;
$table2=strip_tags($_GET['table2']);
echo $table2;
$table3=strip_tags($_GET['table3']);
echo $table3;
$table4=strip_tags($_GET['table4']);
echo $table4;
$table5=strip_tags($_GET['table5']);
echo $table5;
$table6=strip_tags($_GET['table6']);
echo $table6;
$table7=strip_tags($_GET['table7']);
echo $table7;
$table8=strip_tags($_GET['table8']);
echo $table8;
$table9=strip_tags($_GET['table9']);
echo $table9;
$tableA=strip_tags($_GET['tableA']);
echo $tableA;
$tableB=strip_tags($_GET['tableB']);
echo $tableB;
$tableC=strip_tags($_GET['tableC']);
echo $tableC;
$tableD=strip_tags($_GET['tableD']);
echo $tableD;
$tableE=strip_tags($_GET['tableE']);
echo $tableE;
$tableF=strip_tags($_GET['tableF']);
echo $tableF;
//input this info into the SQL noise instrument table
$request = mysql_query("INSERT INTO `noise` SET
AUDIO = '$audio',
AUTOMATE = '$automate',
BY = '$by',
ENVELOPE = '$envelope',
LENGTH = '$length',
NAME ='$name',
NOTES = '$notes',
OUTPUT = '$output',
PATCH_NAME = '$patchname',
S_CMD = '$s_cmd',
SHAPE = '$shape',
TABLE = '$table',
table0 = '$table0',
table1 = '$table1',
table2 = '$table2',
table3 = '$table3',
table4 = '$table4',
table5 = '$table5',
table6 = '$table6',
table7 = '$table7',
table8 = '$table8',
table9 = '$table9',
tableA = '$tableA',
tableB = '$tableB',
tableC = '$tableC',
tableD = '$tableD',
tableE = '$tableE',
tableF = '$tableF',
TYPE = '$type';" );
if($request) {
echo "Your patch has been successfully uploaded.";
echo "Thanks for contributing!";
}
else {
echo "there has been a problem";
}
}
?>
当我从我的 iPhone 应用加载此 URL 时:
NSString *website = [NSString stringWithFormat:@"http://mywebsite/problem.php?AUDIO=%@&AUTOMATE=%@&BY=%@&ENVELOPE=%@&LENGTH=%@&NAME=%@&NOTES=%@&OUTPUT=%@&PATCH_NAME=%@&S_CMD=%@&SHAPE=%@&TABLE=%@&table0=%@&table1=%@&table2=%@&table3=%@&table4=%@&table5=%@&table6=%@&table7=%@&table8=%@&table9=%@&tableA=%@&tableB=%@&tableC=%@&tableD=%@&tableE=%@&tableF=%@&TYPE=%@", audio, automate, by, envelope, length, name, notes, output, patch_name, s_cmd, shape, table, table0, table1, table2, table3, table4, table5, table6, table7, table8, table9, tableA, tableB, tableC, tableD, tableE, tableF, type];
[BackgroundLoader loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:website]]];
我得到的输出是:
AUDIOAUTOMATEBYENVELOPELENGTHNAMENOTESOUTPUTPATCH_NAMES_CMDSHAPETABLETABLE0...TABLEFthere has been a problem
谁能看出为什么这段代码没有更新表格?
提前致谢。
最佳答案
mysql查询可以使用insert set格式
问题可以通过在你的查询之后添加找到
if (mysql_error()) {
die (mysql_error());
}
这会给你一个错误信息
我猜我会说查询末尾的分号会导致问题,这在通过 php 调用时不是必需的
您还应该在列名周围加上反引号。您可能会发现 TYPE 是一个保留字,因此至少要在 TYPE
您的脚本也对 sql 注入(inject)开放。尝试使用 $value = mysql_real_escape_string($_GET['value']) 来阻止这种情况发生
关于php - mysql查询INSERT INTO和SET问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6321112/
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
我知道我可以指定某些字段来使用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
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。