My code with the foreach thing is:
PHP Code:
<?php
include ("../includes/variables.php");
$table_name = "admin";
mysql_connect("x", "x", "x") or die(mysql_error());
mysql_select_db("$db_name") or die(mysql_error());
if(isset($_COOKIE['ID_my_site'])) {
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM $table_name WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check )) {
if ($pass != $info['password']) {
header("Location: ./login.php");
} else {
?>
<!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>Dark Motives</title>
<script type="text/javascript" src="../equality.js"></script>
<link rel="stylesheet" type="text/css" href="../equality.css" />
</head>
<body>
<div id="container">
<?php
include ("../includes/banner2.php");
include ("../includes/left2.php");
include ("../includes/navigation2.php");
if (!$_POST["submit"]) {
if ((!isset($_GET['id']) || trim($_GET['id']) == "")) {
die('Missing record id!');
}
mysql_select_db("$db_name") or die(mysql_error());
$table_name = "matches";
$id = $_GET['id'];
$query = "SELECT * FROM $table_name WHERE id = '$id'";
$result = mysql_query($query)
or die ("Error in query: $query. " . mysql_error());
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_object($result);
?>
<div id="main">
<h1>Administration - Edit Match </h1>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="form" id="form">
<label for="day">Day: </label>
<input name="day" class="form" size="2" id="day" maxlength="2" value="<?php echo $row->day; ?>"/>
<label for="month">Month: </label>
<input name="month" type="text" class="form" id="month" size="2" maxlength="2" value="<?php echo $row->month; ?>"/>
<label for="year">Year: </label>
<input name="year" type="text" class="form" id="year" size="4" maxlength="4" value="<?php echo $row->year; ?>"/>
<br />
<label for="opponent">Opponent: </label>
<input name="opponent" type="text" class="form" id="opponent" size="50" maxlength="60" value="<?php echo $row->opponent; ?>"/>
<br />
<label for="ladder">Ladder/Competition Name: </label>
<input name="ladder" type="text" class="form" id="ladder" size="50" value="<?php echo $row->ladder; ?>"/>
<br />
<label for="game">Game: </label>
<select name="game" class="form" id="game">
<option value="Company of Heroes">Company of Heroes</option>
<option value="Call of Duty 4">Call of Duty 4</option>
</select>
<br />
<label for="result">Result: </label>
<select name="result" class="form">
<option value="Win">Win</option>
<option value="Loss">Loss</option>
<option value="Draw">Draw</option>
</select>
<label for="score1">Higher Score:</label>
<input name="score1" type="text" class="form" id="score1" size="4" maxlength="4" value="<?php echo $row->score1; ?>"/>
<label for="score1">Lower Score:</label>
<input name="score2" type="text" class="form" id="score2" size="4" maxlength="4" value="<?php echo $row->score2; ?>"/>
<label for="map">Map: </label>
<select name="map" class="form" id="map">
<option value="Map Unavailable">Map Unavailable</option>
</select>
<br />
<label for="screenshot">Screenshot URL:</label>
<input name="screenshot" type="text" class="form" id="screenshot" size="60" maxlength="255" value="<?php echo $row->screenshot; ?>"/>
<br />
<p>Extra Comment/Match Details:
<textarea name="comment" cols="50" rows="5" class="form" id="comment"><?php echo $row->comment; ?></textarea>
<br />
<input name="submit" type="submit" class="form" id="submit" value="Edit Match" />
</p>
</form>
<?php
} else {
echo "That match could not be located in our database.<br />";
}
} else {
$key = array("day","month","year", "opponent", "ladder", "result", "score1", "score2", "map", "comment", "screenshot", "game");
$errorList = array();
if (!get_magic_quotes_gpc()) {
foreach ($key as $val) {
$_POST['$val'] = addslashes($_POST['$val']);
}
}
foreach ($key as $val) {
$$val = $_POST['$val'];
}
if ((!isset($_GET['id']) || trim($_GET['id']) == "")) {
die('Missing record id!');
}
foreach($_POST as $key => $val) {
if(trim($val) == '') $errorList[count($errorList)] = "Invalid entry: $key";
}
if (sizeof($errorList) == 0) {
mysql_select_db("$db_name") or die(mysql_error());
$query = "UPDATE $table_name SET day = '$day', month = '$month', year = '$year', opponent = '$opponent', ladder = '$ladder', result = '$result', score1 = '$score1', score2 = '$score2', map = '$map', comment = '$comment', screenshot = '$screenshot', game = '$game' WHERE id = '$id'";
$result = mysql_query($query) or die("Error in query: $query. " . mysql_error());
header("Location: show_editmatch.php");
mysql_close($connection);
} else {
echo "The following errors were encountered:";
echo "<br>";
echo "<ul>";
for ($x=0; $x<sizeof($errorList); $x++) {
echo "<li>$errorList[$x]";
}
echo "</ul><br />";
}
}
include ("../includes/logout.php");
?>
</div>
<?php
include ("../includes/right2.php");
include ("../includes/footer2.php");
?>
</div>
</body>
</html>
<?php
}
}
} else {
header("Location: ./login.php");
}
?>
Bookmarks