Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php/sql代码未将数组插入sql表_Php_Mysql_Arrays - Fatal编程技术网

php/sql代码未将数组插入sql表

php/sql代码未将数组插入sql表,php,mysql,arrays,Php,Mysql,Arrays,我有一些代码,如下所示,它将一些数据插入到sql表中。我尝试输入的数组工作正常,我还在插入代码前加了一个额外的检查,该代码正确显示了数组$array\u author[$I] 我真的不明白为什么product\u rating表中的插入代码不能正常工作 // Firstly the Author data is used to make a new user in the users table. for($i = 0; $i<count($array_review); $i++){

我有一些代码,如下所示,它将一些数据插入到sql表中。我尝试输入的数组工作正常,我还在插入代码前加了一个额外的检查,该代码正确显示了数组
$array\u author[$I]

我真的不明白为什么
product\u rating
表中的插入代码不能正常工作

// Firstly the Author data is used to make a new user in the users table.
for($i = 0; $i<count($array_review); $i++){
  $queryInsertUser=mysqli_query($link,"INSERT INTO `users` 
  (`Name`, `DOB`, `Sex`, `Email`, `Address`, `AddedDate`, `AddedFrom`,`Crawler`) 
  VALUES ('$array_author[$i]', '$dob', '$sex', '$email', '$address', NOW(), '$http_referrer',2)");

// Review and rating data is inserted into the product_rating table.  The user created from the author data
//is then inserted into the product_rating table.
  $selectuser = mysqli_query($link, " SELECT `UserID` FROM `users` ORDER BY `UserID` DESC LIMIT 1 ");
  while ($rowGetDetails = mysqli_fetch_array($selectuser)){
    echo '<br>';
    echo $array_review[$i];
    $sql2 = "INSERT INTO product_rating (ProductID,Rating,AddedDate,Comment,AddedBy,AddedFrom,crawler) 
    VALUES ('$ProductID','$array_rating2[$i]',NOW(),'$array_review[$i]','$UserID','".$_SERVER['REMOTE_ADDR']."','2')";
    $insertcomment = mysqli_query($link, $sql2);
    }
  }

这很有趣,因为您没有数组,因此可以包含您正在使用的那些变量的声明
$array_author = array();
$pos = -1;
while(FALSE != $pos = strpos($str_test, "<span itemprop=\"author\">",$pos+1)) {
    $pos2 = substr($str_test, $pos+24);       
    $pos3 = strpos($pos2, "</span>");
    $author= substr($pos2, 0, $pos3);
    $author=ltrim ($author);       
    $author=rtrim ($author);
    $array_author[ ] = $author;
    }

$array_review = array();
$pos3 = -1;
while (FALSE != $pos3 = strpos($str_test, "<span itemprop=\"description\">",$pos3 + 1)){ 
          $pos4= substr($str_test, $pos3+30);
          $pos5 = strpos($pos4, "</span>");
          $review= substr($pos4, 0, $pos5);   
          $review=ltrim ($review);       
          $review=rtrim ($review);
          $array_review[ ] = $review;
          }

$array_rating = array();
$pos3 = -1;
while (FALSE != $pos3 = strpos($str_test, "<span itemprop=\"ratingValue\">", $pos3 + 1)){
          $pos4= substr($str_test, $pos3+29);
          $pos5 = strpos($pos4, "</span>");
          $rating= substr($pos4, 0, $pos5);   
          $rating=ltrim ($rating);       
          $rating=rtrim ($rating);
          $array_rating[] = $rating;
          }