Let me open this post by saying YIKES!!! I started out just noting some of the minor problems as I went further in I found one problem lead to another which lead to another and in most case the later problems solution dictated that some previously suggested fixes were unnecessary as that segment of code could be removed entirely. Which lead to me ultimately just posting the entire solution and noting the other problems that were removed.
First $newvalue is string in your code but you are referring to it as an array in your update query. The fix I proposed removes the need for it.
Second, you are using the $GET superglobal but your form "method" is "post" you should be using the $POST superglobal.
Third, your going to have troubles using "$row[$i]" inside the while loop that retrieves the names of the columns. As the "$i" is the value for incrementing forward the columns not the rows.
Now I can't tell if you are retrieving multiple rows but if you are and you need to change the value of all the columns in it you need to wrap the column while loop in a while loop for each row.
$r = 0;
while ($r <= count($row)) {
$i = 1;
$color = 0;
while ($i <= mysql_num_fields($varsquery)) {
$meta = mysql_fetch_field($varsquery, $i);
// ....
}
$r++;
}
Fourth, if that is the case your are going to have trouble with the keys in your $POST array as you are using the column names for the key and all the values assigned to the second row would override the first row when you posted and third row would override the second ect. So if you have 4 row of data only the 4th rows values would be found in the $POST array.
To resolve the problem we just need to append the $r (from above while loop) to the end of the $meta->name.
Fifth your update query will needs to be like so.
if ($edit) {
$sql = mysql_query("UPDATE vars SET `" . $meta->name . "`= '" . $_POST[$meta->name . $r]] . "' WHERE id='2'");
}
}
And for that to work you would need to have it in your column "while" loop so that $meta->name references the correct column
Lastly as I could spend hundreds of lines more explaining all the little changes that were need, here is the entire segment of code with all the changes.
<?php
include_once('../inc/admin.php');
include_once('../inc/connect.php');
?>
<html>
<head>
<title>Variables</title>
<style>
a:link{
text-decoration: none;
color: #519904;
}
a:visited{
text-decoration: none;
color: #519904;
}
a:hover{
text-decoration: none;
color: #4296ce;
}
#border{
border-right-style: solid;
border-bottom-style: solid;
border-width: 1px;
}
</style>
</head>
<body>
<div style='font-size: 28px; text-align: center;'>Variables</div><br />
<table align='center'>
<tr>
<th bgcolor='#cccccc'><a href='changevars.php?sort=number'>#</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=variable'>Variable</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=value'>Value</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=rate'>Rate</a></th>
<th bgcolor='#cccccc'><a href='changevars.php'>Change</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=default'>Default</a></th>
</tr><form action='changevars.php' method='POST'>";
<?php
$varsquery = mysql_query("SELECT * FROM vars WHERE id='2'");
$row = mysql_fetch_array($varsquery);
$varsquery1 = mysql_query("SELECT * FROM vars WHERE id='1'");
$row1 = mysql_fetch_array($varsquery1);
$r = 0;
while ($r <= count($row)) {
$i = 1;
$color = 0;
while ($i <= mysql_num_fields($varsquery)) {
$meta = mysql_fetch_field($varsquery, $i);
if (!$meta) {
echo "No information available<br />\n";
}
else {
if ($color % 2){
$bgcolor = "#cccccc";
}
else{
$bgcolor = "#ffffff";
}
echo "<tr bgcolor='$bgcolor'><td align='center' width='20' bgcolor='#eeeeee' id='border'>$i</td>";
echo "<td align='center' width='200' id='border'>" . $meta->name . "</td>";
echo "<td align='center' width='200' id='border'>" .$row[$r]. "</td>";
echo "<td align='center' width='100' id='border'>0</td>";
echo "<td align='center' width='200' id='border'><input type='text' name='" . $meta->name . $r "'></td>";
echo "<td align='center' width='200' id='border' bgcolor='#77ff77'>" .$row1[$r]. "</td>";
echo "</tr>";
$i++;
$color++;
if ($_POST['edit']) {
$sql = mysql_query("UPDATE vars SET `" . $meta->name . "`= '" . $_POST[$meta->name . $r]] . "' WHERE id='2'");
}
}
}
$r++;
}
?>
<tr><td colspan='6' align='center'><input type='submit' name='edit' value='Edit'> <input type='reset' name='reset' value='Reset'></td></tr></form>
</table>
</body>
</html>
NOTE: much of your code has been moved around. I did this as I need to be able to see all the parts in one view without scrolling as I was getting confuse fast on some of the compounding errors. Also there are some minor changes done more to fit my style or to make things more readable. Feel free to change thing back if you need to.
Hopefully all that works. I wouldn't be surprised if I missed something or even had a mistake in there so look everything over carefully.