I'm setting up a database that right now has an id and then two fields, one of the fields I want to be constant. The second I'm trying to alter by using a drop down menu. When I make a choice in the drop down and hit submit it changes the attribute later in the document, but it seems like it regenerates the first part of the document as if it was using the old attribute.
<form name=input action=# method="post">
<?php
$link = @mysql_connect('localhost', 'root', 'password') or
die("Could not connect to MySQL");
$db = @mysql_select_db('temp1',$link) or
die("Could not select database");
$query = "SELECT * FROM table1";
$result = @mysql_query($query,$link) or
die("Could not submit query");
$numrows = @mysql_num_rows($result);
?>
<table valign=top>
<tr>
<td>Location</td>
<td>New Status</td>
<td>Status</td>
<td>Dropmenu</td>
<td>New Status</td>
<td>Status</td>
<td>New Status</td>
<td>Status</td>
</tr>
<?php
for ($i=0; $i<$numrows; $i++)
{
echo('<tr>');
$infov = mysql_fetch_array($result);
$newstatus=$infov[status];
echo('<td>');
echo("$infov[location]");
td();
echo("$newstatus");
td();
echo("$infov[status]");
td();
$newstatus=dropmenu($infov,$i);
td();
echo("$newstatus");
td();
echo("$infov[status]");
td();
if($infov[status]!=$newstatus)
{
$query = "UPDATE table1 SET status="."$newstatus"." WHERE id="."$infov[id]";
update($query);
}
//echo($query);
$infov[status]=$newstatus;
echo("$newstatus");
td();
echo("$infov[status]");
echo('</td>');
echo('</tr>');
}
//add new entry
?>
</table>
</form>
<?php
exit("bye");
?>
<?php
function dropmenu($vector,$int)
{
?>
<SELECT NAME="state<?php echo("$int")?>" SIZE="1">
<OPTION <?php s($vector,1) ?> VALUE="1">ACTIVE</OPTION>
<OPTION <?php s($vector,2) ?> VALUE="2">BROKEN</OPTION>
<OPTION <?php s($vector,3) ?> VALUE="3">PLANNED</OPTION>
<OPTION <?php s($vector,4) ?> VALUE="4">REMOVE</OPTION>
</SELECT>
<input type="submit" value="change"/>
<?php
return $_POST['state'."$int"];
}
?>
<?php
function s($vector,$int)
{
if($vector[status]==$int)
{
echo('selected');
}
}
function update($query)
{
if (@mysql_query($query))
{
//echo('update made');
}
else
{
echo('failure');
}
}
function td()
{
echo('</td>');
echo('<td>');
}
?>