Jump to content


Photo

Parse error: parse error, unexpected $


  • Please log in to reply
6 replies to this topic

#1 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 21 March 2006 - 12:04 PM

<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>

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

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 21 March 2006 - 12:47 PM

You forgot the closing curly brace on the "while" statement.

Ken

#3 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 21 March 2006 - 12:48 PM

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:

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


that should do you
Cheers
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 21 March 2006 - 12:56 PM

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

Ken

#5 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 21 March 2006 - 08:57 PM

Thanks, I'll check it out now.

edit: Ok, I have this now:

<?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>

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.

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 21 March 2006 - 09:10 PM

The "&lt;" in this line
<?php echo "&lt;option value='$row[0]'>{$row[1]}</option>";} ?>
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

#7 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 21 March 2006 - 09:16 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users