By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,347 Members | 1,389 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,347 IT Pros & Developers. It's quick & easy.

Mixture between html and php- UNIDENTIFIED INDEX

P: 36
Lo all,

Had me head wrecked the whole week with a really stupid problem that came down to me not reading something but now when im running the php file i have errors switched on and i have bout 15 unidentified index but the problem is that i have used the code
Expand|Select|Wrap|Line Numbers
  1. function addActual()
  2. {
  3. var myTab = document.getElementById('myTable2');
  4. var row=myTab.rows.length; var y=myTab.insertRow(row);
  5. var a=y.insertCell(0);
  6. var xx= document.createElement('input');
  7. xx.type="text";
  8. xx.name="Date[]";
  9. a.appendChild(xx);
  10. var b=y.insertCell(1);
  11. var xx= document.createElement('input');
  12. xx.type="text";
  13. xx.name="Staff[]";
  14. b.appendChild(xx);
  15. var c=y.insertCell(2);
  16. var xx= document.createElement('input');
  17. xx.type="text";
  18. xx.name="Wage[]";
  19. c.appendChild(xx); var d=y.insertCell(3);
  20. var xx= document.createElement('input');
  21. xx.type="text";
  22. xx.name="Hours[]";
  23. }
  24.  
to add a row of a table in my input form but i have alot of them and as you can see they start array lists. the code in me php to call these is

Expand|Select|Wrap|Line Numbers
  1. $Date = $_POST['Date[]']; 
  2. $Staff = $_POST['Staff[]'];
  3. $Wage = $_POST['Wage[]'];
  4. $Hours = $_POST['Hours[]'];
  5.  
I also think this is stopping my mysql select statement as i use

