PHP和Mysqli查询返回错误?

时间:2016-04-30 06:36:09

标签: php mysqli

我正在尝试将数组中的信息插入到MySQL表中。这是我的代码:

include "db_conx.php";
$transactionid = array(); //stores our output

首先我们从网址中获取结果,然后使用preg_match_all查找我们要查找的标记:

$url = file_get_contents("https://blockchain.info/address/1CRBDxjEQV317Q9DZZ13kVE23d2iY9Brqg?filter=2");

preg_match_all('#<a class="hash-link" href="/tx/([a-zA-Z0-9]*)">([a-zA-Z0-9]*)</a>#Uis', $url, $matches);

从上面的表达式中抓取每个匹配^:

foreach($matches[0] as $transactionids){
$transactionid[] = "<div class='transactionids' >".$transactionids."</div>";
}

为结果准备数据库:

$iresult = mysqli_query("INSERT INTO bitcoin (transaction) VALUES ("$transactionid[$i]")");

然后这是我用来记录结果的循环:

for($i = 0; $i < count($transactionid); $i++){
$iresult .= $transactionid[$i];
}

但它正在返回此错误:

Parse error: syntax error, unexpected '$transactionid' on line 21

编辑:所以在阅读下面的三个答案后,它现在插入一个空行而不是信息。

2 个答案:

答案 0 :(得分:2)

我认为你必须使用这样的东西: -

   $con=mysqli_connect("localhost","my_user","my_password","my_db");
$iresult = mysqli_query($con, "INSERT INTO bitcoin (transaction) VALUES (".$transactionid[$i].")");

答案 1 :(得分:0)

您忘记使用customizations句点运算符连接$ sql语句中的不同字符串。更改以下代码:

.

到此代码:

$iresult = mysqli_query("INSERT INTO bitcoin (transaction) VALUES ("$transactionid[$i]")");