Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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错误未定义变量:result1帮助!_Php_Mysql - Fatal编程技术网

php错误未定义变量:result1帮助!

php错误未定义变量:result1帮助!,php,mysql,Php,Mysql,我试图对这段代码进行故障排除,但我遇到了这个错误,我不知道如何修复它:第44行的plainview.php中的未定义变量:result1 代码如下: // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sq

我试图对这段代码进行故障排除,但我遇到了这个错误,我不知道如何修复它:第44行的plainview.php中的未定义变量:result1

代码如下:

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$sql="SELECT * FROM $tbl_name WHERE depot = 'plainview'";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);

//error reporting
error_reporting(E_ALL); ini_set('display_errors', '1');


//update
if(isset($_POST['Submit'])){
for($i=0;$i<$count;$i++){

$sql1 = "UPDATE $tbl_name SET 

available='".mysql_real_escape_string($_POST['available'][$i])."', 
rent='".mysql_real_escape_string($_POST['rent'][$i])."',  
corp_ready='".mysql_real_escape_string($_POST['corp_ready'][$i])."', 
down='".mysql_real_escape_string($_POST['down'][$i])."',  
gfs='".mysql_real_escape_string($_POST['gfs'][$i])."', 
dateTime = NOW()   
WHERE id='".$id[$i]."'";



$result1 = mysql_query($sql1) or die(mysql_error());
}
}

//redirect
if($result1){
header("location: plainview.php");
}




mysql_close();
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script language="JavaScript1.1" type="text/javascript">
<!--
function mm_jumpmenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<title>Untitled Document</title>
</head>

<body>

<div>
    <p>Plainview, North East Region</p>
    <p>Select a different region: <select onchange="mm_jumpmenu('parent',this,0)" name="lostlist">
                <option value="" selected="selected">Choose Your Depot</option>
                <option value="plainview.php">Plainview</option>
                <option value="worcrester.php">Worcrester</option>

                </select></p>
</div><Br />

<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="700" border="0" cellspacing="1" cellpadding="0">

<tr>
<td>ID</td>
<td align="center"><strong>Product Name</strong></td>
<td align="center"><strong>Available</strong></td>
<td align="center"><strong>Rent</strong></td>
<td align="center"><strong>Corp Ready</strong></td>
<td align="center"><strong>Down</strong></td>
<td align="center"><strong>GFS</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="left"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td>

<td align="left"><?php echo $rows['product']; ?></td>
<td align="center"><input name="available[]" type="text" id="available" value="<?php echo $rows['available']; ?>" size="5"></td>
<td align="center"><input name="rent[]" type="text" id="rent" value="<?php echo $rows['rent']; ?>" size="5"></td>
<td align="center"><input name="corp_ready[]" type="text" id="corp_ready" value="<?php echo $rows['corp_ready']; ?>" size="5"></td>
<td align="center"><input name="down[]" type="text" id="down" value="<?php echo $rows['down']; ?>" size="5" /></td>
<td align="center"><input name="gfs[]" type="text" id="gfs" value="<?php echo $rows['gfs']; ?>" size="5"></td>

</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>



</body>
</html>
//连接到服务器并选择数据库。
mysql_connect(“$host”、“$username”、“$password”)或die(“无法连接”);
mysql_select_db($db_name)或die(“无法选择db”);
$sql=“从$tbl\U名称中选择*,其中depot='plainview';
$result=mysql\u查询($sql);
//统计表行数
$count=mysql\u num\u行($result);
//错误报告
错误报告(E_全部);ini_集('display_errors','1');
//更新
如果(isset($_POST['Submit'])){
对于($i=0;$i)
无标题文件
普莱恩维尤,东北地区

选择其他区域: 选择你的仓库 普莱恩维尤 沃克雷斯特


身份证件 产品名称 可用 租金 公司准备就绪 向下 GFS
$result1
仅在for循环内、if语句内设置。如果
if
失败,则从未定义它,因此
if($result1)
给出该错误。在if语句之前设置$result1=false。更好的是,将
if
语句移动到整个代码块周围,包括数据库连接和断开连接的内容。

第44行$result未定义,如果

if ( isset( $_POST['Submit'] )) {
 ...
 $result1 = mysql_query($sql1) or die(mysql_error());
}
由于您没有发布请求或未定义$\u POST['Submit'],因此会使其块偏转


预设$result1的默认值为FALSE。

只有通过POST操作调用脚本时,才能定义$result1。因此

if($result1){
    header("location: plainview.php");
}
将在您不处于POST状态时发出警告


另外,另一方面,在获取行以生成HTML之前,您正在关闭mysql连接。这将终止您的页面输出,因为在您关闭连接时,结果尚未“获取”。

我已经更新了页面,但现在它失败了,我想这是因为我没有在任何地方设置$id