我正试图将数组中的信息插入MySQL表中。这是我的代码:
include "db_conx.php";
$transactionid = array(); //stores our output
因此,首先我们从url中获取结果,然后使用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
编辑:所以在阅读了下面的三个答案后,它现在插入一个空白行,而不是信息。
我认为你必须使用这样的东西:-
$con=mysqli_connect("localhost","my_user","my_password","my_db");
$iresult = mysqli_query($con, "INSERT INTO bitcoin (transaction) VALUES (".$transactionid[$i].")");
您忘记使用.
句点运算符连接$sql语句中的不同字符串。更改以下代码:
$iresult = mysqli_query("INSERT INTO bitcoin (transaction) VALUES ("$transactionid[$i]")");
到此代码:
$iresult = mysqli_query("INSERT INTO bitcoin (transaction) VALUES (".$transactionid[$i].")");