Page 1 of 1

[SOLVED] $form['id'] not being selected :(

Posted: Fri Feb 25, 2005 10:48 am
by neon068
Ok, I'm new to both the DevNetwork forums and PHP so flame away :P Anyways, I'm trying to make a small script but I suck so I can't get it to work.

What it supposed to do is just find a person in a database via an id number provided in the address bar (i.e. edit.php?id=7 ), edit it, then thats it. It will get everything fine but when I try to submit, it comes up with the echo 'the request is missing data';

Any help would be greatly appreciated!

Here's the code...

Code: Select all

<?
    include_once ( 'config.php' );

    if ( isset ( $_REQUEST&#1111;'id'] ) && ! empty ( $_REQUEST&#1111;'id'] ) )
    &#123;

        if ( strtolower ( $_SERVER&#1111;'REQUESTED_METHOD'] ) == 'post' )
        &#123;
            $query = array ();

            if ( isset ( $_POST&#1111;'firstname'] ) && ! empty ( $_POST&#1111;'firstname'] ) )
            &#123;
                $query&#1111;] = "firstname = '" . mysql_real_escape_string ( $_POST&#1111;'firstname'] ) . "'";
            &#125;

            if ( isset ( $_POST&#1111;'lastname'] ) && ! empty ( $_POST&#1111;'lastname'] ) )
            &#123;
                $query&#1111;] = "lastname = '" . mysql_real_escape_string ( $_POST&#1111;'lastname'] ) . "'";
            &#125;

            if ( isset ( $_POST&#1111;'email'] ) && ! empty ( $_POST&#1111;'email'] ) )
            &#123;
                $query&#1111;] = "email = '" . mysql_real_escape_string ( $_POST&#1111;'email'] ) . "'";
            &#125;

            if ( ! empty ( $query ) )
            &#123;

                $result = "UPDATE clients SET " . implode ( ', ', $query ) . " WHERE id = '" . mysql_real_escape_string ( $_REQUEST&#1111;'id'] ) . "'";

                mysql_query ( $result ) or die ( 'UPDATE ERROR: ' . mysql_error () );

                echo '<b>Thank you! client UPDATED Successfully!<br>';
                echo '<meta http-equiv=Refresh content=2;url=index.php>';
            &#125;
            else
            &#123;
                echo 'the request did not contain any valid data, try again';
                echo '<meta http-equiv=Refresh content=2;url=' . $SERVER&#1111;'PHP_SELF'] . '?id=' . $_REQUEST&#1111;'id'] .'>';
            &#125;
        &#125;
        else
        &#123;

            $result = "SELECT firstname, lastname, email FROM clients WHERE id = " . (int)$_REQUEST&#1111;'id'];

            $r = mysql_query ( $result ) or die ( 'SELECT ERROR: ' . mysql_error () );

            if ( mysql_num_rows ( $r ) > 0 )
            &#123;
                $form = mysql_fetch_assoc ( $r );
?>

<h3>Edit Clients</h3>

<form method="post" action="<?=$_SERVER&#1111;'PHP_SELF'];?>">

<input type="hidden" name="id" value="<?=$form&#1111;'id'];?>">

firstname: <input name="firstname" size="50" maxlength="50" value="<?=htmlentities($form&#1111;'firstname']);?>">
<br>
lastname: <input name="lastname"  size="50" maxlength="50" value="<?=htmlentities($form&#1111;'lastname']);?>">
<br>
email: <input name="email" size="50" maxlength="50" value="<?=htmlentities($form&#1111;'email']);?>">
<br>
<input type="submit" name="submit" value="Update Client">
</form>

<?

            &#125;
            else
            &#123;
                die ( 'QUERY ERROR: the id is not valid' );
            &#125;
        &#125;
    &#125;
    else
    &#123;
        echo 'the request is missing data';
    &#125;

?>

Posted: Fri Feb 25, 2005 10:54 am
by feyd
check to make sure the id is being printed in the form's html. I suspect that you don't have short-tags on.

Posted: Fri Feb 25, 2005 10:56 am
by anjanesh
Try using $_GET['id'];

Posted: Fri Feb 25, 2005 11:00 am
by neon068
I tryed using the following...

Code: Select all

<?php
$id = (int)$_REQUEST&#1111;'id'];
?>
<input type="hidden" name="id" value="<?=$id?>">
and this didn't work, unless I put it somewhere I shouldn't have. What I think is happening is that I'm not selecting the "id" column in the query, so $form['id'] does not have a value. But I am not sure how to fix it

Posted: Fri Feb 25, 2005 11:08 am
by feyd

Code: Select all

<?php echo $id; ?>
do anything? if so, you have short-tags off.

Posted: Fri Feb 25, 2005 12:03 pm
by neon068
nope... nothing works... here is a test of the script...


http://serasfinancial.com/testing/edit.php?id=1

id 1 and 2 work if you want to try it. This is the current code i'm using...

Code: Select all

<?
    include_once ( 'config.php' );
    $id = $_GET&#1111;'id'];
    if ( isset ( $_REQUEST&#1111;'id'] ) && ! empty ( $_REQUEST&#1111;'id'] ) )
    &#123;

        if ( strtolower ( $_SERVER&#1111;'REQUESTED_METHOD'] ) == 'post' )
        &#123;
            $query = array ();

            if ( isset ( $_POST&#1111;'firstname'] ) && ! empty ( $_POST&#1111;'firstname'] ) )
            &#123;
                $query&#1111;] = "firstname = '" . mysql_real_escape_string ( $_POST&#1111;'firstname'] ) . "'";
            &#125;

            if ( isset ( $_POST&#1111;'lastname'] ) && ! empty ( $_POST&#1111;'lastname'] ) )
            &#123;
                $query&#1111;] = "lastname = '" . mysql_real_escape_string ( $_POST&#1111;'lastname'] ) . "'";
            &#125;

            if ( isset ( $_POST&#1111;'email'] ) && ! empty ( $_POST&#1111;'email'] ) )
            &#123;
                $query&#1111;] = "email = '" . mysql_real_escape_string ( $_POST&#1111;'email'] ) . "'";
            &#125;

            if ( ! empty ( $query ) )
            &#123;

                $result = "UPDATE clients SET " . implode ( ', ', $query ) . " WHERE id = '" . mysql_real_escape_string ( $_REQUEST&#1111;'id'] ) . "'";

                mysql_query ( $result ) or die ( 'UPDATE ERROR: ' . mysql_error () );

                echo '<b>Thank you! client UPDATED Successfully!<br>';
                echo '<meta http-equiv=Refresh content=2;url=index.php>';
            &#125;
            else
            &#123;
                echo 'the request did not contain any valid data, try again';
                echo '<meta http-equiv=Refresh content=2;url=' . $SERVER&#1111;'PHP_SELF'] . '?id=' . $_REQUEST&#1111;'id'] .'>';
            &#125;
        &#125;
        else
        &#123;

            $result = "SELECT firstname, lastname, email FROM clients WHERE id = " . (int)$_REQUEST&#1111;'id'];

            $r = mysql_query ( $result ) or die ( 'SELECT ERROR: ' . mysql_error () );

            if ( mysql_num_rows ( $r ) > 0 )
            &#123;
                $form = mysql_fetch_assoc ( $r );
?>

<h3>Edit Clients</h3>

<form method="post" action="<?=$_SERVER&#1111;'PHP_SELF'];?>">

<?
$id = (int)$_REQUEST&#1111;'id'];
?>
<input type="hidden" name="id" value="<?=$id?>">

firstname: <input name="firstname" size="50" maxlength="50" value="<?=htmlentities($form&#1111;'firstname']);?>">
<br>
lastname: <input name="lastname"  size="50" maxlength="50" value="<?=htmlentities($form&#1111;'lastname']);?>">
<br>
email: <input name="email" size="50" maxlength="50" value="<?=htmlentities($form&#1111;'email']);?>">
<br>
<input type="submit" name="submit" value="Update Client">
</form>

<?

            &#125;
            else
            &#123;
                die ( 'QUERY ERROR: the id is not valid' );
            &#125;
        &#125;
    &#125;
    else
    &#123;
        echo 'the request is missing data';
    &#125;

?>

I'll give you a big cookie if you can fix this! :D

Posted: Fri Feb 25, 2005 12:07 pm
by feyd
the link requires http auth.

Posted: Fri Feb 25, 2005 12:11 pm
by neon068
Sorry... I forgot about that. It's

test/test123

Posted: Fri Feb 25, 2005 12:19 pm
by feyd
hmmm just noticed.. you are using $_SERVER['REQUESTED_METHOD'] which doesn't exist.. $_SERVER['REQUEST_METHOD'] does however.

Posted: Fri Feb 25, 2005 2:14 pm
by neon068
ARG! thats it... Stupid error! :(

Thanks... here's your cookie!

Image