Solved

mysql / php form works on internet but not on intranet

Posted on 2011-09-18
3
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

695 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