Hello, I've got a page that I've created that allows me to change multiple values in a row in my database. These values are all stored in a single row. I have input boxes for every one of the columns in my row. If a box is filled in, that value will be updated for that column in the row. This sounds like all I have to do is an Update query for the row, but it's becoming more complicated. Take a look:
PHP Code:
<?php
include_once('../inc/admin.php'); include_once('../inc/connect.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);
$edit = $_GET['edit']; $newvalue = "";
echo " <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> ";
echo "<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'>";
$i = 1; $color = 0; while ($i < mysql_num_fields($varsquery)) { $meta = mysql_fetch_field($varsquery, $i); if (!$meta) { echo "No information available<br />\n"; } 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[$i]. "</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'></td>"; echo "<td align='center' width='200' id='border' bgcolor='#77ff77'>" .$row1[$i]. "</td>"; echo "</tr>"; $newvalue .= $_GET[$meta->name]; $i++; $color++; } echo "<tr><td colspan='6' align='center'><input type='submit' name='edit' value='Edit'> <input type='reset' name='reset' value='Reset'></td></tr></form>"; echo "</table>";
if ($edit){
// Update new value $sql = mysql_query("UPDATE vars SET `credits500`='$newvalue[0]' WHERE id='2'");
}
// Footer echo " </body> </html> ";
?>
|