Update rows in php

I don’t know if this is the correct way to do this but I created a link that reloads the page and puts the row number of a database table in the url so that I can insert the values inside a few drop down lists and text boxes. It does not want to show the values when I click on the link?


//I have the below code on top of the page
$rn=$_GET['rn'];

if ($rn < 0)
{
	$editSql1 = mysql_query("Select * FROM Hospital WHERE HospitalID = " . $rl);
	while($erow = mysql_fetch_array($editSql1))
	{
		$editStage = $erow['StageID'];
		$editState = $erow['StateID'];
		$editCity = $erow['CityID'];
		$editName = $erow['HospitalName'];
		$editCasualty = $erow['CasualtyTrauma'];
		$editAddress = $erow['Address'];
		$editContactP = $erow['ContactPerson'];
		$editContactNum = $erow['ContactNum'];
		$editEmergency = $erow['EmergencyNum'];
		$editBeds = $erow['NumBeds'];
		$editFacilities = $erow['Facilities'];
		$editDistance = $erow['DistanceCBD'];
		$editHelipad = $erow['Helipad'];
		$editGPS = $erow['GPS'];
	}
	
}

//This piece of code is the body section
<input name="HospitalName" type="text" id="HospitalName" <?php echo 'value="' . $editName . '"'; ?> width="90%" />


//This displays all rows in table
$DisplayData = mysql_query("SELECT Hospital.HospitalID, LkupStages.Stage, State.StateName, City.CityName, Hospital.HospitalName, LkupHospitalCasualty.HospitalCasualty, Hospital.NumBeds, Hospital.Facilities, Hospital.ContactPerson, Hospital.ContactNum, Hospital.EmergencyNum, Hospital.Address, Hospital.DistanceCBD, Hospital.GPS, LkupYesNo.YesNo FROM Hospital INNER JOIN LkupStages ON Hospital.StageID = LkupStages.StageID INNER JOIN State ON Hospital.StateID = State.SID INNER JOIN City ON Hospital.CityID = City.CID INNER JOIN LkupHospitalCasualty ON Hospital.CasualtyTrauma = LkupHospitalCasualty.HospitalCasualtyID INNER JOIN LkupYesNo ON Hospital.Helipad = LkupYesNo.YNID ORDER BY Hospital.HospitalID DESC");
		
		
		
		while($srow = mysql_fetch_array($DisplayData))
		{
			echo "<tr><td>" . $srow['Stage']. "</td>";
			echo "<td>" . $srow['StateName']. "</td>";
			echo "<td>" . $srow['CityName']. "</td>";
			echo "<td>" . $srow['HospitalName']. "</td>";
			echo "<td>" . $srow['HospitalCasualty']. "</td>";
			echo "<td>" . $srow['Address']. "</td>";
			echo "<td>" . $srow['ContactPerson']. "</td>";
			echo "<td>" . $srow['ContactNum']. "</td>";
			echo "<td>" . $srow['EmergencyNum']. "</td>";
			echo "<td>" . $srow['NumBeds']. "</td>";
			echo "<td>" . $srow['Facilities']. "</td>";
			echo "<td>" . $srow['DistanceCBD']. "</td>";
			echo "<td>" . $srow['Helipad']. "</td>";
			echo "<td>" . $srow['YesNo']. "</td>";
			echo "<td> <a href='Hospital.php?rn=".$srow['HospitalID']."'><span style='color:#F00'>Edit</span></a></td></tr>";
			
			
		}

First off I can see that you need to add some opening and closing PHP tags, particularly before the <input>.

I actually just took part of the code that I am having trouble with out. below I have added the opening and closing tags.


<?php
//I have the below code on top of the page
$rn=$_GET['rn'];

if ($rn < 0)
{
    $editSql1 = mysql_query("Select * FROM Hospital WHERE HospitalID = " . $rn);
    while($erow = mysql_fetch_array($editSql1))
    {
        $editStage = $erow['StageID'];
        $editState = $erow['StateID'];
        $editCity = $erow['CityID'];
        $editName = $erow['HospitalName'];
        $editCasualty = $erow['CasualtyTrauma'];
        $editAddress = $erow['Address'];
        $editContactP = $erow['ContactPerson'];
        $editContactNum = $erow['ContactNum'];
        $editEmergency = $erow['EmergencyNum'];
        $editBeds = $erow['NumBeds'];
        $editFacilities = $erow['Facilities'];
        $editDistance = $erow['DistanceCBD'];
        $editHelipad = $erow['Helipad'];
        $editGPS = $erow['GPS'];
    }

}
?>

<?php
//This piece of code is the body section ?>
<input name="HospitalName" type="text" id="HospitalName" <?php echo 'value="' . $editName . '"'; ?> width="90%" />

<?php
//This displays all rows in table
$DisplayData = mysql_query("SELECT Hospital.HospitalID, LkupStages.Stage, State.StateName, City.CityName, Hospital.HospitalName, LkupHospitalCasualty.HospitalCasualty, Hospital.NumBeds, Hospital.Facilities, Hospital.ContactPerson, Hospital.ContactNum, Hospital.EmergencyNum, Hospital.Address, Hospital.DistanceCBD, Hospital.GPS, LkupYesNo.YesNo FROM Hospital INNER JOIN LkupStages ON Hospital.StageID = LkupStages.StageID INNER JOIN State ON Hospital.StateID = State.SID INNER JOIN City ON Hospital.CityID = City.CID INNER JOIN LkupHospitalCasualty ON Hospital.CasualtyTrauma = LkupHospitalCasualty.HospitalCasualtyID INNER JOIN LkupYesNo ON Hospital.Helipad = LkupYesNo.YNID ORDER BY Hospital.HospitalID DESC");



        while($srow = mysql_fetch_array($DisplayData))
        {
            echo "<tr><td>" . $srow['Stage']. "</td>";
            echo "<td>" . $srow['StateName']. "</td>";
            echo "<td>" . $srow['CityName']. "</td>";
            echo "<td>" . $srow['HospitalName']. "</td>";
            echo "<td>" . $srow['HospitalCasualty']. "</td>";
            echo "<td>" . $srow['Address']. "</td>";
            echo "<td>" . $srow['ContactPerson']. "</td>";
            echo "<td>" . $srow['ContactNum']. "</td>";
            echo "<td>" . $srow['EmergencyNum']. "</td>";
            echo "<td>" . $srow['NumBeds']. "</td>";
            echo "<td>" . $srow['Facilities']. "</td>";
            echo "<td>" . $srow['DistanceCBD']. "</td>";
            echo "<td>" . $srow['Helipad']. "</td>";
            echo "<td>" . $srow['YesNo']. "</td>";
            echo "<td> <a href='Hospital.php?rn=".$srow['HospitalID']."'><span style='color:#F00'>Edit</span></a></td></tr>";


        }
?>

I have fixed the problem above but now I can’t seem to change the drop down lists to show the correct selected value.


<?Php
						echo 'State: '.$editState . '<br/>';
	$queryState = mysql_query("SELECT SID, StateName FROM State");
    echo "<select name='State' id='State' >";
	//echo '<option>Select State</option>';  
    while($row = mysql_fetch_array($queryState))  
	{
		if ($rn >= 0)
		{
			if ($editState = $row["SID"])
			{
				
				echo  '<option selected="selected" value="' . $row["SID"] . '">' . $row["StateName"] . '</option>';
				
			}
			
		}
		else
		{
			echo  '<option value="' . $row["SID"] . '">' . $row["StateName"] . '</option>';
		}
	}
    echo '</select>';
	
?>

$editState = $row[“SID”] should be $editState == $row[“SID”]