close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Checked? in a Dynamic Radio Group

Thread began 5/31/2009 2:59 pm by Jon Gibson | Last modified 6/05/2009 9:18 am by Jon Gibson | 11601 views | 7 replies |

Jon GibsonBeta Tester

Checked? in a Dynamic Radio Group

Hello:

What is working:
Dynamically generated a radio group using PHP and MySQL (with Dreamweaver built in Record Set and a loop).

What I can't get done:
How can I determine which radio button has been checked by the user?

What I have tried:
Googleing this thing to death.

I found a site that uses a checked status type thing, but that assumed the values were hard coded. I would like to maintain dynamic values if possible. Also, I realize some (maybe all:) of the php below may not be well formed . . . I am trying to learn how to use Dreamweaver's built in functionality and the generated code is throwing me a bit.
Here is my current Form code:
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">


<?php $checkedStatus = 'unchecked'; do { ?>
<?php ?>
<input type="radio" checked="<?php print $checkedStatus; ?>" name="candidate" value="<?php echo $row_getCandidateInfo['numberVotes']; ?>" id="<?php echo $row_getCandidateInfo['id'];?>" /><?php echo $row_getCandidateInfo['candidate'] . "<br />"; ?>

<?php } while ($row_getCandidateInfo = mysql_fetch_assoc($getCandidateInfo)); ?>
<br />

<input name="vote" type="submit" value="vote" />
<input type="hidden" name="MM_update" value="form1" />
</form>

Thank you!
Jon

Sign in to reply to this post

Ray BorduinWebAssist

Set the value attribute of the radio input tag.

Set all radio buttons of the same group to have the same name attribute.

The form will behave the same way as if you used and input type text button and they typed in the value of the selected radio.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jon GibsonBeta Tester

Did not Work

Thank you for the suggestion Ray, but unfortunately it did not work. I have my name attribute hard coded to 'candidate' and the value hard coded to '1' now. The id is dynamic where I used a server behavior to assign the database id to the respective person.

I believe my error is in the MySQL statement. For whatever reason I cannot perform an update that searches for the where of the dynamic id.

I know this is not a MySQL forum, but here is the partial statement I am using in case you have a suggestion:
within an if statement for submit:
$query: "UPDATE candidates SET numberVotes=numberVotes+1 WHERE id=id";

QUESTION:
the original SQL statement that DW generated had numberVotes=%s. What does the %s stand for, as I could not see it repeated within the generated code.

Regardless of a new suggestion, thank you for your help.
Jon

Sign in to reply to this post

Ray BorduinWebAssist

%s is probably correct. It is used as a token to be replaced with a parameter. So it would be used to identify the id of the candidate to update. It will need the %s to differentiate which to update.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jon GibsonBeta Tester

Still Trying

Good afternoon Ray:

I have attempted to figure this out on my own with little success. I have, however, discovered a pattern to my problem:

If I vote for person A, person B (the next person in the voting list) gets that vote and all of the total votes of person A. Even if the person is not 'visible' from my database, they still hog the votes of the previous person.

Here is the SQL code:
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE candidates SET numberVotes=%s+1 WHERE id=%s",
GetSQLValueString($_POST['voteValue'], "int"),
GetSQLValueString($_POST['voteValue'], "int"));

Here is the Form PHP/HTML:
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<?php do { ?>
<input type="radio" value="<?php echo $row_rsCandidates['numberVotes']; ?>" name="voteValue" id="<?php echo $row_rsCandidates['id']; ?>" /><?php echo $row_rsCandidates['candidate']; ?><br />
<?php } while ($row_rsCandidates = mysql_fetch_assoc($rsCandidates)); ?>

Question:
Would the data and security assist products help create more specific queries (server behaviors)? I have yet to purchase but am strongly considering if they would aid in the server behavior area.

Thank you for the support Ray!

Sign in to reply to this post

Jon GibsonBeta Tester

Answer

I still would like to know about the server behavior bit in the above post, but I believe my problem is that I am using the value property of a form incorrectly.

Namely, since all candidates would start out with 0 votes, and then I tried to update via a vote, the value would conflict. And in the 'pattern' I discovered was just pure coincidence because candidate id 4 had four votes and when I voted for her (adding 1) it would post to candidate id 5 because the new value was 5.

Just thought this might someone else who is making a similar mistake . . .

Sign in to reply to this post

Ray BorduinWebAssist

I think it should be:

Here is the SQL code:
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE candidates SET numberVotes=numberVotes+1 WHERE id=%s",
GetSQLValueString($_POST['voteValue'], "int"));

Here is the Form PHP/HTML:
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<?php do { ?>
<input type="radio" value="<?php echo $row_rsCandidates['id']; ?>" name="voteValue" /><?php echo $row_rsCandidates['candidate']; ?><br />
<?php } while ($row_rsCandidates = mysql_fetch_assoc($rsCandidates)); ?>

Sign in to reply to this post
Did this help? Tips are appreciated...

Jon GibsonBeta Tester

Thank You

I actually came to the same solution . . . it boiled down to me incorrectly using the value option within the radio button.

Thank you for answering my SQL question here.

Have a great weekend Ray!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...