php – mysql查询INSERT INTO和SET问题

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – mysql查询INSERT INTO和SET问题脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我现在已经摸不着头了好一个小时,但我无法弄清楚我在这里做错了什么.我希望有人能指出我正确的方向.

我试图使用INSERT INTO方法将一些数据插入到sql数据库中,但它似乎不起作用.我包含了许多回声,看看尝试,看看错误到底在哪里.从此我知道代码正常的,直到调用INSERT INTO部分.此外,在线检查数据库显示没有添加任何信息…在线数据库有3个表,’噪音’,’波浪’和’脉冲’.此外,所有字段都存在,所以我真的不明白为什么这个代码失败.

<?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=%@&amp;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

任何人都可以看到为什么这段代码没有更新表?

提前致谢.

解决方法

看起来你有像BY,TABLE,TYPE这样的字段是保留字.使用反引用这些:

`BY` = '$by',...

`TABLE` = '$table',...

`TYPE` = '$type' ;" );

脚本宝典总结

以上是脚本宝典为你收集整理的php – mysql查询INSERT INTO和SET问题全部内容,希望文章能够帮你解决php – mysql查询INSERT INTO和SET问题所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。