Rohit_Bhutani Posted January 27, 2013 Share Posted January 27, 2013 Hello to all, I am new to this forum as well as php. Would highly appreciate if someone could help me on this: This is my code: $result = mysql_query("SELECT * FROM Users"); $num= mysql_numrows($result); echo " <table border='1'> <tr> <th>Username</th> <th>Can comment for you ?</th> </tr> "; echo '<form id="commentchoices1" name="form3" method="post" action="permissionsentry.php">'; while($row = mysql_fetch_array($result)) { if ($row['username']!= $_SESSION['SESS_USER_NAME']) //dont print the name of this user itself in the list comment for { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>"; $var= $row['username']; $var2= $row['serial']; echo '<input name=$var2 type="radio" value= " . $var . " >Yes'; echo '<input name=$var2 type="radio" value="">No'; echo "</td>"; echo "</tr>"; } } The problem is with the radio buttons. I get the output clean and good with 5 rows of users. But the problem is that I want to be able to select "Yes" or "No" in each row but this output allows me to select only one radio button out of all of them. I kept the radio button name as the serial number of each user fetched from data base but still it doesnt work. Also value=value= " . $var . " is not working either. I get the output as ". $var ." only as if it was a string and not a variable. I know that I am doing in error in quotes and colons but I am not sure where. I have tried this also in value field: echo '<input name=$var2 type="radio" value= "<?php echo $var;?>" >Yes'; If I use echo '<input name=$var2 type="radio" value= '$var' >Yes'; I get a syntax error. But it does not give any output. May be because my statement is already in an "echo". Could anyone please help ? Thanks in advance. Regards, Rohit Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 27, 2013 Share Posted January 27, 2013 Each set will needs it's own name. Variables within single quotes will not be read, you need to use double quotes or string concatenation. And no, you cannot echo within an echo. Please use the code tags when you post, it's easier to read your code that way. Quote Link to comment Share on other sites More sharing options...
Rohit_Bhutani Posted January 27, 2013 Author Share Posted January 27, 2013 Thanks a lot for a prompt reply. Next time will use the code tags for sure. Even if I put a double qoute on variable (for the name field), its read as a string only and still I cant chose one option per row. Also if i cant echo in an echo, Is there any way to use these variables in the name and value field ?? There should be some way to use variables in these fields. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 27, 2013 Share Posted January 27, 2013 I suggest you read the PHP manual pages about strings, specifically about concatenation, and variable interpolation. I know those are big words but the manual explains them. When you've updated your code, post it and we can help with the remaining bugs. Quote Link to comment Share on other sites More sharing options...
computermax2328 Posted January 28, 2013 Share Posted January 28, 2013 (edited) Hello, Welcome to the forum and PHP! Jessica is right, you have your quotations mixed up. When you echo out html you need the proper concatenation and quotation marks. Look up concatenation and learn it because you are going to need it. I tried to skip learning it and work around it, but it will bite you in the ass. Anyway back to your question. So Jessica was also right when she said your radio buttons need names. That is how the process form will figure out what was selected, so something more like this: echo "<input name='$var2' type='radio' value='$var' name='yes'>" . "Yes"; So notice how the two different elements are separated by a period or a concatenation. Also notice that the input is surrounded by double quotes and everything inside that requires quotes has single quotes. If you have any other questions feel free to ask. This is where I learned to code PHP and I am getting a lot better than I was. There are a lot of nice people and great coders in this community. Edited January 28, 2013 by computermax2328 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.