doukang2003 2015-03-16 21:26
浏览 53
已采纳

PHP MySQL数据被插入,仍然得到警告:mysqli_fetch_array()期望参数1是mysqli_result,[重复]中给出的布尔值

I am trying to make a reservation system, but everytime I try to submit, I get this error "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in", but the data still gets inserted to the database. It should also go to the submitted.php page, but it doesn't, it stays at the current page, I haven no idea what to do. Help me out guys, kinda new to PHP.

<?php 
session_start();
include("connect.php");
include("functies.php");

$db = mysqli_connect($host, $user, $password, $db)
or die(mysqli_connect_error());

//when submit button is clicked
if(isset($_POST['submit'])) {

$artist = $_POST['Artist'];
$track = $_POST['Track'];
$trackDL = $_POST['DownloadLink'];
$genre = $_POST['Genre'];
$sml = $_POST['Links'];
$date = $_POST['releaseDate'];


$query = "INSERT INTO submissions (users_Id, artist, track, trackDL, genre,  socialMediaLinks, dateRelease)
          VALUES (" . $_SESSION['id'] . ", '$artist', '$track', '$trackDL', '$genre', '$sml', '$date' )";
$result = $db->query($query) or die(mysqli_connect_error());

if ($row = mysqli_fetch_array($result)) {

    $sid = $row['submitId'];

    $_SESSION['submitted'] = true;
    $_SESSION['submitId'] = $sid;

}
}
mysqli_close($db);

submitted();

?>

This is my submitted function. When everything goes fine, it should go to the submitted.php file, but it doesn't.

function submitted(){
if (isset($_SESSION['submitted']) && $_SESSION['submitted'] == true) {
    header("Location:submitted.php");
    exit();
}
}
</div>
  • 写回答

1条回答 默认 最新

  • duandong9195 2015-03-16 21:43
    关注

    To check if an insert has been successful, you should check number of rows affected

    In your code instead of

    $res = $db->query () 
    

    Check

    If ($db->affected_rows == 1)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献