The following code contain some errors which im unable to locate. The problem is.....Im doing search and update. Im able to search the database and update Animal_Type and Animal_Breed BUT cannot update Premium_Habitat and Age......
Can some one locate that fatal error please
Thanks
<?php
include("svrconfig.php");
$svr_connect = mysql_connect("localhost","root","magicpass");
if(!$svr_connect)
{
die("Could not connect to server: ". mysql_error());
}
else
{
echo "Connected to server...<br/>";
$db_connect = mysql_select_db("test_update", $svr_connect);
if(!$db_connect)
{
die("Could not locate table: ". mysql_error());
}
else
{
echo "Connected to table: \"$table\"<br/><br/>";
}
}
if(!isset($pet_code))
{
echo "Opps! No match found!<br/>";
}
$pet_code = $_POST['Pet_Code'];
if(isset($pet_code) && $pet_code != '')
{
echo "You are UPDATING $pet_code.<br/>";
}
else
{
echo"No PET CODE entered...<br/>";
die("<a href = \"pet_search.php\"> <strong>GO BACK</strong>");
}
//write search query
$search = "SELECT * FROM $table WHERE Pet_Code = '$pet_code'";
$result = mysql_query($search);
$num = mysql_num_rows($result);
mysql_close($svr_connect);
//--------------------------------------------------------------------------------------------------------------------------------------------//
$i = 0;
while($i < $num)
{
$pet_code = mysql_result($result,$i,"Pet_Code");
$a_type = mysql_result($result,$i,"Animal_Type");
$a_breed = mysql_result($result,$i,"Animal_Breed");
$p_habitat = mysql_result($result,$i,"Premium_Habitat");
$a_age = mysql_result($result,$i,"Age");
echo "<form action = 'update.php' method = 'post'>
<h3> $pet_code </h3>
<input type='hidden' name='Pet_Code' value='$pet_code'>
Animal Type: <br/> <input type = 'text' maxlength = '20' name = 'ud_a_type' value = '$a_type'><br/><br/>
Animal Breed: <br/><input type = 'text' maxlength = '30' name = 'ud_a_breed' value = '$a_breed'><br/><br/>
Premium Habitat: <br/><input type = 'text' maxlength = '30' name = 'ud_p_habitat' value = '$p_habitat'><br/><br/>
Animal Age <input type = 'text' name = 'ud_age' value = '$a_age' >
<input type = 'submit' value = 'UPDATE PETS'></forms>";
$i++;
}
@$ud_a_type = $_POST['ud_a_type'];
@$ud_a_breed = $_POST['ud_a_breed'];
@$ud_p_habitat = $_POST['ud_b_habitat'];
@$ud_age = $_POST['ud_age'];
include("svrconfig.php");
$svr_connect = mysql_connect("localhost","root","magicpass");// I assigned my password
$db_connect = mysql_select_db("test_update", $svr_connect);
$update_query = "UPDATE pets SET Animal_Type = '$ud_a_type', Animal_Breed = '$ud_a_breed', Premium_Habitat = '$ud_p_habitat', Age = 'ud_age' WHERE Pet_Code = '$pet_code'";
mysql_query($update_query);
mysql_close($svr_connect);
?>