I am new to php and I am stuck. I am trying to complete this script. Everything works except for the last piece I put in which is
if ( $str5 == $str6 ) {echo "$str4"};
what I need this if to do is is the photo 2 checkbox is selected create the Html tag which is $str4, but if it is not checked, do not create the tag.
this is the entire script:
<?
if (isset($_POST['submit']) && $_POST['submit']=="Submit" && !empty($_POST['name'])) {//if submit button clicked and name field is not empty
$name = $_POST['name']; //the entered name
$contenttags = " <?php require_once('indextags.php') ?> ";
$contenttop = " <?php require_once('indexheader.php') ?> ";
$contentbottom = " <?php require_once('indexfooter.php') ?> ";
$town = $_POST['town'];
$city = $_POST['city'];
$s4 = $_POST['stock'];
$tit4="<img src=\"http://www.somesite.com/test/";
$u4=_;
$my_number4=4;
$my_string4=".jpg\" width=\"500\" height=\"375\" border=\"0\"><br><br>";
$str4 = "$tit4$u4$my_number4$my_string4";
$str5 = $_POST['photo2'];
$str6 = 'test';
// Create the file:
$fileName = dirname(__FILE__)."/$name.php"; // names the file $name
$fh = fopen($fileName, 'w') or die("can't open file");
// The html code:
// this will outout: My name is (name) !
$str = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<title>" .$name. "</title>
" .$contenttags. "
</head>
<body>
" .$contenttop. "
<table width=\"700\" align=\"center\" bgcolor=\"#ffffff\" link=\"#F00000\">
<tr><td colspan=\"2\" align=\"center\">
My name is " . $name . " !<br />
" .$town . "" .$city . "" .$town . "
if ( $str5 == $str6 ) {echo "$str4"};
</td></tr>
</table>
" .$contentbottom. "
</body>
</html>";
fwrite($fh, $str);
fclose($fh);
// End create file
echo "Congratulations!<br />
The file has been created.
Go to it by clicking <a href=\"$name.php\">here</a>.";
die();
}
// The form:
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action="test2.php" method="post">
Name <input type="text" name="name"><br />
Photo 1: <input type="checkbox" name="town" value=" town,"><br>
Photo 1: <input type="checkbox" name="city" value=" city,"><br>
Photo 2: <input type="checkbox" name="photo2" value="test"><br>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>