Solved

mysql / php form works on internet but not on intranet

Posted on 2011-09-18
3
373 Views
Last Modified: 2012-08-14
I am continuing my attempt to port an established web site with mysql backend to an intranet site.  To date I have established the database and web site, with tables and data, on a stand-alone Windows 7/Wamp setup.

The intranet web site functions correctly.  I can access the database from phpmyadmin however, when I attempt to use the intranet form (php/html) to access the database I am getting an "Undefined index" error returned.

I have made several corrections based on the "Experts" feedback.  I now need some additional assistance


Specifics:

      Internet:      MySQL 5.0, PHP 5, Apache on Linux Server

      Intranet:      MySQL 5.0.7, PHP 5.3.5, Apache 2.2.17, on Windows 7


Error:

      Notice: Undefined index: eMail in C:\wamp\www\part\edit_pprq1.php on line 62

      Notice: Undefined index: Dateother1 in C:\wamp\www\part\edit_pprq1.php
                                 on line 216

      Notice: Use of undefined constant FirstAidTrainingOther -  
                                   assumed 'FirstAidTrainingOther' in
                                   C:\wamp\www\part\edit_pprq1.php on line 262

Code:

      62.      <p><font size="2" face="Arial">4.&nbsp; Occupation:<input        
                                            type="text" name="Occ" value="<?php echo $data2["Occ"]?>"
                                            size="30"> email:<input type="text" name="eMail" value="<?php
                                             echo $data2['eMail']?>" size="40"></font></p>

      216.      <td width="64"><input type="text" name="Dateother1" value="<?php
                                            echo $data2["Dateother1"]?>" size="8"></td>      

      262.      <p><font size="2" face="Arial">16. First Aid Training;     Red Cross
                                            Advance:<input type="checkbox" name="FirstAidTrainingRCA" <?
                                             php if ($data2['FirstAidTrainingRCA']=="ON"){echo "checked";}?
                                             >>&nbsp;&nbsp;&nbsp; CPR:<input type="checkbox"
                                             name="FirstAidTrainingCPR" <?php if       ($data2['FirstAidTrainingCPR']
                                              =="ON"){echo "checked";}?>>&nbsp;&nbsp;&nbsp; EMT:<input       
                             type="checkbox" name="FirstAidTrainingEMT" <?php if ($data2
                                            ['FirstAidTrainingEMT']=="ON"){echo "checked";}?
                                            >>&nbsp;&nbsp;&nbsp;Other:<input type="text"
                                               name="FirstAidTrainingOther" value="<?php echo $data2
                                             ['FirstAidTrainingOther']?>" size="20"></font></p>

0
Comment
Question by:dibrandt
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
acbxyz earned 500 total points
ID: 36557427
These first two are warnings, which tell you the used array items doesn't exist.
One option is to declare them before use
if (!isset($data2['Occ'])) $data2['Occ'] = '';
if (!isset($data2['Dateother1'])) $data2['Dateother1'] = '';

Open in new window

Another is to check everytime when used
<p><font size="2" face="Arial">4.&nbsp;
Occupation:<input type="text" name="Occ" value="<?php if (isset($data2['Occ'])) echo $data2["Occ"]; ?>" size="30">
email:<input type="text" name="eMail" value="<?php if (isset($data2['eMail'])) echo $data2['eMail']; ?>" size="40">
</font></p>

Open in new window


The third warning tells you, you used a constant instead of a string as Dave told you in #27309891 before, but it seems to be already fixed in your code. Please use code tags to avoid strange line feeds in this posting.
0
 

Author Comment

by:dibrandt
ID: 36557517
acbxyz,

Does "array items doesn't exist" mean that:

    1.  The field does not exist
or
     2. The field is empty

0
 
LVL 10

Expert Comment

by:acbxyz
ID: 36559588
Your first, if you assign null to an array field you won't get this error.
To check it, you can use array_key_exists(), while isset returns false if the value of a field is null.
http://php.net/manual/en/function.array-key-exists.php
Everythime, this function returns false you get an error if you want to use it.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question