Jump to content

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?
Link to comment
https://forums.phpfreaks.com/topic/5409-parse-error-parse-error-unexpected/
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
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.
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.