Andrew Smith
Andrew Smith

Reputation: 310

PHP Syntax Error

I posted this question a little earlier but here is the full version. I keep getting a Syntax Error which is solved when I remove the following code. So there must be a problem here, I just can't see what it is.

The syntax error is: "The topic (none) was not found in any of the reference materials currently installed".

 <?php

$ds = 'Pear';
$sd = 'Orange';
$dt = 'Banana';
$td = 'KiwiFruit';


$FoodArray=array();

echo "<p>";

foreach ($_POST ["Gender"] as $value) {
    if ($value == Female) {
    $FoodArray=array($ds, $sd, $dt, $td);
    echo "<ul>";
foreach ($FoodArray as $key => $value)

{
    echo "<li>" . $value . "</li>";
}
    echo "</ul>";
}



?>

This is the only thing stopping me from finishing a project, so I would be grateful to anyone who can help. I will try to answer a few of your questions too.

Upvotes: 0

Views: 81

Answers (5)

nl-x
nl-x

Reputation: 11832

You say

The syntax error is: "The topic (none) was not found in any of the reference materials currently installed".

This is not a PHP Syntax Error. Googling for this message makes me wonder if this has to do with Flash/Adobe/Cold Fusion/CFML.

I don't know anything about CFML though. But as most markup languages extend SGML and tend to look like XML, I would suggest you close all tags that you open.

You start a <p> but never close it with </p>. So try adding echo "</p>"; at the end.

Upvotes: 2

Jeff Lambert
Jeff Lambert

Reputation: 24661

The following code:

if($value == Female)

would produce a notice, not an error. However, I know from experience that someone inheriting code that relies on PHP bare strings being interpreted as strings will hate the person who wrote it for the rest of their life.

PHP Notice: Use of undefined constant Female - assumed 'female' in file on line #

Your error is you're missing a curly brace at the end. Not sure if it's just the code you posted here or if that is indeed the format of your code, but using correct indentation practices will help you avoid these types of issues, as well as help others spot check your code for you.

Upvotes: 1

Cleiton Souza
Cleiton Souza

Reputation: 881

Can you show me ur $_POST["Gender"] ?

And ur code have any erros...

"Female" $_POST["Gender"] Where is the

?

Try this:

$ds = 'Pear';
$sd = 'Orange';
$dt = 'Banana';
$td = 'KiwiFruit';


$FoodArray=array();

echo "<p>";

foreach ($_POST["Gender"] as $value) {
    if ($value == "Female") {
        $FoodArray=array($ds, $sd, $dt, $td);
        echo "<ul>";

        foreach ($FoodArray as $key => $value) {
            echo "<li>" . $value . "</li>";
        }

        echo "</ul>";
    }
}

echo "</p>";

Upvotes: 0

Topher Hunt
Topher Hunt

Reputation: 4804

My first thought: try removing the space between $_POST and ['Gender']. Typically I see associative arrays referenced without a space, such as : $_POST['Gender'].

Second: On the line if ($value == Female) {, what does Female reference? Maybe that should be a string, "Female"?

Third: I don't know what IDE you're using to debug your PHP, but if you run that script on a server, the error log will contain a more helpful error message that (at the very least) gives you the line number of the error it found.

Upvotes: 1

Lucas
Lucas

Reputation: 1231

It could be:

    if ($value == Female) {

should this be?

    if ($value == "Female") {

Also, is $_POST ["Gender"] an array, or a single value?

Upvotes: 0

Related Questions