dongshendi3599 2011-04-27 19:57
浏览 47
已采纳

我在哪里设置这个PHP代码中的$ id变量?

I'm troubleshooting this code, I am very new to PHP, so any help would be appreciated.

I think the error is coming from not having the $id variable set anywhere, so where do I set it?

Here is the code:

// 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');

$result1 = false;

//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: success.php");
}
else
header("location: fail.php");


?>



<!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>
<?php

mysql_close();

?>


</body>
</html>

Per the statement:

if($result1){
header("location: success.php");
}
else
header("location: fail.php");

Every time I try to access the page it redirects to fail.php, so why does it fail?

  • 写回答

4条回答 默认 最新

  • drxm72811 2011-04-27 20:01
    关注

    Either $_POST['Submit'] is not set, or $count is 0.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!