Error Message in <option> when I try to run within the form.

Hi,
This might be a stupid question. Here is the code to create drop down box which is working file outside the but when I try to insert the code within the form in between other input columns it doesn’t work. Any idea what I am missing here?

Error Message: Parse error: syntax error, unexpected ‘’ (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\gms_files\funder_form.php on line 167

Line 167/168 (from below coding):

<?php echo $row['types']?>

-------- Code ---------

Country : -- Select Code--
<?php
include("gms_cn.php");
$query = "select * from type order by types";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result)){
?>

<?php echo $row['types']?>
<?php } ?>
</select>
</label></td>

Thanks so much!

<?php echo $row['types'][b];[/b]?>

Your welcome.

Thanks Kevin,
I tried but still getting the same error? Any idea why the same code is working out side the but in the ?

<?php echo $row['types'];?>

Try this:

<?php echo {$row['types']};?>

[php]<?php echo $row['types']; ?>[/php]

There is a space between the semicolon and the closing php tag, correct?

Thank You for your reply.
It’s working but not showing records anymore?

<?php echo {$row['types']};?>

Two things:

View the page source and see if the data is showing there. If not,

Check and make sure there is data in the variables

Do
print_r($result);

I am sorry to bother you once again. I have tried it a couple of times within form and without form (just the dropdown function) and what I figured it out is :

a) Data is not showing in the form when I replace the below code (See the attached file with screen shot for the form and coding of the function)

b) When I try to run the function only on a fresh page with below coding I got an error message "
Parse error: syntax error, unexpected ‘{’ in C:\xampp\htdocs\gms_files\test.php on line 19"

<option id="<?php echo {$row['type_id']}; ?>">
<?php echo {$row['types']}; ?>

I am sure data is there. In the attached file I am showing 2 drop downs one is out of the function (box #2) showing data and another (box 1) is showing no data (coding is showing in the attachment)


Screenshot.doc (176 KB)

Sorry, I sent you the attachment with wrong function. Here is the file with correct function. Thanks you so much!!


2-Screenshot.doc (173 KB)

Personally I wouldn’t intermingle PHP with HTML for it looks messy and can be confusing - I would do something like this:

[php]while ($row = mysql_fetch_array($result)){
echo ‘’ . $row[‘types’] . ‘’ . “\n”;
} [/php]

and I would do it for the other HTML Tags that deal with the <select) tags, but that is just my preference. :wink:

Anyway part of you problem is you don’t have value="" in you option tag…you’ll never get the data if you don’t have it.

Thanks for your response
Again, it’s working outside the function but not in the function. Is something wrong in the function???
I am really fed up now:)

See the error when I try to run in the function

Parse error: syntax error, unexpected ‘’ (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\gms_files\funder_form.php on line 167


function printform(){
//$PageTitle=‘Print - Name of the Title’;
//include(“hd.php”);
print <<< HERE

Add a new Funder:

Name :
Address :
City :
State :
Zip :
Web Address :
Sales Force ID :
Note: :
?>
Country : -- Select Code--
<?php
include("gms_cn.php");
$query = "select * from type order by types";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result)){
echo ‘’ . $row[‘types’] . ‘’ . “\n”;
}
?>

<?php
HERE; }

The function has it’s own variable scope, what I mean by that variable declared outside the function (Database connection variable for example) would have to be brought into the function along with any other variables that needed to access (use).

Here’s an example what I’m talking about
[php]/* Function to Display Thumbnails and Images /
/
Convert to a Class in Near Future */
function displayDir($pdo, $name) {
try { // Fetch the images:
$query = ‘Select id, thumbnail, picName, subDirectory, user_name FROM pictures WHERE subDirectory=:subDirectory ORDER BY id ASC’; //RAND() = Random Pictures
$result = $pdo->prepare($query);
$result->execute(array(’:subDirectory’ => $name));
if ($result && $result->rowCount() > 0) { // Check that rows were returned:
$result->setFetchMode(PDO::FETCH_CLASS, ‘StoredPictures’); // Arm the image class by fetching it:
} else { // Problem!
throw new Exception(‘No content is available to be viewed at this time’);
}
} catch (Exception $e) { // Catch generic exceptions
}
return $result;
}[/php]
In this particular example I have to pull in the $pdo (database connection varibale) and name of the file (I think?) into the function in order for this function to work properly. Otherwise the function would spit out an error, which would basically be saying in English that it doesn’t know what I’m trying to do.

Thank you so much! Let me look into it. I appreciate your great help.

Sponsor our Newsletter | Privacy Policy | Terms of Service