Location: PHPKode > projects > Battle Cart > order/admin/edit.php
<?
require "basic.inc.php";
require "header.inc.php";
?>

<?
if ($_GET['action'] == "add") {
	$txn_id = substr(md5(uniqid(rand(), true)),0,17);
	mysql_query("INSERT INTO orders (txn_id,time) VALUES ('".$txn_id."',NOW())");
} else {
	$txn_id = $_GET['txn_id'] ? $_GET['txn_id'] : $_POST['txn_id'];
}
?>
<form method="post" action="edit.php">
<input name="txn_id" type="HIDDEN" value="<? echo $txn_id ?>">
<input name="update" type="HIDDEN" value="1">
<?
$row = mysql_fetch_assoc(mysql_query("SELECT * FROM orders WHERE txn_id = '$txn_id'"));
$sql = "UPDATE orders SET ";
$sql .= "txn_id = '".$row['txn_id']."'";
for ($i=0;$i<(sizeof($row)-1);$i++) {
	next($row);
	$key = key($row);
	$sql .= ", $key = '".$$key."'";
?>
<b><? echo $key ?>:</b><br><input type="text" name="<? echo $key ?>" value="<? echo (isset($update) ? $$key : ss($row[$key])); ?>" size="75"><br><br>
<?
}
if ($update) {
	$sql .= " WHERE txn_id = '$txn_id'";
	$result = mysql_query($sql);
	if ($result) echo "Success!";
	else exit("Failed!");
	//echo " (<A HREF=edit.php?txn_id=$txn_id>Back</A> | <A HREF=javascript:alert(\"".str_replace(" ","&nbsp;",$sql)."\")>SQL</A>)<BR><BR>";
	?>
	<script language="JavaScript">location.replace('txn.php?id=<? echo $txn_id ?>')</script>
	<?
}
?>
<input type="SUBMIT" value="Edit">
</form>
Return current item: Battle Cart