Expand|Select|Wrap|Line Numbers
  1. function getProjectDetails()
  2. {
  3.     global $ProjName;
  4.     $temp = mysql_query("SELECT   Float, Extension, Excusable, NonExcusable, Delays, Value, LiquidatedDamages, totalLiquidatedDamages 
  5.               FROM     ProjectDetails
  6.               WHERE    Name= $ProjName")or die('<hr />MySQL Error1: ' .mysql_error(). '<hr />'); 
  7.     $row = mysql_fetch_array($temp);
  8.     return $row;
  9. }
  10. // A function to allow overall project variables to be manipulated.
  11. function makeVariableProjectDetails()
  12. {
  13.     global $projectFloat, $projectExtension, $projectExcusable, $projectNonExcusable,
  14.         $projectDelays, $projectValue, $liquidateddamages, $totalliquidateddamages;
  15.     $temp = getProjectDetails();
  16.     $projectFloat = $temp['ProjectFloat'];
  17.     $projectExtension = $temp['Extension'];
  18.     $projectExcusable = $temp['Excusable'];
  19.     $projectNonExcusable = $temp['NonExcusable'];
  20.     $projectDelays = $temp['Delays'];
  21.     $projectValue = $temp['Value'];
  22.     $liquidateddamages = $temp['LiquidatedDamages'];
  23.     $totalliquidateddamages = $temp['totalLiquidatedDamages'];
  24. }
  25.  
where the error message

MySQL Error1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Float, Extension, Excusable, NonExcusable, Delays, Value, Liquid

comes. So is this connected and any1 ideas... im bout 99% positive me sql query is sound and i had ProjName in input form added so it wasnt that?
Oct 9 '08 #1
Share this Question
Share on Google+
14 Replies


Dormilich
Expert Mod 5K+
P: 8,639
if $ProjName is a string, you should enclose it in single quotation marks.

regards
Oct 9 '08 #2

P: 36
sound one that solved the mysql problem... still have to figure the
Undefined index: EmailFrom[] in /home/moneill/public_html/mainPHP.php on line 37

which are me arrays..
Oct 9 '08 #3

Markus
Expert 5K+
P: 6,050
sound one that solved the mysql problem... still have to figure the
Undefined index: EmailFrom[] in /home/moneill/public_html/mainPHP.php on line 37

which are me arrays..
Post the code concerning your arrays. I currently can't find them in your given code.
Oct 9 '08 #4

P: 36
lo markus

just got in from work there the code im using in the html file is basically having

header 1 h2 h3 h4 h5 etc |BUTTON|

There is zero input boxes below this so when you first press button javascript kicks in with the code

Expand|Select|Wrap|Line Numbers
  1. function addActual() 
  2. var myTab = document.getElementById('myTable2'); 
  3. var row=myTab.rows.length; var y=myTab.insertRow(row); 
  4.  
  5. var a=y.insertCell(0); 
  6. var xx= document.createElement('input'); 
  7. xx.type="text"; 
  8. xx.name="Date[]"; 
  9. a.appendChild(xx); 
  10.  
  11. var b=y.insertCell(1); 
  12. var xx= document.createElement('input'); 
  13. xx.type="text"; 
  14. xx.name="Staff[]"; 
  15. b.appendChild(xx);
  16.  
  17. var c=y.insertCell(2); 
  18. var xx= document.createElement('input'); 
  19. xx.type="text"; 
  20. xx.name="Wage[]"; 
  21. c.appendChild(xx);
  22.  
  23. var d=y.insertCell(3); 
  24. var xx= document.createElement('input'); 
  25. xx.type="text"; 
  26. xx.name="Hours[]"; 
  27.  
  28.  

I have a couple of these all adding rows to different tables and it updates them ok. The problem i am having is that the inputs that it creates doesnt appear to work in the php program as i get the error;

unidentified index

I am using $_POST to pass them from html to php by

Expand|Select|Wrap|Line Numbers
  1. $Date = $_POST['Date[]'];  
  2. $Staff = $_POST['Staff[]']; 
  3. $Wage = $_POST['Wage[]']; 
  4. $Hours = $_POST['Hours[]']; 
  5.  
It is only the variables that i pass to php using this format all the normal inputs are accepted but not these. The problem i am guessing it is is that the javascript is not being passed to php but i cant be sure ... have you any ideas on this.
Oct 9 '08 #5

Markus
Expert 5K+
P: 6,050
You're receive and undefined error, not unidentified.

When you pass an array to POST, you access it like an array.

Expand|Select|Wrap|Line Numbers
  1.  
  2. $Date = $_POST['date']
  3.  
  4.  
Oct 9 '08 #6

pbmods
Expert 5K+
P: 5,821
Heya, Micky.

When you name an input with '[]' at the end, it creates an array on the PHP side.

http://php.net/variables.external
Oct 10 '08 #7

P: 36
sound one guys in work now but having to work till 10pm gmt the night so uve helped me loads. its in for next friday an i cant work on it over the weekend.

THANKS.
Oct 10 '08 #8

P: 36
lol hey guys well ive done what u say and fair enuf it works but how do i separate the array i get into smaller parts.
I have tried the usual
for($i=1; $i<=count("theArray"); $i++) //"theArray" is generic

but this throws an undefined offset which is when the array part im accessing doesnt exist. I have also tried using

explode(",", "theArray")

but it throws array to string conversion...

because of this i get undefined offset within any for loop i use with these arrays.
Oct 10 '08 #9

pbmods
Expert 5K+
P: 5,821
For greater efficiency, consider using foreach. Putting count() in the for loop is a bit inefficient, as the array elements are count()'ed with each iteration.

http://blog.pbmods.com/2007/11/27/wh...lopers-part-1/
Oct 10 '08 #10

P: 36
LOL PBMods u hit the nail on the head there... im only outa uni (doing this for dissertation in construction management [yes a major change]) and all i learned was java, cobol, mysql and prolog so what ur saying is 100% but i have looked at foreach code and have not understood it. In ur explanation it is very clear tbh but what is $element, is this the $i or do i go for column headings?
Oct 10 '08 #11

pbmods
Expert 5K+
P: 5,821
This code:
Expand|Select|Wrap|Line Numbers
  1. foreach( $array as $index => $element )
  2. {
  3.   .
  4.   .
  5.   .
  6. }
  7.  
is roughly equivalent to this:

Expand|Select|Wrap|Line Numbers
  1. for( $index = 0; $index <= count($array); $index++ )
  2. {
  3.   $element = $array[$index];
  4.  
  5.   .
  6.   .
  7.   .
  8. }
  9.  
Except that foreach runs through EVERY element in the array, even if it has a non-numeric index.

http://php.net/foreach
Oct 10 '08 #12

P: 36
U learn something new every day... thanks for explaining it to me cus i know uve got the blog and probs explain everyday of the week but sound1. Ill pass this teaching on LOL. :D
Oct 10 '08 #13

P: 36
Hi guys ive been trying to use these foreach loops and was just looking clarification to find whetehr i am doing it rite.
Expand|Select|Wrap|Line Numbers
  1. //Email Variables
  2. $EmailFro = $_POST['EmailFrom'];
  3. $EmailT = $_POST['EmailTo'];
  4. $EmailDat = $_POST['EmailDate'];
  5. $EmailSubjec = $_POST['EmailSubject'];
  6. $EmailMessag = $_POST['EmailMessage'];
  7.  
  8. foreach ($EmailFro as $i => $temp) {
  9.   $EmailFrom[$i] = $temp;
  10. }
  11. foreach ($EmailT as $i => $temp) {
  12.   $EmailTo[$i] = $temp;
  13. foreach ($EmailDat as $i => $temp) {
  14.   $EmailDate[$i] = $temp;
  15. }
  16. foreach ($EmailSubjec as $i => $temp) {
  17.   $EmailSubject[$i] = $temp;
  18. }
  19. foreach ($EmailMessag as $i => $temp) {
  20.   $EmailMessage[$i] = $temp;
  21. }
  22.  
  23. // With the remaining foreach loops being
  24.  
  25. foreach ($Dat as $i => $temp) {
  26.   $Date[$i] = $temp;
  27. }
  28. foreach ($Staf as $i => $temp) {
  29.   $Staff[$i] = $temp;
  30. }
  31. foreach ($Wag as $i => $temp) {
  32.   $Wage[$i] = $temp;
  33. }
  34. foreach ($Hour as $i => $temp) {
  35.   $Hours[$i] = $temp;
  36. }
  37. foreach ($SubDat as $i => $temp) {
  38.   $SubDate[$i] = $temp;
  39. }
  40. foreach ($Sub as $i => $temp) {
  41.   $Subs[$i] = $temp;
  42. }
  43. foreach ($Pric as $i => $temp) {
  44.   $Price[$i] = $temp;
  45. }
  46. foreach ($Typ as $i => $temp) {
  47.   $Type[$i] = $temp;
  48. }
  49.  
  50.  
I get errors of

Warning: Invalid argument supplied for foreach() in /home/moneill/public_html/mainPHP.php on line 231

Notice: Undefined offset: 1 in /home/moneill/public_html/mainPHP.php on line 238

and the period of coding that this represents is

Expand|Select|Wrap|Line Numbers
  1. // A function to allow overall project variables to be manipulated.
  2. function makeVariableProjectDetails()
  3. {
  4.     global $ProjName, $projectFloat, $projectExtension, $projectExcusable, $projectNonExcusable,
  5.         $projectDelays, $projectValue, $liquidateddamages, $totalliquidateddamages;
  6.  
  7.     $temp = mysql_query("SELECT Name, ProjectFloat, Extension, Excusable, NonExcusable, Delays, Value, LiquidatedDamages, totalLiquidatedDamages 
  8.               FROM     ProjectDetails
  9.               WHERE    Name= '$ProjName'")or die('<hr />MySQL Error1: ' .mysql_error(). '<hr />');
  10.     $temp = mysql_fetch_array($temp); 
  11.     $projectFloat = $temp['ProjectFloat'];
  12.     $projectExtension = $temp['Extension'];
  13.     $projectExcusable = $temp['Excusable'];
  14.     $projectNonExcusable = $temp['NonExcusable'];
  15.     $projectDelays = $temp['Delays'];
  16.     $projectValue = $temp['Value'];
  17.     $liquidateddamages = $temp['LiquidatedDamages'];
  18.     $totalliquidateddamages = $temp['totalLiquidatedDamages'];
  19. }
  20.  
Where line 231 is $projectFloat ... and 238 is $liquidatedDamages?

The reason why I want to call a variable by for loop is that the 800 lines of code have a lot of for loops and the program, as well as 20000 words has to be in for wednesddday morning so im a bit caught for time. Any one any ideas of the problem?
Oct 13 '08 #14

pbmods
Expert 5K+
P: 5,821
Save your server some CPU cycles and just do:
Expand|Select|Wrap|Line Numbers
  1. $EmailFrom = $_POST['EmailFrom'];
  2. $EmailTo = $_POST['EmailTo'];
  3. $EmailDate = $_POST['EmailDate'];
  4. $EmailSubject = $_POST['EmailSubject'];
  5. $EmailMessage = $_POST['EmailMessage'];
  6.  
Its result is identical to that of the code that you posted.
Oct 16 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.