Help: Undefined index

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Help: Undefined index

Post by raghavan20 »

I am developing a website for my company and I have a few forms in there.

The php file works well when I use with another hosting site with Linux OS but it does give a few problems when I use with my company's hosting server running on Windows server.
<body>
<table width="700" class = 'bordersOnly' cellspacing="0" style="margin-top:10px; background-color:#000099; color:#FFFFFF">
<tr style="background-color:#999999; "><td></td><td class="Lalign"><h4>Omnisoft - Request Quote</h4></td></tr>
<tr><td><?php //echo $msg; ?></td></tr>
<form name="frmRequestQuote" method="get" action="" onsubmit="javascript:return validateForm(this)">
<tr><td>&nbsp;&nbsp;Name:</td><td class="Lalign"><input type = "text" name="txtName" value="<? echo $_GET['txtName']; ?>" size="60" /></td></tr>
<tr><td>&nbsp;&nbsp;Position:</td><td class="Lalign"><input type = "text" name="txtPosition" value="<? echo $_GET['txtPosition']; ?>" size="60" /></td></tr>
<tr><td>&nbsp;&nbsp;Company:</td><td class="Lalign"><input type = "text" name="txtCompany" value="<? echo $_GET['txtCompany']; ?>" size="60" /></td></tr>
<tr><td>&nbsp;&nbsp;Telephone:</td><td class="Lalign"><input type = "text" name="txtTelephone" value="<? echo $_GET['txtTelephone']; ?>" size="60" /></td></tr>
<tr><td>&nbsp;&nbsp;Email Address:</td><td class="Lalign"><input type = "text" name="txtEmail" value="<? echo $_GET['txtEmail']; ?>" size="60" /></td></tr>
<tr><td>&nbsp;&nbsp;Subject:</td>
<td class="Lalign"> <input name="txtSubject" type="text" value="<? echo $_GET['txtSubject']; ?>" checked="checked" size="60" /></td>
</tr>
<tr>
<td>&nbsp;&nbsp;Comments:</td>
<td>
<textarea name="txtComments" cols="50" rows="10"><? echo $_GET['txtComments']; ?></textarea>
</td></tr>
<tr><td></td><td><input type="submit" name="subRequestQuote" value="Request Quote" <? echo $disableStatus; ?> /></td></tr>
</form>
</table>

</body>
</html>

<?php

if ($_GET["subRequestQuote"] == "Request Quote"){
//get the fields from the form
$name = $_GET["txtName"];
$position = $_GET["txtPosition"];
$company = $_GET["txtCompany"];
$telephone = $_GET["txtTelephone"];
$email = $_GET["txtEmail"];
$subject = $_GET["txtSubject"];
$comments = $_GET["txtComments"];

//form the query
$fields = "(Name, Position, Company, Phone, Email, Subject, Comments, `Time`, IpAddress)";
$query = "insert into RequestQuote_tbl $fields values('$name', '$position', '$company', '$telephone', '$email', '$subject', '$comments', '". date("D d.m.Y G:i:s") ."','{$_SERVER['REMOTE_ADDR']}')";
//echo $query;
$result = mysql_query($query);
if ($result){
$msg = "<h4 class = 'Calign'>Your details have been recorded and we will call you to discuss about the quote!!!</h4>";
echo $msg;
$disableStatus = "disabled";
}
}
?>


You can visit two pages to see the difference
http://raghavan.allhyper.com/contact.html
http://www.omnisoft.co.uk/contact.html
click any of the links 'call me back' or 'request info' and scroll down the popped window to see the error message.
Last edited by raghavan20 on Tue Jul 12, 2005 12:05 am, edited 1 time in total.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Notice: Undefined index: txtComments in E:\Hosted_Web\LocalUser\omnisoftcouk\website\callMeBack.php on line 109
You could change code like

Code: Select all

if (!isset($_GET['txtComments']) $_GET['txtComments'] = '';
4a6f96]] on line 109
[/quote]

You could change code like

Code: Select all

