简体   繁体   English

错误数组,我无法获取信息 - 在mysql查询中

[英]Error array, i cant get out the information - in mysql query

Hello i got a big trouble which i couldnt solve, this is a very weird problem :S i use the next code: 您好我遇到了一个无法解决的大问题,这是一个非常奇怪的问题:我使用下一个代码:

for( $m = 0; $m < sizeof( $jugadores ) ; $m++ )
{   
            $juga_q = "INSERT INTO jugadores VALUES($jugadores[$m][1],$nom_equipo,'',$jugadores[$m][4]);";
            $result = mysql_query( $juga_q );
            echo $juga_q."<br>";
}

i got information in the array which i want to insert into my data base, for that i dump my query in $juga_q variable which i use in the insert into, but the query doesnt execute and i make an echo to check whats failing and got the next: 我得到了数组中的信息,我想插入到我的数据库中,因为我将我的查询转储到我在插入中使用的$ juga_q变量中,但是查询没有执行,我做了一个回声来检查什么是失败的并得到了下一个:

 INSERT INTO jugadores VALUES(Array[1],Aston Villa,'',Array[4]);

when i make a echo of the array out of this query i got no problems, thats why im getting crazy with that and hope u could help me. 当我从这个查询中回应数组时,我没有遇到任何问题,这就是为什么我对此感到疯狂并希望你能帮助我。

Thanks forward!! 谢谢!

try to concatenate it, 试着连接它,

$juga_q = "INSERT INTO jugadores VALUES(". $jugadores[$m][1].",$nom_equipo,'',".$jugadores[$m][4].");";

As a sidenote, the query is vulnerable with SQL Injection if the value( s ) of the variables came from the outside. 作为一个旁注,查询是脆弱的SQL Injection ,如果变量的值(一个或多个 )从外面走了进来。 Please take a look at the article below to learn how to prevent from it. 请查看下面的文章,了解如何防止它。 By using PreparedStatements you can get rid of using single quotes around values. 通过使用PreparedStatements您可以摆脱使用值周围的单引号。

When using array accessors in strings, you need to wrap them in brackets. 在字符串中使用数组访问器时,需要将它们包装在括号中。

Instead of "VALUES ($jugadores[$m][1],..." , try using "VALUES ({$jugadores[$m][1]},..." . 而不是"VALUES ($jugadores[$m][1],..." ,尝试使用"VALUES ({$jugadores[$m][1]},..."

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM