Solved

mysql / php form works on internet but not on intranet

Posted on 2011-09-18
3
367 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now