Re: insert data in to columns base on the selection ofthe list box.
am 04.04.2007 11:05:24 von php--------------050909060609000100070306
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Well, simply put (not really following your structure):
--- code ---
if (isset($_POST['R'])):
$address = addslashes($_POST['address']);
$phone = addslashes($_POST['phone']);
$lastname = addslashes($_POST['R']);
$sql = "update $tablename set address = '$address', phone =
'$phone' where LastName = '$lastname';";
if (mysql_query($sql)):
echo "Updated " . $_POST['R'] . "
\n";
else:
echo "Error: " . mysql_error();
endif;
endif;
?>
--- code ---
Choosing a lastname in the select, entering some address and phone info
and hitting submit will update Address and Phone on the row where
Lastname matches what ever you've chosen in the select.
The addslashes stuff is for security only, so no hacker does SQL
insertions on you.
sam rumaizan skrev:
> "I don't get the purpose of your code. It's not looking right anywhere!"
> *(The purpose of my code is to update the fields PhoneNumber, Address,
> Job, FavoriteFood that belong to the selected last name from the menu).*
>
>
> "I'm guessing the select-box isn't working too well, right?"
> *(Sorry; but the select-box works fine) (Your code will print each
> field twice (repetition. Try my code then you will see the difference))*
>
> "Let's say there's 4 $lines:
>
> foreach ($line as $value)
> {
> echo" > }
> echo ">$value";
>
> will produce:
>
> > value='value3'
>
> ... You need to use this code for the selectbox instead:
>
> while ($line = mysql_fetch_array($result))
> {
> foreach ($line as $value)
> {
> echo"";
> }
> }
>
>
> But, I must say, printing all columns as separate values in the select
> box doesn't make any sense.
> In a situation with this data in the database:
>
> LastName PhoneNumber Address Job
> FavoriteFood
> ____________________________________________________________ _____________
> Johnsson 12345 Superstreet Programmer Pizza
> Gustavsson 54321 Miniway 42 Cleaner Chicken
> Andersson 23456 Richstreet 2 Boss Noodles
> Dood 45678 Projects Security Fajitas
>
> you will get:
>
>
>
> Is that really what you're after? *NO* *I need to pull the last name*
> *only from my database. *
> **
>
> *Then:*
> *Let's say I want to change the information in my database for
> Johnsson(How can I do this)*
> * *
> *Sam*
>
>
>
>
>
> ------------------------------------------------------------ ------------
> Finding fabulous fares is fun.
> Let Yahoo! FareChase search your favorite travel sites
>
> to find flight and hotel bargains.
--------------050909060609000100070306--