当我在本地主机中运行它时,以下代码有效,但是当我在线托管它时,它给出了错误。
if(isset($_POST['congressman'])){
$congressman = $_POST['congressman'];
$no_of_votes = mysql_result(mysql_query("SELECT no_of_votes FROM `tbcandidates` WHERE `identification_no`=$congressman"),0) + 1;
$query=mysql_query("UPDATE tbcandidates SET no_of_votes = '$no_of_votes' WHERE identification_no = $congressman");
这一行:
no_of_votes = mysql_result(mysql_query("SELECT no_of_votes FROM `tbcandidates` WHERE `identification_no`=$congressman"),0) + 1;
它说mysql_result():提供的参数不是等中的有效MySQL结果资源。
尝试在代码顶部添加ob_start()
,在末尾添加ob_flush()
已经发送的标头只是意味着在你调用 header() 指令之前已经有一个数据输出......
因此,您询问的是在本地主机上运行的原因,而服务器拒绝运行它: 严格的模式和错误处理 - 在您的 webhosts 服务器上,设置可能更严格,因此错误不会像在本地主机上那样被忽略
搜索在标题之前进行的任何输出并将其删除。
在head
函数之前找出输出。它可能是一些 html 内容,可能是 bom 标头,也可能是其他一些警告消息。
快速解决方法是将代码放在脚本的顶部。
<?php
if ($_POST['user']=="admin" && $_POST['pass']=="password"){
header('Location: adminview.php');
exit;
}