Re: update db with variables

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

 



Quotes missing around $value. Try instead:

mysql_query( "UPDATE tablename SET {$name} LIKE '{$value}' WHERE ID={$id}")

Of course, even though the code does not show, you have properly validated
user input before firing this query...<blink/>

HTH
Ignatius
_________________________
----- Original Message -----
From: "Robbie Staufer" <rstaufer@scd.ucar.edu>
To: <php-db@lists.php.net>
Sent: Wednesday, September 24, 2003 5:20 PM
Subject:  update db with variables


> Hi,
>
> I'm writing an application that will display the contents of a db in the
> browser, including the db-assigned id number.  The user can then enter
> the id number in a form and the browser will display the record
> corresponding to that id number, with the data in editable text fields.
>
> The user edits the text fields and submits to an 'update' script using
> POST, and the update script puts the new values back into the database.
>  In the update script, I'm trying to access the field names and values
> in the $_POST array, and update the db using a loop:
>
>                                 while ($data = each($_POST)) {
>                                             $name = $data[ 'key' ];
>                                             $value = $data[ 'value' ];
>                                             echo $name, $value;
>                                             $result =
> mysql_query("UPDATE tablename SET $name = $value WHERE ID=$id") or die
> ("unable to update record");
>                                }
>
> The echo statement shows me that the script dies on the first time
> through the loop.
>
> The application must be on line this week.  Does anyone have any
> suggestions?
>
> Many thanks,
> Robbie
>
>
>
> --
> -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
> Robbie Staufer
> NCAR/SCD
> 1850 Table Mesa Dr. Rm. 42
> Boulder, CO. 80305
> (303) 497-1836
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux