I am just starting out with PHP, and I am trying to make a way for a client to be able to change an image using radio buttons and form submission. My intention is for one of 2 image files (Open/Closed.jpg) to be copied and renamed to another location (images/status/Status.jpg) so that coding isn't needed to make the change.
The "new" image will then be used elsewhere. I have tried various copy() and rename() calls, but with no luck. Below is the code I am working with. I feel my problem lies with the submit call, but all things I have tried have not worked. So I am back to my original code (below) trying for a fresher start with help from seasoned users/programmers.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="">
<meta name="keywords" content="">
<title></title>
<link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<?php
// define variables and set to empty values
$WinterStatusErr = "";
$WinterStatus = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["WinterStatus"]))
{$WinterStatusErr = "Status is required";}
else
{$WinterStatus = test_input($_POST["WinterStatus"]);}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<p><span class="error"><font color="red"><b>* required selection</b></font></span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="radio" name="WinterStatus" <?php if (isset($WinterStatus) && $WinterStatus=="open") echo "checked";?> value="Open">Open
<input type="radio" name="WinterStatus" <?php if (isset($WinterStatus) && $WinterStatus=="closed") echo "checked";?> value="Closed">Closed
<span class="error"><font color="red"><b>* <?php echo $WinterStatusErr;?></b></font></span>
<br><br>
<input type="submit" name="submit" value="Submit" <?php
if ($Winterstatus == "Open")
{ copy ("images/Open.jpg", "images/status/Status.jpg"); }
elseif ($Winterstatus == "Closed")
{ copy ("images/Closed.jpg", "images/status/Status.jpg");}
?>>
</form>
<?php echo $WinterStatus ?>
</body>