Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-02-2006, 12:54 PM   PM User | #1
alex57
Regular Coder

 
Join Date: Sep 2006
Posts: 216
Thanks: 9
Thanked 0 Times in 0 Posts
alex57 has a little shameless behaviour in the past
php and checkboxes

I have a page that reads the firstname (fname) from mysql database and gives each name a checkbox. See below:

PHP Code:
<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 Code:
<?php $thename=$_POST["$row['fname']"]; 
echo 
$thename;
?>
Thanks
alex57 is offline   Reply With Quote
Old 11-02-2006, 02:42 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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.
__________________

Last edited by Fumigator; 11-02-2006 at 02:44 PM..
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:36 PM.


Advertisement
Log in to turn off these ads.