0

I've successfully populated a HTML form dropdown menu using this method, so I know it works, the difference this time is I'm trying to populate text boxes with content (account details), but it's just not working.

PHP:

try {
        $sql = "SELECT Firstname, Surname, Email FROM `users`;";
        $result = $pdo->query($sql);


    }
    catch (PDOException $e){
        echo "There was an error whilst fetching the users information:" .$e->getMessage();
        exit();
    }

    while($row=$result->fetch()){
        $displayinfo[] = array('UserFirstName' => $row['Firstname'],
            'UserSurname' => $row['Surname'], 
            'UserEmail' => $row['Email']);
    }

HTML SIDE:

<?php foreach($displayinfo as $info): ?>
                <?php echo "<input type="text" name="firstname" value=". $info['UserFirstName'] ."><br>"
                            ?>
                <?php endforeach; ?>    

This seems to show a

Syntax error, unexpected T_String, expecting ',' or ';'

Any help would be appreciated

2
  • Quotes are not escaped, it brakes the string : "<input type="text" name="firstname" value=". $info['UserFirstName'] ."><br>". You can change the quotes of attributes to single quotes '. Commented May 3, 2017 at 14:05
  • You have a quote mismatch when outputting the html - use single quotes within the input element perhaps Commented May 3, 2017 at 14:05

2 Answers 2

1

The problem is in:

<?php echo "<input type="text" name="firstname" value=". $info['UserFirstName'] ."><br>"

You need to use the single '

<?php echo '<input type="text" name="firstname" value='. $info['UserFirstName'] .'><br>';
Sign up to request clarification or add additional context in comments.

Comments

1

You should escape double quotes with backslash inside of input.

Ex: echo "<input type=\"text\"/>".

Or use single quotes.

Ex: echo '<input type="text"/>'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.