if (!isset($_GET['txtComments']) $_GET['txtComments'] = '';
= '';
ts in E:\Hosted_Web\LocalUser\omnisoftcouk\website\callMeBack.php on line 109
[/quote]

You could change code like

Code: Select all

if (!isset($_GET['txtCo
[b]Notice[/b]:  Undefined index:  txtComments in [b]E:\Hosted_Web\LocalUser\omnisoftcouk\website\callMeBack.php[/b] on line [b]109[/b]
[/quote]

You could change code like

Code: Select all

if (!isset($_GET['txtComments']) $_GET['txtComments'] = '';
\website\callMeBack.php[/b] on line 109
[/quote]

You could change code like

Code: Select all

if (!isset($_GET['txtComments']) $_GET['txtComments'] = '';
d5ac4a6f96]

You could change code like

Code: Select all

if (!isset($_GET&#1111;'txtComments']) $_GET['txtCommeoftcouk\website\callMeBack.php[/b] on line [b]109[/b]
[/quote]

You could change code like

Code: Select all

if (!isset($_GET&#1111;'txtComments']) $_GET&#1111;'txtComments'] = '';
uk\website\callMeBack.php[/b] on line 109
[/quote]

You could change code like

Code: Select all

if (!isset($_GET['txtComments']) $_GET['txtComments'] = '';
ed_Web\LocalUser\omnisoftcouk\website\callMeBack.php[/b] on line 109
[/quote]

You could change code like

Code: Select all

if (!isset($_GET['txtComments']) $_GET['txtComments'] = '';
fined index: txtComments in E:\Hosted_Web\LocalUser\omnisoftcouk\website\callMeBack.php on line 109
[/quote]

You could change code like

Code: Select all

if (!isset($_GET['txtComments']) $_GET['txtComments'] = '';
] on line 109
[/quote]

You could change code like

Code: Select all

if (!isset($_GET['txtComments']) $_GET[
if (!isset($_GET['txtComments']) $_GET['txtComments'] = '';
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

if you had noticed more, you would have found that it gives error wherever there is $_GET statement. Is it a incompatibility btw PHP versions? cos I dont see any syntax problems with the code as it works fine with the other hosting server
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Prepend the following to all your scripts:

Code: Select all

ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);
Just read your php.ini and fine the settings ;)

On development/test servers i choose to show errors
On production servers i choose not to show errorsyour php.ini and fine the settings ;)

On development/test servers i choose to show errors
On production servers i choose not to show errorsing', E_ALL);
ini_set('display_errors', TRUE);


Just read your php.ini and fine the settings ;)

On development/test servers i choose to show errors
On production servers i choose not to show errorsing to all your scripts:

Code: Select all

ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);
Just read your php.ini and fine the settings ;)

On development/test servers i choose to show errors
On production servers i choose not to show errors]

Just read your php.ini and fine the settings ;)

On development/test servers i choose to show errors
On production servers i choose not to show errorsrvers i choose to show errors
On production servers i choose not to show errors

Just read your php.ini and fine the settings ;)

On development/test servers i choose to show errors
On production servers i choose not to show errors]

Just read your php.ini and fine the settings ;)

On development/test servers i choose to show errors
On production servers i choose not to show errorsplay_errors', TRUE);


Just read your php.ini and fine the settings ;)

On development/test servers i choose to show errors
On production servers i choose not to show errors
ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);


Just read your php.ini and fine the settings ;)

On development/test servers i choose to show errors
On production servers i choose not to show errors
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

timvw wrote:On development/test servers i choose to show errors
On production servers i choose not to show errors
I always show errors E_ALL when devloping too... it's good practise. But I thought in production you can just save the errors to a log file without outputting them to the user rather than disable all together? Maybe I'm wrong.

PS: How come in FF whenever I hit the single quote key is the "search page text" bar appearing at the bottom :?
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

If you had carefully examined the line numbers where errors throw up are places where it has $_GET or $_POST.

The hosting machine runs on PHP 4. Do you think there is a difference between PHP 4 and PHP 5?
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Solved

Post by raghavan20 »

Its been configured in the php.ini file to show notices. So if I include this line it stops notices from getting displayed.

error_reporting(E_ALL ^ E_NOTICE);
Post Reply