update knap på php hjemmeside virker ikke
Jeg har problmer med at få oprettet en update funktion. Jeg har ind til videre fået lavet to php filer. Men kan ikke få update funktionen til at fungere.hjælp:(
common_dd5.php
<?php
include("../adodb/adodb.inc.php");
define ("blank"," ");
function htmlheader($titel='') {
?>
<html>
<head>
<title><?php echo $titel; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="style1.css" type="text/css">
</head>
<body>
<?php
}
function updatearea($zip='',$town='')
{
if (($zip!="") && ($town!=""))
{
$conn = &ADONewConnection("mysql"); # create a connection
if (@$conn->Connect("localhost", "grouop08", "123456", "grouop08"))
{
$strsql = "update from area where zip='".$zip."' and town='".$town."'";
//echo $strsql."<br>";
$rs = &$conn->Execute($strsql);
}
}
}
function deletearea($zip='',$town='')
{
if (($zip!="") && ($town!=""))
{
$conn = &ADONewConnection("mysql"); # create a connection
if (@$conn->Connect("localhost", "grouop08", "123456", "grouop08"))
{
$strsql = "delete from area where zip='".$zip."' and town='".$town."'";
//echo $strsql."<br>";
$rs = &$conn->Execute($strsql);
}
}
}
function insertarea($zip='',$town='')
{
$conn = &ADONewConnection("mysql"); # create a connection
if (@$conn->Connect("localhost", "grouop08", "123456", "grouop08"))
{
$tablename = "area";
$zip = htmlspecialchars($zip);
$town = htmlspecialchars($town);
$strsql = "insert into $tablename values ('$zip','$town')";
//echo $strsql."<br>";
$rs = &$conn->Execute($strsql);
} else echo "ingen connection";
}
function post1($show,$zip,$town) {
echo "<form name='form1' method='post' action='".$php_self."'>";
?>
<table width="95%" border="0"> <tr> <td colspan="2"> <div class="storcenter" align="center">Zip and Town</div></td></tr>
<tr> <td width="27%">Zip</td><td width="73%"> <input type="text" name="zip" maxlength="10" value="<?php echo $zip;?>" size="10">
<tr> <td width="27%">Town</td><td width="73%"> <input type="text" name="town" maxlength="50" value="<?php echo $town;?>" size="50">
</td></tr> <tr> <td class="center" colspan="2">
<?php
if ($show=="show") {
$conn = &ADONewConnection("mysql"); # create a connection
if (@$conn->Connect("localhost", "grouop08", "123456", "grouop08"))
{
$strsql = "select zip, town from area";
$rs = &$conn->Execute($strsql);
echo "<select name='showzip'>";
while (!$rs->EOF) {
echo "<option value='".$rs->fields[0]." ".$rs->fields[1]."'>".$rs->fields[1]."</option>";
$rs->MoveNext();
}
echo "</select>";
echo "<input type='submit' name='button' value='To screen'>";
echo "<br/>";
}
}
?><input type="submit" name="button" value="insert">
<input type="reset" name="Reset" value="Reset">
<input type="submit" name="button" value="end">
<input type="submit" name="button" value="delete">
<input type="submit" name="button" value="show">
<input type="submit" name="button" value="update">
</td>
</tr> </table></form><?php
}
function htmlfooter() {
?>
</body>
</html>
<?php
}
function start1($post='',$show='notshow',$zip='',$town='')
{
htmlheader($post);
post1($show,$zip,$town);
htmlfooter();
}
?>
og
insertpost.php
<?php
include "../common/common_db5.php";
switch($_POST["button"]) {
case "insert":
insertarea($_POST["zip"],$_POST["town"]);
start1("Zip and Town","notshow");
break;
case "end":
//header("Location: http://localhost");
header("Location: ../admin/right.html");
break;
case "delete":
deletearea($_POST["zip"],$_POST["town"]);
start1("Zip and Town","notshow");
break;
case "update":
updatearea($_POST["zip"],$_POST["town"]);
start1("zip and Town","notshow");
case "show":
start1("Zip and Town","show");
break;
case "To screen":
$position = strpos($_POST["showzip"]," ");
$zipcode = substr($_POST["showzip"],0,$position);
$towncode=substr($_POST["showzip"],$position+1,strlen($_POST["showzip"]));
start1("Zip and Town","show",$zipcode,$towncode);
break;
default:
start1("Zip and Town","notshow");
}
?>
