I was wondering if a variable at the top of the page will still be available thru the whole script even thru loops and such. My problem is that I have a variable that works about 5 lines above in an if statement and then doesnt seem to work in an if statement right after.
<STYLE TYPE="text/css">
.step1{
border: 1px solid #000000;
border-collapse: collapse;
padding: 3px;
font: 8pt verdana, arial, sans-serif;
font-weight: bold;
}
.step2{
color: red;
border: 1px solid red;
border-collapse: collapse;
padding: 3px;
font: 8pt verdana, arial, sans-serif;
font-weight: bold;
}
.add{
color: red;
font: 8pt verdana, arial, sans-serif;
font-weight: bold;
}
</STYLE>
<?php
// Include connection and queries
include 'connect.php';
include 'queries.php';
// Setting vars
$cell = "class=step1";
$cell2 = "class=step2";
$bname = $_POST['bname'];
echo "<h1>Updating</h1>";
// Updating building
echo "<b>Building</b>";
echo "<form action=$self method=POST>";
echo "<table><tr><td $cell>Building</td><td $cell>$step1</td><td $cell><input type=submit name=sub1 value=Submit></td></tr>";
echo "</table>";
echo "</form>";
// Updating building 2
if ($_POST['sub1']){
$query = "SELECT id,name FROM building WHERE id = $bname";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
$name = $row['name'];
echo "<b>Change</b>";
echo "<form action=$self method=POST>";
echo "<table><tr><td $cell2>Name</td><td $cell2><input type=text name=changeb value=$name></td><td $cell2><input type=submit name=sub1a value=Submit></td></tr>";
echo "</table>";
echo "</form>";
}
}
// Updating building 3
if ($_POST['sub1a']){
$build = $_POST['changeb'];
$query = "UPDATE building SET name = $build WHERE id = $bname";
$result = mysql_query($query);
echo "$bname $build";
}
echo "<hr>";
// Updating room
echo "<b>Room </b>- select building first";
echo "<form action=$self method=POST>";
echo "<table><tr><td $cell>Building</td><td $cell>$step1</td><td $cell><input type=submit name=sub2 value=Submit></td></tr>";
echo "</table>";
echo "</form>";
if ($_POST['sub2']){
echo "hi";
}
echo "<hr>";
// Updating software
echo "<b>Software</b>";
echo "<form action=$self method=POST>";
echo "<table><tr><td $cell>Software</td><td $cell>$step3</td><td $cell><input type=submit name=sub3 value=Submit></td></tr>";
echo "</table>";
echo "</form>";
if ($_POST['sub3']){
echo "hi";
}
?>
On line 46:
$query = "SELECT id,name FROM building WHERE id = $bname";
$bname works, I can tell because when I select the building name from the drop down menu, it pulls the building name up in the input box for you to change it.
I then did a check with line 63 to see if it still has $bname available:
echo "$bname $build";
but it doesnt, $build gets printed but $bname does not. If I cant get $bname working then I cant set up a UPDATE query to change the building name. So I am trying to figure out why $bname doesnt work anymore.