dongnai3960 2012-05-22 13:32
浏览 150

网站在线工作正常,但在localhost上运行显示未定义的索引和变量

having a panic here! my dissertation website works fine online, but an hour before submission i found out it doesnt work on a local host..two or 3 pages keep coming up with undefined index or variable. could anyone help? Here is a snipped of an error: Notice: Undefined index: tables in C:\Users..\Desktop\USBWebserver v8_enoot\SnysbArchive\Search.php on line 76

<?php
include 'UserFunction.php';
..html omitted..
//write connect function in here
include('Connect.php'); //Connects to database
$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);

if (!$result) 
{
    echo "DB Error, could not list tables
";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}
if (mysql_select_db($dbname, $conn))
{
?>
    <form method="post" action="SearchResults.php?go" id="searchform">
    In <select name="tables">
    <?php
    while ($row = mysql_fetch_row($result)) 
    {
    if ($row[0] != 'user_details' && $row[0] != 'request') 
    {
        echo '<option value="'.$row[0].'">'.$row[0].'</option>';
    }
    }
}
    ?>
    </select>
        Seach for: <input type="text" name="name"> 
    <input type="submit" name="submit" value="Search" />
</form>

<br>
<?php
$tbl=$_POST['tables'];
echo $tbl;
?>

it doesnt like this line $tbl=$_POST['tables']; thanks

  • 写回答

2条回答 默认 最新

  • dongyuan3094 2012-05-22 13:34
    关注

    Your local server has error reporting set to be higher then on your production server. This is resulting in you getting error messages for "lesser" errors like notices that you won't get on your production server. That's a good thing as your production server shouldn't be showing error messages will may be helpful to hackers and your local server should be telling you everything you are doing wrong, big and little, so you can build your application properly before going live.

    In your case $_POST['tables'] isn't set and is being reported by your local server. It's also being caught by your production server but because of your error reporting settings you aren't being notified (except probably in your error logs).

    UPDATE

    To fix your error, check to see if that value exists before assigning it to a variable:

    $tbl = (isset($_POST['tables'])) ? $_POST['tables'] : ''; 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器