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" />&nbsp;&nbsp;<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.

your <input> tages needc to bee inside you <form> tag

<form action="editbrand.php" method="post">
    <input />
</form>

i already have that code in place. what i want is for the form to determine whether the form has been submitted or the user has been redirected to that page through via

Could you use

$HTTP_GET_VARS

what does HTTP_GET_VARS do? haven't encountered it before

Don't use HTTP_GET_VARS it's deprecated
use $_GET


do something like

if (isset($_GET['submit']){
     // process form
}

and change

<input type="submit" value="Edit Brand" name="submit" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.