Location: PHPKode > projects > Run > Run-0.8.0.2/Run-0.8.0.2/shoesadd.php
<?php
include("system/environment.php");
include("system/functions.php");
?>

<html>
<?php
include("system/head.php");
?>
<body>

<?php
if ($_POST["submit"]) {
	//check if shoe with the same ShoeName user is trying to input already exists
	$shoeCheckQuery = mysql_query("select ID from $mysqltableshoes where RunnerID='$user' and ShoeName='".$_POST["ShoeName"]."'") or die (mysql_error());
	$shoeCheck = mysql_num_rows($shoeCheckQuery);

	//if the shoe with this ShoeName does not yet exist, put it in the thable now
	if ($shoeCheck == 0) {
	$insert = mysql_query("insert into $mysqltableshoes (RunnerID, ShoeName, ShoeModel, ShoeBrand, ShoeSize, ShoeRetired, ShoeNotes) values ('$user', '".$_POST["ShoeName"]."', '".$_POST["ShoeModel"]."', '".$_POST["ShoeBrand"]."', '".$_POST["ShoeSize"]."', 'N', '".$_POST["ShoeNotes"]."')") or die (mysql_error());

	echo "<html>\n<head>\n<meta http-equiv=\"refresh\" content=\"3; url=shoes.php?active=1\">\n</head>\n<body>\n<div class=\"inputconfirm\">You have successfully added a new pair of shoes.</div>\n</body>\n</html>";
	} else {
	//if the shoe with this ShoeName already exists print the form again, but this time with red notice by the ShoeName text box.
?>



<!-- BEGIN - this filled-out form is displayed only if the shoe with the same ShoeName already exists !-->

<div class="logo"><img src="system/imgs/runsmall.png"></div>

<div class="navigation">
<a href="shoes.php?active=1" title="Active Shoes: Alt+A" accesskey="a" class="url"><u>A</u>ctive Shoes</a> | 
<a href="shoes.php?active=0" title="Retired Shoes: Alt+R" accesskey="r" class="url"><u>R</u>etired Shoes</a>
</div>

<div class="content">
<b>Runner: <?php echo $user ?></b>
<p class="header">Add New Shoe</p>

<table width="460" border="0">
<form class="log" method="post" action="<?php $_SERVER['PHP_SELF']?>">

<tr>
<td class="log" valign="bottom">Name:</td>
<td><input class="log" type="text" name="ShoeName" value="<?php echo $_POST["ShoeName"]?>" size="20" maxlength="30">
</td></tr>
<tr><td></td><td>
<span class="warning">You already own a shoe named <b><?php echo $_POST["ShoeName"]?></b>.<br>Choose a different name.</span></td>
<tr>

<tr>
<td class="log">Model:</td>
<td><input class="log" type="text" name="ShoeModel" value="<?php echo $_POST["ShoeModel"]?>" size="20" maxlength="30"></td>
</tr>

<tr>
<td class="log">Brand:</td>
<td><select class="log" name="ShoeBrand">
<option value="<?php echo $_POST["ShoeBrand"]?>"><?php echo $_POST["ShoeBrand"]?></option>
<?php
shoeBrands();
?>
</select></td>
</tr>

<tr>
<td class="log">Size:</td>
<td><input class="log" type="text" name="ShoeSize" value="<?php echo $_POST["ShoeSize"]?>" size="2" maxlength="4"></td>
</tr>

<tr>
<td class="log" valign="top">Notes:</td>
<td><textarea class="log" name="ShoeNotes" rows="7" cols="40" wrap="virtual"><?php echo htmlentities($_POST["ShoeNotes"]);?></textarea></td>
</tr>

<tr>
<td></td>
<td class="left">
<input class="log" type="submit" name="submit" accesskey="s" value="Submit">&nbsp;
<input class="log" type="submit" accesskey="w" value="Wipe">
</td>
</tr>
</form>

<tr>
<td align="right" colspan="2"><a href="javascript:window.close();" title="Close This Window: Alt+C" accesskey="c" class="url">Close</a></td>
</tr>

</table>
</div>
<!-- END - this filled-out form is displayed only if the shoe with the same ShoeName already exists !-->



<?php
	}

} else {
	//the empty form below is printed first - before submit is clicked
?>



<!-- BEGIN - regular table with regular empty form !-->

<div class="logo"><img src="system/imgs/runsmall.png"></div>

<div class="navigation">
<a href="shoes.php?active=1" title="Active Shoes: Alt+A" accesskey="a" class="url"><u>A</u>ctive Shoes</a> | 
<a href="shoes.php?active=0" title="Retired Shoes: Alt+R" accesskey="r" class="url"><u>R</u>etired Shoes</a>
</div>

<div class="content">
<b>Runner: <?php echo $user ?></b>
<p class="header">Add New Shoe</p>

<table width="460" border="0">
<form class="log" method="post" action="<?php $_SERVER['PHP_SELF']?>">

<tr>
<td class="log">Name:</td>
<td><input class="log" type="text" name="ShoeName" size="20" maxlength="30"></td>
<tr>

<tr>
<td class="log">Model:</td>
<td><input class="log" type="text" name="ShoeModel" size="20" maxlength="30"></td>
</tr>

<tr>
<td class="log">Brand:</td>
<td><select class="log" name="ShoeBrand">
<option value=""></option>
<?php
shoeBrands();
?>
</select></td>
</tr>

<tr>
<td class="log">Size:</td>
<td><input class="log" type="text" name="ShoeSize" size="2" maxlength="4"></td>
</tr>

<tr>
<td class="log" valign="top">Notes:</td>
<td><textarea class="log" name="ShoeNotes" rows="7" cols="40" wrap="virtual"></textarea></td>
</tr>

<tr>
<td></td>
<td class="left">
<input class="log" type="submit" name="submit" accesskey="s" value="Submit">&nbsp;
<input class="log" type="submit" accesskey="w" value="Wipe">
</td>
</tr>
</form>

<tr>
<td align="right" colspan="2"><a href="javascript:window.close();" title="Close This Window: Alt+C" accesskey="c" class="url"><u>C</u>lose</a></td>
</tr>

</table>
</div>
<!-- END - regular table with regular empty form !-->

<?php
}
?>

</body>
</html>
Return current item: Run