View Full Version : php and checkboxes

11-02-2006, 01:54 PM
I have a page that reads the firstname (fname) from mysql database and gives each name a checkbox. See below:


mysql_connect("localhost", "root", "dinosaur") or die(mysql_error());

mysql_select_db("info") or die(mysql_error());

$query = "SELECT fname FROM users";

$result = mysql_query($query) or die(mysql_error());

<form name=myForm action='Edit.php' method='post'>
while($row = mysql_fetch_array($result)){

echo $row['fname']?> <input type="checkbox" name="<?php $row['fname']?>"><BR><?php

<input type='submit' value='Confirm'></form>

Is the syntax correct where I am naming the checkbox? are the quotes correct? Also on the page where I am calling a value the syntax isnt correct becasue I get the error:

"Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\xampp\htdocs\Login\tests\Edit.php on line 1"

<?php $thename=$_POST["$row['fname']"];
echo $thename;


11-02-2006, 03:42 PM
You have to <?php echo $row['fname']; ?>; you just have <?php $row['fname'] ?>

On the syntax $_POST["$row['fname']"], just skip the outer quotes-- quotes indicate "I am putting a literal string here", which you aren't doing-- you are putting a variable there. Use $_POST[$row['fname']] and it'll work fine.