0

I am really getting frustrated. I am moving my website from php 5.2 to php 5.3. When adding information from my form to the mysql database an empty record is added and I am getting this error messages, which are connected to each other. The error log message is:

[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

I have tried everything, like adding

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

The code it is referring to is:

<?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);
?>

Please help, I am getting this error message over and over again with different websites.

The HTML code of the form is:

<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>

Thanx!

Charles
  • 50,943
  • 13
  • 104
  • 142
Paul Willems
  • 51
  • 1
  • 2
  • 8

1 Answers1

0

I'm not sure why it would've worked in a previous version of PHP but not in a new one.

However, I'm certain the problem is that the whole thing is working fine the first run, then there's a redirect back to the same page, where no POST variables are set because it's not coming from a form.

Try getting rid of any redirects, that should fix it. Then sort out the redirecting as needed (though you shouldn't need to redirect again after the form has been submitted).

Feel free to post the rest of your code if you want me to take a look at what else is going on.

SharkofMirkwood
  • 11,483
  • 2
  • 17
  • 25