Jump to content

Undefined index


june_c21

Recommended Posts

i encounter this problem when i trying to run the php scripts. what's wrong?

 

for($i=1;$i<9;$i++)

  {

  $eq_id[$i] = $i;

  $var1 = $i . "equipment";

$equipment[$i] = $_POST[$var1];

  $var2 = $i . "viscosity";

  $viscosity[$i] = $_POST[$var2];

  $var3 =  $i . "water";

  $water[$i]  = $_POST[$var3];

  $var4 =  $i . "tan";

  $tan[$i]    = $_POST[$var4];

  $var5 =  $i . "oil";

  $oil[$i]    = $_POST[$var5];

  $var6 =  $i . "wear";

  $wear[$i]    = $_POST[$var6];

  $var7 =  $i . "remarks";

  $remarks[$i]  = $_POST[$var7];

  }

 

the red one is the error

Link to comment
Share on other sites

Try the following code instead, don't need to use $i for the array indexes :-o (it automatically indexes if you use just empty brackets, like so)

for($i=1;$i<9;$i++)
  {
  $eq_id[] = $i;
  $equipment[] = $_POST[$i."equipment"];
  $viscosity[] = $_POST[$i."viscosity"];
  $water[] = $_POST[$i."water"];
  $tan[] = $_POST[$i."tan"];
  $oil[] = $_POST[$i."oil"];
  $wear[] = $_POST[$i."wear"];
  $remarks[] = $_POST[$i."remarks"];
  }

Link to comment
Share on other sites

Try the following code instead, don't need to use $i for the array indexes :-o (it automatically indexes if you use just empty brackets, like so)

There is a purpose to defining an index, if you are to resort the array you can resort by your defined indexing (as it will carry the indexes with the new sort)

Link to comment
Share on other sites

still having the same problem

 

Notice Undefined index: 1viscosity in C:\Web\lubrication1\add_phase2.php on line 15

 

Notice: Undefined index: 1water in C:\Web\lubrication1\add_phase2.php on line 16

 

Notice: Undefined index: 1tan in C:\Web\lubrication1\add_phase2.php on line 17

 

Notice: Undefined index: 1oil in C:\Web\lubrication1\add_phase2.php on line 18

 

Notice: Undefined index: 1wear in C:\Web\lubrication1\add_phase2.php on line 19

 

Notice: Undefined index: 1remarks in C:\Web\lubrication1\add_phase2.php on line 20

 

 

Link to comment
Share on other sites

still having the same problem

 

Notice Undefined index: 1viscosity in C:\Web\lubrication1\add_phase2.php on line 15

 

Notice: Undefined index: 1water in C:\Web\lubrication1\add_phase2.php on line 16

 

Notice: Undefined index: 1tan in C:\Web\lubrication1\add_phase2.php on line 17

 

Notice: Undefined index: 1oil in C:\Web\lubrication1\add_phase2.php on line 18

 

Notice: Undefined index: 1wear in C:\Web\lubrication1\add_phase2.php on line 19

 

Notice: Undefined index: 1remarks in C:\Web\lubrication1\add_phase2.php on line 20

 

 

 

Ok, those are the post variables. Where are you getting the post variables from, cause I'm a bit scared of a form that submits well over 50 variables through the post method at once xD

Link to comment
Share on other sites

<?php

 

$host = 'localhost';

$user = 'root';

$password = 'admin';

$dbase = 'oil';

 

$dblink = mysql_connect($host,$user,$password);

mysql_select_db($dbase,$dblink);

 

echo "<form id=form1 name=form1 method=post action=add_phase2.php>";

echo "<table border=3 align=center width=80%>";

echo "<tr><td width=16% align=center><span class=style5>Equipment </td></span><td width=12% align=center><span class=style5>Viscosity</td></span><td width=12% align=center><span class=style5>Water Content</td></span><td width=12% align=center><span class=style5>TAN</td></span><td width=12% align=center><span class=style5>Oil Cleanliness</td></span><td width=12% align=center><span class=style5>Wear</td></span><td align=center><span class=style5>Remarks</td></span></tr>";

 

$query = "SELECT eq_id, equipment FROM equipment WHERE gf='2' " ;

$result = mysql_query($query, $dblink);

while($myrow = mysql_fetch_row($result))

{

echo "<tr><td><span class=style2>" . $myrow[1] . "</span></td>";

echo "<td><div align=center><input name=" . $myrow[0] . "viscosity type=text size=1 /></div></td>";

echo "<td><div align=center><input name=" . $myrow[0] . "water type=text size=1 /></div></td>";

echo "<td><div align=center><input name=" . $myrow[0] . "tan type=text size=1 /></div></td>";

echo "<td><div align=center><input name=" . $myrow[0] . "oil type=text size=1 /></div></td>";

echo "<td><div align=center><input name=" . $myrow[0] . "wear type=text size=1 /></div></td>";

echo "<td><textarea name=" . $myrow[0] . "remarks cols=20 id=remarks></textarea></td></tr>";

 

 

}

 

echo "<div align=center><span class = style6>Phase 2</span></div>";

echo "<br>";

echo "<div align=center><input type=submit name=Submit value=Submit /></div>";

echo " <span class=style2> Month <input name=month type=text id=month size=8/></span>";

 

echo "</table>";

echo "</form>";

Link to comment
Share on other sites

if your lost then don't try and help, you will need to show what these outputs, also if you are pulling dynamic fields off a database with dynamic names (not exactly ideal) then you will need to consider this in the process page

 

No, I said I'm lost on what the outputs of those variables are supposed to be. And as far as dynamic content, I agree... I mean, you don't know exactly how many rows you'd be returning (unless it was index, unique) or there was a LIMIT attached to the end, etc... or of course, you use mysql_num_rows for that matter.

Link to comment
Share on other sites

Notice Undefined index: 1viscosity in C:\Web\lubrication1\add_phase2.php on line 15

 

You can translate this as "POST variable 1viscosity was not sent to the script"

 

Note that that's only accurate for your script, it's not a general translation for "undefined index".  So you need to work out why it's not sent.  The best way to work that out is to look at the generated form, which is what the others are asking for.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.