PHP注意:未定义的索引/ PHP注意:未定义的变量

时间:2013-07-16 10:59:05

标签: php

我真的很沮丧。我正在将我的网站从php 5.2移动到php 5.3。从我的表单添加信息到mysql数据库时,添加一个空记录,我收到这些错误消息,它们相互连接。错误日志消息是:

[Tue Jul 16 12:37:08 2013] [warn] [client XX.XX.XXX.XXXX] mod_fcgid: stderr: PHP Notice:  Undefined variable: prijs in XXX/page.php on line 100, referer: XXX/page.php
[Tue Jul 16 12:37:08 2013] [warn] [client XX.XX.XXX.XXXX] mod_fcgid: stderr: PHP Notice:      Undefined index: type_contract in XXX/page.php on line 116, referer: XXX/page.php
[Tue Jul 16 12:37:08 2013] [warn] [client XX.XX.XXX.XXXX] mod_fcgid: stderr: PHP Notice:  Undefined index: klantnummer in XXX/page.php on line 117, referer: XXX/page.php
[Tue Jul 16 12:37:08 2013] [warn] [client XX.XX.XXX.XXXX] mod_fcgid: stderr: PHP Notice:  Undefined index: datum in XXX/page.php on line 118, referer: XXX/page.php
[Tue Jul 16 12:37:08 2013] [warn] [client XX.XX.XXX.XXXX] mod_fcgid: stderr: PHP Notice:  Undefined index: omschrijving in XXX/page.php on line 119, referer: XXX/page.php

我已尝试过所有内容,例如添加

if (isset($_POST['prijs'])) { $prijs = $_POST['prijs']; }

它所指的代码是:

<?php if (isset($_GET['action']) && ($_GET['action'] == "abonnement_toevoegen")) {

$prijs = $_POST['prijs'];  <=== this is the code is referring to!!!

$prijs_comma = str_ireplace(",", ".", "$prijs");

$prijs = $prijs_comma;
$btw = $prijs * 0.21;
$totaal = $prijs + $btw;

$prijs = round($prijs, 2);
$btw = round($btw, 2);
$totaal = round($totaal, 2);

$prijs_weergave = str_ireplace(".", ",", "$prijs");
$btw_weergave = str_ireplace(".", ",", "$btw");
$totaal_weergave = str_ireplace(".", ",", "$totaal");

include("include_addslashes.php");

$type_contract = $_POST['type_contract']; <=== this is the code is referring to!!!
$klantnummer = $_POST['klantnummer']; <=== this is the code is referring to!!!
$datum = $_POST['datum']; <=== this is the code is referring to!!!
$omschrijving = $_POST['omschrijving']; <=== this is the code is referring to!!!

$sql = "INSERT INTO wi_abonnementen
(
type_contract,
klant_id,
factuurdatum,
omschrijving,
prijs,
btw,
totaal
 )
VALUES
(
'$type_contract',
'$klantnummer',
'$datum',
'$omschrijving',
'$prijs_weergave',
'$btw_weergave',
'$totaal_weergave'
)";

if (!mysql_query($sql, $con)) {
    die('Error: ' . mysql_error());
}

include("include_stripslashes.php");
var_dump($_POST);
?>

请帮助,我在不同的网站上反复收到此错误消息。

表单的HTML代码为:

<form action="finance.php?action=abonnement_toevoegen" method="post"  name="abonnement_toevoegen">
<table>
<tr>
    <td>Type</td>
    <td><select name="type_contract" size="1">
            <option value="">Kies een optie</option>
            <option value="tco">TouringcarOfferte</option>
            <option value="tao">TaxiOfferte</option>
            <option value="wih">Wi4 Hosting</option>
            <option value="wii">Wi4 Internet diensten</option>
        </select></td>
</tr>
<tr>
    <td>Klant</td>
    <td><select name="klantnummer" size="1">
            <option value="">Kies een optie</option>
                            <option value=""> ()</option> 
                            <option value="wi126">XXX (wi126)</option> 
                            <option value="Wi154">XXX (Wi154)</option> 
                            <option value="wi108">XXX (wi108)</option>
                        </select>       
    </td>
</tr>
<tr>
    <td>Factuurdatum</td>
    <td><input class="form" type="Text" name="datum" value="2013-07-17" size="10">        </td>
</tr>
<tr>
    <td valign="top">Omschrijving</td>
    <td><textarea class="form" name="omschrijving" cols="25" rows="4"></textarea>    </td>
</tr>
<tr>
    <td>Prijs (excl. BTW)</td>
    <td>&#8364; <input class="form" type="Text" name="prijs" value="" size="10">    </td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr>
    <td></td>
    <td><input type="submit" class="form" value="Voeg toe"></td>
</tr>
</table>
<div id='abonnement_toevoegen_errorloc' class='error_strings'></div>
</form>

感谢名单!

1 个答案:

答案 0 :(得分:0)

我不确定为什么它会在之前版本的PHP中运行但不会在新版本中运行。

但是,我确定问题是第一次运行时整个工作正常,然后重定向到同一页面,没有设置POST变量,因为它不是来自表单

尝试删除任何重定向,应该修复它。然后根据需要对重定向进行排序(尽管在提交表单后您不需要再次重定向)。

如果您希望我查看其他内容,请随意发布其余代码。