...

View Full Version : php and checkboxes



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


<html>
<body>
<?php

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'>
<?php
while($row = mysql_fetch_array($result)){

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

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

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;
?>

Thanks

Fumigator
11-02-2006, 02: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum