Re: POST + QUERY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



using mssql_fetch_assoc worked out great.  I had actually typed it in before
but the code formatting didn't change the color of the text like it normally
does for my mssql functions so I assumed it wasn't valid and deleted it.

Thanks to everyone for your help!


On 3/27/07, Jim Lucas <lists@xxxxxxxxx> wrote:

Dan Shirah wrote:
> Okay, I thought this was VERY simple, but I cannot wrap my mind around
what
> I am doing wrong.
>
>
> echo $_POST['max_id'];  *The echo returns the correct result
> *if($_POST['max_id'] ='') {  *This is suppose to run the below query if
> $_POST['max_id'] is not blank*
>
> $max_id = $_POST['max_id'];  *Sets my POST value to a variable*
> $info = "SELECT * FROM payment_request WHERE id = '$max_id'"; *Selects
> record from my database by the matching ID's*
> $result_info = mssql_query($info) or die(mssql_error());  *Puts the
query
> results into a variable*
> $row_info = ifx_fetch_row($result_info);  *Makes a row in an array for
all
> the returned fields from my query*
>
> $my_info = $row_info['my_value'];
>
> <input type="Text" value="<?php echo $my_info; ?>" size="20"
maxlength="16"
> name="my_value">  *However, this box returns no data.*
>
> I should be using if($_POST['max_id'] ='') {   and
notif($_POST['max_id']
> !=='') {     correct?  Since it is a comparative function just the =
should
> be correct.
>

Can someone take a look at this solution and tell me if this would be a
descent solution for his
problem?

I use this logic all over my code base, let me know if it is efficient,
clean, well structured, etc...

if ( isset($_POST['max_id']) ) {

       $max_id = (int)$_POST['max_id'];

       if ( empty($max_id) ) {
               die('not a valid id');
               # or some other, more graceful, way of catching the error
       }

       $SQL = "SELECT * FROM payment_request WHERE id = '{$max_id}'";

       if ( ( $result_info = mssql_query($SQL) ) === false ) {

               die(mssql_error());
               # again, maybe something more graceful here

       }

       if ( mssql_num_rows( $result_info ) == 0 ) {

               die('nothing to display');
               # again, maybe something more graceful here

       } else {

               while ( $row_info = mssql_fetch_array($result_info) ) {

                       echo '<input type="Text"
value="'.$row_info['my_value'].
                            '" size="20" maxlength="16" name="my_value">';

               }

       }

}

--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different
strings. But there are times
for you and me when all such things agree.

- Rush





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux