Jump to content

Archived

This topic is now archived and is closed to further replies.

lpxxfaintxx

Parse error: parse error, unexpected $

Recommended Posts

[code] <html>
  <p>Category:
    <label>
    <select name="Category" id="Category"><option value="NULL">Choose A Category:</option>
    <?php $query = 'SELECT * FROM registered_cat ORDER BY cat_name ASC';
    $result = mysql_query ($query);
    while ($row = mysql_fetch_array
        ($result, MYSQL_NUM)) {
        echo "<option value='$row[0]'>$row[1]</option>"; ?>
    </select></html>[/code]

I don't know where it went wrong, but its not working no matter what I tried. Can anyone spot the error?

Share this post


Link to post
Share on other sites
You forgot the closing curly brace on the "while" statement.

Ken

Share this post


Link to post
Share on other sites
you have two problems, both in the same block. you need to treat array values differently to normal variables when putting them in double quotes (use curly braces {}), and you also need a closing bracket for your while loop. so:

[code]
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
   echo "<option value='{$row[0]}'>{$row[1]}</option>"; <-- curly braces
} <--- you forgot this
?>

[/code]

that should do you
Cheers

Share this post


Link to post
Share on other sites
No, actually they way the OP has that statement does work. Try it with the following example code:
[code]<?php
$row = array('xyz','123');
echo "&lt;option value='$row[0]'>$row[1]</option>"; ?>
?>[/code]

Ken

Share this post


Link to post
Share on other sites
Thanks, I'll check it out now.

edit: Ok, I have this now:

[code]<?php
$username = $userdata['user_name'];
?>
<center><form enctype='multipart/form-data' action='upload.php' method='post'>
  <p>Image Name:
    <label>
    <input type="text" name="textfield" />
    </label>
  </p>
  <p>Image Description: <br />
      <label>
      <textarea name="description" cols="50" rows="2"></textarea>
      </label>
  </p>
  <p>Category:
    <label>
    <select name="Category" id="Category"><option value="NULL">Choose A Category:</option>
    <?php $query = 'SELECT * FROM registered_cat ORDER BY cat_name ASC';
    $result = mysql_query ($query);
    while ($row = mysql_fetch_array
        ($result, MYSQL_NUM)) {
echo "&lt;option value='$row[0]'>{$row[1]}</option>";} ?>

    </select>


    </label>
    <br />
      <input type='hidden' name='MAX_FILE_SIZE' value='1048576'>
      <input name='userfile' type='file'>
    
      <input type='submit' value='Upload'>
  </p>
  <p>&nbsp;</p>
</form>[/code]

but the options "Category" doesn't grab the information from the database. It just comes out blank, the MySQL database exists and has values in it, so it must be the PHP.

Share this post


Link to post
Share on other sites
The "&lt;" in this line
[code]<?php echo "&lt;option value='$row[0]'>{$row[1]}</option>";} ?>[/code]
was just to show one of the other people that your original code on this line was fine (It prevents the browser from interpreting the line). I didn't mean for you to change your line, put back the "<" character there.

Ken

Share this post


Link to post
Share on other sites
Haha, I knew that :P

(Sarcasm)

The only thing I hate about PHP is the syntax. One little syntax error, and the whole script doesnt work. Hehe, other than that, I'm in love.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.