Hi!
I am a total newbie who has just developed a db for storing infos about some machines.I have coded a program to display the details of a particular machine and update the details only if the submit button is pressed.I wonder why it is not getting updated,instead if i close without pressing the submit button;the record gets corrupted.I have been stuck with this problem for nearly 2 wks.Can anyone help me plsssssss?
Here's my code:
<html>
<head><TITLE>m2.php</TITLE>
<SCRIPT LANGUAGE="JavaScript">
redirTime = "5000";
redirURL = "thankyou.html";
function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); }
</script>
</head>
<body >
<form name="m2.php" method="GET">
<?
$reference=$_GET['ref'];
$db="mydb";
$link=mysql_connect("localhost","username","password") or die("couldn't connect to Mysql");
mysql_select_db($db) or die("Select Error:".mysql_error());
$query="SELECT * FROM machines where ref='$reference'";
$rt=mysql_query($query);
$nt=mysql_fetch_array($rt);
$id = $nt['id'];
print "<table class=internal>";
print "<tr><td class=internal><b class=intro3>Ref:</b></td>
<td><input type=text name=ref value=$nt[ref] size=10></td></tr>";
print "<tr><td class=internal><b class=intro3>IP:</b></td>
<td><input type=text name=IP value=$nt[IP] size=20></td></tr>";
print "<tr><td class=internal><b class=intro3>MAC:</b></td>
<td><input type=text name=MAC value=$nt[MAC] size=20></td></tr>";
print "<tr><td class=internal><b class=intro3>Name:</b></td>
<td><input type=text name=Name value=$nt[Name] size=20></td></tr>";
print "<tr><td class=internal><b class=intro3>Location:</b></td>
<td><input type=text name=Location value=$nt[Location] size=20></td></tr>";
print "<tr><td class=internal><b class=intro3>Authority:</b></td>
<td><input type=text name=Authority value=$nt[Authority] size=20></td></tr>";
print "<tr><td class=internal><b class=intro3>Operative:</b></td>
<td><input type=text name=Operative value=$nt[Operative] size=10></td></tr>";
print "<tr><td class=internal><b class=intro3>MachineType:</b></td>
<td><input type=text name=MachineType value=$nt[MachineType] size=20></td></tr>";
print "<tr><td class=internal><b class=intro3>Processor:</b></td>
<td><input type=text name=FreqProcessor value=$nt[FreqProcessor] size=20></td></tr>";
print "<tr><td class=internal><b class=intro3>Hard Disk:</b></td>
<td><input type=text name=HardDisk value=$nt[HardDisk] size=10></td></tr>";
print "<tr><td class=internal><b class=intro3>Memory:</b></td>
<td><input type=text name=Memory value=$nt[Memory] size=10></td></tr>";
print "<tr><td class=internal><b class=intro3>Operating System:</b></td>
<td><input type=text name=OS value=$nt[OS] size=20></td></tr>";
print "<tr><td class=internal><b class=intro3>Other Operating System:</b></td>
<td><input type=text name=OtherOS value=$nt[OtherOS] size=15></td></tr></table>";
print "<table><tr><td><input type=submit name=submit value=submit onclick=redirTimer()></td></tr></table>";
mysql_close($link);
if (isset($_GET['submit'])){
$db="mydb";
$link=mysql_connect("localhost","username","password") or die("couldn't connect to Mysql");
mysql_select_db($db) or die("Select Error:".mysql_error());
$query="SELECT * FROM machines where ref='$reference'";
$rt=mysql_query($query);
$nt=mysql_fetch_array($rt);
$id = $nt['id'];
$ref=$GET['ref'];
$ip=$GET['IP'];
$mac=$GET['MAC'];
$name=$GET['Name'];
$lo=$GET['Location'];
$aut=$GET['Authority'];
$op=$GET['Operative'];
$ma=$GET['MachineType'];
$pr=$GET['FreqProcessor'];
$hd=$GET['HardDisk'];
$mem=$GET['Memory'];
$os=$GET['OS'];
$oth=$_GET['OtherOS'];
$myref=$ref;
$myip=$ip;
$mymac=$mac;
$myname=$name;
$mylo=$lo;
$myaut=$aut;
$myop=$op;
$myma=$ma;
$mypr=$pr;
$myhd=$hd;
$mymem=$mem;
$myos=$os;
$myoth=$oth;
$test="update machines set IP='$myip',MAC='$mymac', Name='$myname',Location='$mylo', Authority='$myaut' , Operative='$myop' , MachineType='$myma', FreqProcessor='$mypr' , HardDisk='$myhd', Memory='$mymem' , OS='$myos' , OtherOS='$myoth' where ref = '$reference'";
$test1=mysql_query($test);
mysql_close($link);
}
?>
</form>
</body>
</html>
I realize that the loop following the statement isset(.. is not getting executed.Can anyone please point out my mistake.I even tried the following:
1.replaced the method=GET with method=PUT in the form declaration statement.
2.used isset($POST['submit']) instead of isset($GET['submit']) after declaring the method as PUT.
3.I have changed the registered globals to ON in .ini.
i use this method GET because I am using this single code for all my machines.the display is in a pop-up window.
Any help would be gratefully accepeted.
Thanks in advance,
mssmanian