SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2005
    Location
    USA
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET is working, but $_POST is not.

    The follow code works when I use the GET method in the form, but not when I use POST.


    If anyone as any ideas I would appreciate it.
    Thanks.
    jdwalke

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>E.A.C.H: Edit Rules</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>

    <?php

    include 'dbeach.inc.php';
    include 'banner.inc.php';
    echo '<h1>Rules Administration</h1>';
    $ruletext = $_REQUEST['ruletext'];
    if (isset($ruletext)):
    //news details have been updated
    $ruleid = $_REQUEST['ruleid'];
    $ruletext = $_REQUEST['ruletext'];

    //$newstext = $_REQUEST['newstext'];
    //$expiredate=$_POST['expire_date'];
    //$steeringmembid=$_POST['steeringmembid'];

    if($ruleid < 1){
    $sql="INSERT INTO rules ";
    }else{
    $sql="UPDATE rules ";
    }

    $sql=$sql . "SET rules_text='$ruletext'";

    if($ruleid > 0){
    $sql=$sql . "WHERE rule_id='$ruleid';";
    }

    if (@mysql_query($sql)) {
    echo '<p>Rule';
    if($ruleid > 0){
    echo " updated";
    }else{
    echo " added.";
    }
    echo '</p>';
    } else {
    echo '<p>Error updating rule: ' .
    mysql_error() . '</p>';
    } //end if
    ?>


    <?php
    else: //allow user to edit or delete
    $mode = $_REQUEST['mode'];
    $ruleid=$_REQUEST['ruleid'];

    if ($mode == "delete" && $ruleid > 0):
    $sql="DELETE from rules WHERE rule_id='$ruleid';";

    if (@mysql_query($sql)) {
    echo '<p>Rule deleted</p>';
    } else {
    echo '<p>Error deleting rule: ' .
    mysql_error() . '</p>';
    } //end if

    ?>
    <?php else: //edit

    $rules=@mysql_query("SELECT rules_text FROM rules WHERE
    rule_id='$ruleid';");

    if (!$rules) {
    echo $sql;
    exit('<p>Error fetching details: ' .
    mysql_error() . '</p>');
    } //end if

    $rules=mysql_fetch_array($rules);
    $ruletext=htmlspecialchars($rules['rules_text']);
    //$newsdesc=htmlspecialchars($rules['news_desc']);

    ?>
    <form name="rules" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
    Rule descriptionbr />
    <textarea name = "ruletext" rows="6" cols="100">
    <?php echo $ruletext; ?></textarea>
    <input type="hidden" name="ruleid" value="<?php echo $ruleid; ?>" />
    <br /><input type="submit" value="SUBMIT" />
    </form>
    <?php endif; ?>
    <?php endif; ?>
    <p><a href="rules_admin.php">Back to rules</a> |
    <a href="admin.php">Admin Page</a> |
    <a href="index.php">Home</a></p>
    <?php include 'footer.inc.php'; ?>
    </body>
    </html>

  2. #2
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why are you using $_REQUEST? If you want to use the post method on your form replace $_REQUEST with $_POST

  3. #3
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Try


    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>E.A.C.H: Edit Rules</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>

    <?php

    include 'dbeach.inc.php';
    include 
    'banner.inc.php';
    echo 
    '<h1>Rules Administration</h1>';
    if (isset(
    $_POST['ruletext'])):
    //news details have been updated
    $ruleid $_POST['ruleid'];
    $ruletext $_POST['ruletext'];

    //$newstext = $_POST['newstext'];
    //$expiredate=$_POST['expire_date'];
    //$steeringmembid=$_POST['steeringmembid'];

    if($ruleid 1){
    $sql="INSERT INTO rules ";
    }else{
    $sql="UPDATE rules ";
    }

    $sql=$sql "SET rules_text='$ruletext'";

    if(
    $ruleid 0){
    $sql=$sql "WHERE rule_id='$ruleid';";
    }

    if (@
    mysql_query($sql)) {
    echo 
    '<p>Rule';
    if(
    $ruleid 0){
    echo 
    " updated";
    }else{
    echo 
    " added.";
    }
    echo 
    '</p>';
    } else {
    echo 
    '<p>Error updating rule: ' .
    mysql_error() . '</p>';
    //end if
    ?>


    <?php
    else: //allow user to edit or delete
    $mode $_POST['mode'];
    $ruleid=$_POST['ruleid'];

    if (
    $mode == "delete" && $ruleid 0):
    $sql="DELETE from rules WHERE rule_id='$ruleid';";

    if (@
    mysql_query($sql)) {
    echo 
    '<p>Rule deleted</p>';
    } else {
    echo 
    '<p>Error deleting rule: ' .
    mysql_error() . '</p>';
    //end if

    ?>
    <?php 
    else: //edit

    $rules=@mysql_query("SELECT rules_text FROM rules WHERE
    rule_id='
    $ruleid';");

    if (!
    $rules) {
    echo 
    $sql;
    exit(
    '<p>Error fetching details: ' .
    mysql_error() . '</p>');
    //end if

    $rules=mysql_fetch_array($rules);
    $ruletext=htmlspecialchars($rules['rules_text']);
    //$newsdesc=htmlspecialchars($rules['news_desc']);

    ?>
    <form name="rules" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    Rule description:<br />
    <textarea name = "ruletext" rows="6" cols="100">
    <?php echo $ruletext?></textarea>
    <input type="hidden" name="ruleid" value="<?php echo $ruleid?>" />
    <br /><input type="submit" value="SUBMIT" />
    </form>
    <?php endif; ?>
    <?php 
    endif; ?>
    <p><a href="rules_admin.php">Back to rules</a> |
    <a href="admin.php">Admin Page</a> |
    <a href="index.php">Home</a></p>
    <?php include 'footer.inc.php'?>
    </body>
    </html>
    However I haven't checked any other code for errors, but you don't seem to be passing anything with name=mode even though its in your code.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  4. #4
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Stupid yet obvious point (I see Mandes has corrected it) but you are using Method="Get" in your form therefore only $_GET and $_REQUEST will work, post won't as there are no post variables set.

  5. #5
    SitePoint Member
    Join Date
    Jul 2005
    Location
    USA
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tried using method="POST" in the form, along with changing the $_GET to $_POST. Still will not work.

    Thanks,
    jdwalke


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •