Forum Moderators: coopster
View the source after first requesting this form to see what your <input> element looks like. If it shows
<input type="text" name="">then $usage has not yet been populated and actually you should be getting an error, that's if you have error_reporting() [php.net] turned on in your development mode here.
help!
Regards
Swati
this stuff is inside a while loop : while($row = @mysql_fetch_array($sql))
and just before it $k =0;
and this text box is inside a form with method="get"
<html><head><title>Sample</title></head><body>
<h1>Sample</h1>
<form action="<?php print $_SERVER['PHP_SELF'];?>" method="get">
<fieldset>
<legend>Sample</legend>
<?php
$k =0;
// Don't know what total is, so I set it to 50
$total = 50;
// Just used a for loop for demonstration purposes:
for ($i = 0; $i < 10; $i++) {
$usage = "usage".$k;
$k++;
?>
<input type="text" size="4" name="<?php echo $usage;?>" maxlength="3"
<?php
}
?>
<br /><br />
<input type="submit" name="Submit" value="Submit" />
</fieldset>
</form>
<fieldset>
<legend>Posted Form Values<legend/>
<?php
if (isset($_GET)) {
print '<pre>';
print_r($_GET);
print '</pre>';
// or perhaps a foreach loop:
print '<pre>';
foreach ($_GET as $name => $value) {
print "$name: $value\n";
}
print '</pre>';
}
?>
</fieldset>
</body></html>
while loop starts
{
?>
<tr>
<td class=resourceName>
<?php echo($row['name']);?></td>
<td class=dayNamesStyle>
<table width=75%>
<tr>
<td>
<?php
$sql = @mysql_query("select idTest_Equipment from Test_Equipment where name = '".$row['name']."'");
while($srow = @mysql_fetch_array($sql)){
$idvar = $srow['idTest_Equipment'];
}
$sql1 = @mysql_query("select Project_idProject from Assignment where
Test_Equipment_idTest_Equipment =
'".$idvar."' and monthYear = '".$pass_month[1]."'");
while($prow = @mysql_fetch_array($sql1)){
$idpro = $prow['Project_idProject'];
$sql2 = @mysql_query("select name from Project where idProject = '".$idpro."'");
while($qrow = @mysql_fetch_array($sql2)){
echo($qrow['name']); echo '<br />';
}
}
?><br />
</td>
</tr></table>
</td>
<td class=resourceName>
<form name="myForm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
<input type="hidden" name="site" value="<?php echo $site;?>">
<input type="hidden" name="monthYear" value="<?php echo $HTTP_GET_VARS['monthYear'];?>">
<table>
<tr>
<td class=resourceName>Project:</td>
<td class=resourceName>Usage :(%)</td>
</tr>
<tr><td class=resourceName><?php
$project = "project".$k; #$k++;?>
<select name="<?php echo $project;?>">
<option>select</option>
<option>3G LPM</option>
<option>ZM-FF</option>
<option>Vanquish</option>
</select></td>
<td class=resourceName>
<?php
if($_GET['usage'])
{
$sql4 = @mysql_query("select usage_Per_Month from Assignment where
Test_Equipment_idTest_Equipment = '".$idvar."' and
monthYear = '".$_GET['pass_month'][0]."'");
$total = 0;
while($check = @mysql_fetch_array($sql4)){
$total += $check['usage_Per_Month'];
}
$total += $_GET['usage'];
}
$usage = "usage".$k;
$k++;?>
<input type="text" size="4" name="<?php echo $usage;?>" maxlength="3" <?php if($total>100){?>
onBlur="alert('usage exceeds 100%, select another value.');return true" <?php }?>
onKeyUp="changeVal(this);" onChange="this.form.submit()">
<?php
if($_GET['usage'])
{
$sql_in = @mysql_query("insert into
Assignment(idAssignment, Project_idProject,
date_Of_Assignment,
monthYear,
usage_Per_Month,
Test_Equipment_idTest_Equipment)
VALUES('',
'".$idpro."', curdate(),
'".$pass_month[1]."',
'".$_GET['usage']."', '".$idvar."')") or die(mysql_error());
}
?>
</td></tr></table>
</form>
<?php
if (isset($_GET)){
print_r($_GET);
foreach ($_GET as $name => $value) {
print "$name: $value\n";
}
print '</pre>';
}
?></td>
<?php }?>
please ignore the opening closing of tr, td tags cos i have tried to shorten the code for you n there are far too many nested table sin my page (rest assured there is no error in the markup!)
help!
($_GET['usage']) You'd need to check each variable. Using the sample test code above, I changed the foreach to:
foreach ($_GET as $name => $value) {
if (strpos($name,'usage')===FALSE){
print "Not the right variable\n";
} else{
if ($value <> ''){
print "$name: $value\n";
} else {
print "$name: empty\n";
}
}
} baze