i have the following form which submits to itself. the form is used for editing a row in a database table.
<?php
session_start(); // start a session
require_once '../includes/adminheader.php';
require_once '../includes/mysql_connect.php';
require_once '../includes/functions.php';
require_once '../includes/brand_functions.php';
$brandid = (int)$_GET['brandid'];
$brandname = getBrandName( $brandid );
$page_title = 'Auto-Zim Administration - Edit Brand : ' . $brandname;
if ( isset( $_POST['submitted'] ) ) {
$errors = array();
if ( $_POST['txtBrandName'] == "" ) {
$errors[] = 'Please the brand\'s new name.';
} else {
$newName = escape_value( $_POST['txtBrandName'] );
}
if ( epmty( $errors ) ) {
$connection = open_connection();
$sql = "UPDATE tblbrands SET name = '{$newName}' WHERE brandid = $brandid LIMIT 1";
$r = mysql_query( $sql ) or die( 'Could not execute query: ' . mysql_error() );
if ( mysql_affected_rows( $r ) == 0 ) {
$errors[] = 'Could not edit brand details. Try again later.';
} else {
redirect_to( 'brands.php' );
}
}
}
?>
<div class="title">Edit Brand : <?php echo $brandname; ?></div>
<form action="editbrand.php" method="post"></form>
<table cellpadding="5" cellspacing="5">
<tr>
<td align="left"><b>Brand Name:</b></td>
<td><input type="text" maxlength="25" size="25" id="txtBrandName" id="txtBrandName" value ="<?php echo isset ( $_POST['txtBrandName'] ) ? $_POST['txtBrandName'] : $brandname; ?>"/></td>
</tr>
<tr>
<td colspan="2"><input type="hidden" name="submitted"/><input type="hidden" value="<?php echo $brandid; ?>"/>
<input type="submit" value="Edit Brand" /> <input type="button" value="Cancel" onclick="window.location.href='brands.php'" /></td>
</tr>
</table>
<?php
require_once '../includes/footer.php';
?>
i want to add code that enables me
1. retrieve the name of the row being edited when the user is directed to that page
2. process the new data supplied by the user and then add it to a database.
i have tried checking for the $_SERVER to determine whether it's a get or post method but it's not working.