English 中文(简体)
网站在网上运作良好,但在本地主机上运行显示未定义的索引和变量
原标题:Website works fine online, but running on localhost displays undefined index and variable

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..DesktopUSBWebserver v8_en ootSnysbArchiveSearch.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

问题回答

您的本地服务器有 < a href=> https:// www.php. net/ manual/ en/ opident.error- reporting. php> rel= “ nofollown noreferrer” > error report 设置在您的生产服务器上, 时间会更高一些。 这导致您获得错误信息, 比如您在生产服务器上不会得到的通知等“ 更低” 错误 。 您的生产服务器不应该显示错误信息, 这会对黑客有帮助, 您的本地服务器应该告诉您您您做错、 大而小的事情, 这样您就可以在直播前正确构建您的应用程序 < em > < / em > 之前 / 。

在您的情况中, $_POST[表] 尚未设置,并且正在由您的本地服务器报告。它也被生产服务器捕获,但由于您的错误报告设置,您没有得到通知(除了错误日志中可能存在的错误)。

<强> UPDATE

要修正错误, 请检查该值是否存在, 然后再将它指定为变量 :

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

你总是可以放

error_reporting(E_ALL ^ E_NOTICE);

在页面的顶端, 这将防止 PHP 抱怨被引用但尚未存在的变量 。

最好照@john Conde 的建议去做, 我的建议会消除错误, 但允许您以简便的方式编码。 软代码不是最好的 。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签