PHP / MySQL / Forms - editing an exising record

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Protoevangel
Forum Newbie
Posts: 2
Joined: Tue Aug 29, 2006 3:17 pm

PHP / MySQL / Forms - editing an exising record

Post by Protoevangel »

Hello all. I have searched and browsed the forums for an answer to my question before deciding to post this. If I have passed over the answer unintentionally, I apologize, perhaps the answer to my question would simply be a link?

I am trying to edit records in a MySQL database. My insert record page is working fine, so is my view records and delete records pages. What I am having a problem with is with my edit record page. Following is the only part that isn't working:

Code: Select all

PWL ONLY:
<input type="radio" <?php if ($site="PWL") echo "checked='checked'" else echo "" ?> name="site" value="PWL">

Both sites:
<input type="radio" <?php if ($site="Both") echo "checked='checked'" else echo "" ?> name="site" value="Both">
I have also tried the following:

Code: Select all

PWL ONLY:
<input type="radio" <?php if ($row["site"]="PWL") {echo "checked='checked'";} else {echo "";} ?> name="site" value="PWL">

Both sites:
<input type="radio" <?php if ($row["site"]="Both") {echo "checked='checked'";} else {echo "";} ?> name="site" value="Both">
In every case, every record, whether $site="PWL" or $site="Both", are showing up with the "Both" button selected.


Does anyone know what my problem is? I would be very grateful for any assistance.
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

You need to use == instead of =

Code: Select all

PWL ONLY:
<input type="radio" <?php if ($site == "PWL") echo "checked='checked'" else echo "" ?> name="site" value="PWL">

Both sites:
<input type="radio" <?php if ($site == "Both") echo "checked='checked'" else echo "" ?> name="site" value="Both">
What you were doing was assigning "PWL" to $site, and then assigning "Both" to $site. Can't tell you how many times I've done that to myself.
Protoevangel
Forum Newbie
Posts: 2
Joined: Tue Aug 29, 2006 3:17 pm

Post by Protoevangel »

:oops:

Thanks blackbeard, you got me on the right track again! I can't believe I pounded my head against my keyboard for hours on that one.

Anyway, following is what worked:

Code: Select all

<?php if ($row["site"] == "PWL") echo "checked='checked'"; ?>
Thanks again for getting me out of the rut I dug for myself!!!
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

No problem, like I said, I've been down that road before, and have the keyboard impressions in my forehead to prove it. :)
Post Reply