june_c21 Posted November 7, 2007 Share Posted November 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 7, 2007 Share Posted November 7, 2007 first use the [ code] brackets, secondly you need to give us a line number and the exact error if u want help Quote Link to comment Share on other sites More sharing options...
june_c21 Posted November 7, 2007 Author Share Posted November 7, 2007 the red line is the error Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 7, 2007 Share Posted November 7, 2007 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"]; } Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 7, 2007 Share Posted November 7, 2007 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) Quote Link to comment Share on other sites More sharing options...
june_c21 Posted November 7, 2007 Author Share Posted November 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 7, 2007 Share Posted November 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 7, 2007 Share Posted November 7, 2007 lets see the form Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 7, 2007 Share Posted November 7, 2007 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 why is over 50 post variables an issue? Quote Link to comment Share on other sites More sharing options...
june_c21 Posted November 7, 2007 Author Share Posted November 7, 2007 <?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>"; Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 7, 2007 Share Posted November 7, 2007 Use [ code ] [ /code ] tags please. I'm lost on the following variables: $myrow[1] and $myrow[0], what are those variables supposed to give you? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 7, 2007 Share Posted November 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 7, 2007 Share Posted November 7, 2007 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. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 7, 2007 Share Posted November 7, 2007 the post names are transparent because they are transported you can do a foreach($_POST as $key => $value) and return those keys, and discovery all keys that match a regex with that textual suffex, and then use those, but that only complicates things Quote Link to comment Share on other sites More sharing options...
june_c21 Posted November 7, 2007 Author Share Posted November 7, 2007 this is how the form look like [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 7, 2007 Share Posted November 7, 2007 that ain't what we are talking about. The source code of the form inputs is what I am talking about. What is outputted to the browser, not the php as your raw php creates dynamic output. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 7, 2007 Share Posted November 7, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.