954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

form submission in php

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['REQUEST_METHOD'] to determine whether it's a get or post method but it's not working.

dinhunzvi
Newbie Poster
21 posts since Jul 2010
Reputation Points: 10
Solved Threads: 2
 

your tages needc to bee inside you tag

<form action="editbrand.php" method="post">
    <input />
</form>
pzuurveen
Posting Whiz in Training
229 posts since Sep 2006
Reputation Points: 32
Solved Threads: 47
 

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

dinhunzvi
Newbie Poster
21 posts since Jul 2010
Reputation Points: 10
Solved Threads: 2
 

Could you use

$HTTP_GET_VARS
dkjuk
Newbie Poster
5 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

what does HTTP_GET_VARS do? haven't encountered it before

dinhunzvi
Newbie Poster
21 posts since Jul 2010
Reputation Points: 10
Solved Threads: 2
 

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" />
pzuurveen
Posting Whiz in Training
229 posts since Sep 2006
Reputation Points: 32
Solved Threads: 47
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: