dpge74512 2015-07-22 16:07
浏览 22
已采纳

发送联系表单时出现Mysql错误[关闭]

I get the errors

Warning: mysqli_close() expects exactly 1 parameter, 0 given in /home1/ab61859/public_html/contact.php on line 143 and

Warning: Cannot modify header information - headers already sent by (output started at /home1/ab61859/public_html/contact.php:143) in /home1/ab61859/public_html/contact.php on line 144

My php code is here http://pastebin.com/4KVr7bg1

I have no idea what I did wrong, so please help me thanks, ItsMeRomian

  • 写回答

1条回答 默认 最新

  • douxiexie3574 2015-07-22 17:18
    关注

    In the following code (which is from the pastebin link above):

    foreach($form_data as $name=>$value)
    {
      mysqli_query($db, "UPDATE $mysql_table SET $name='".mysqli_real_escape_string($db, $value)."' WHERE ID=$id") or die('Failed to update table!<br>'.mysqli_error($db));
    }
    mysqli_close();
    header('Location: '.$success_url);
    exit;
    

    You need to put the connection or link handle generated during the connection in the mysqli_close() statement so it knows which one to close (i.e. you can have more than one open at a time). If you change your snippet to use the following line the close error should go away.

    mysqli_close($db);
    

    Once the close error goes away then the redirect header issues on the next line may work. I say may because if you have other output happening before you issue the header it will continue to fail. Headers can only be used successfully when the web page has not generated any other non-header output.

    As a side note you may want to build one large SQL string instead of doing a database update for each field returned. However, that's food for some more learning and/or a future question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?