Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6877781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:38:32+00:00 2026-05-27T04:38:32+00:00

I’m working on a profile page, where a registered user can update their information.

  • 0

I’m working on a profile page, where a registered user can update their information. Because the user has already submitted their information, I would like their information from the database to populate my HTML form.

Within PHP, I’m creating the HTML form with the values filled in. However, I’ve tried creating an IF statement to determine whether an option is selected as the default value. Right now, my website is giving me a default value of the last option, Undeclared. Therefore, I’m not sure if all IF statements are evaluation as true, or if it is simply skipping to selected=selected.

Here is my HTML, which is currently embedded with PHP(<?php ?>):

<?php

// Connect to MySQL
$db = mysql_connect("", "xxx", "xxx");

if (!$db)
{
    exit("Error - Could not connect to MySQL");
}

$er = mysql_select_db("cs329e_fall11_nemo008", $db);

if (!$er)
{
    exit("Error - Could not select the database");
}

$query = "SELECT *
FROM tblMembers
WHERE Username = 'fzr11017' ";

$result = mysql_query($query);

if (!$result)
{
    print("Error - The query could not be executed");
    $error = mysql_error();
    print("<p>:" . $error . "</p>");
    exit;
}

$row = mysql_fetch_array($result);

print <<<FORM

<form id="frmRegister" action="update.php" method="post" onsubmit="return Validate()" >
<table>
    <tr>
        <th><br /></th>
        <td><br /></td>
    </tr>
    <tr>
        <th align="left">Username:</th>
        <td><input type="text" name="Username" maxlength="10" value=$row[Username] readonly="readonly"/></td>
    </tr>
    <tr>
        <th align="left">First Name:</th>
        <td><input type="text" name="FirstName" value=$row[FirstName] readonly="readonly" /></td>
    </tr>
    <tr>
        <th align="left">Last Name:</th>
        <td><input type="text" name="LastName" value=$row[LastName] readonly="readonly" /></td>
    </tr>
    <tr>
        <th align="left">Email Address:</th>
        <td><input type="text" name="Email" value=$row[Email] /></td>
    </tr>
    <tr>
        <th align="left">Phone Number:</th>
        <td><input type="text" name="Phone" maxlength="10" value=$row[Phone] /></td>
    </tr>
    <tr>
        <th align="left">Year:</th>
        <td>
            <select name="Year" >
                <option if(strcmp($row[Year], 'Freshman') == 0){ selected="selected"} >Freshman</option>
                <option if(strcmp($row[Year], 'Sophomore') == 0){ selected="selected"} >Sophomore</option>
                <option if(strcmp($row[Year], 'Junior') == 0){ selected="selected"} >Junior</option>
                <option if(strcmp($row[Year], 'Senior') == 0){ selected="selected"} >Senior</option>
            </select>
        </td>
    </tr>
    <tr>
        <th align="left">Primary Major:</th>
        <td>
            <select name="Major">
                <option if($row[Major] == Accounting){ selected="selected"}>Accounting</option>
                <option if($row[Major] == Business Honors Program){ selected="selected"}>Business Honors Program</option>
                <option if($row[Major] == Engineering Route to Business){ selected="selected"}>Engineering Route to Business</option>
                <option if($row[Major] == Finance){ selected="selected"}>Finance</option>
                <option if($row[Major] == International Business){ selected="selected"}>International Business</option>
                <option if($row[Major] == Management){ selected="selected"}>Management</option>
                <option if($row[Major] == Management Information Systems){ selected="selected"}>Management Information Systems</option>
                <option if($row[Major] == Marketing){ selected="selected"}>Marketing</option>
                <option if($row[Major] == MPA){ selected="selected"}>MPA</option>
                <option if($row[Major] == Supply Chain Management){ selected="selected"}>Supply Chain Management</option>
                <option if($row[Major] == Undeclared){ selected="selected"}>Undeclared</option>
            </select>
        </td>
    </tr>
    <tr>
        <th><br /></th>
        <td><br /></td>
    </tr>
    <tr>
        <td align="center"><input type="submit" name="btnSubmit" value="Submit" /></td>
        <td align="center"><input type="reset" value="Reset" /></td>
    </tr>
</table>
</form>
FORM;

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:38:33+00:00Added an answer on May 27, 2026 at 4:38 am

    You seem to be missing any tags in your code, which means that nothing is being processed. Something more along the lines of this should be used:

    <option <?php if($row["Major"] == "Accounting"){ echo "selected"; } ?>>Accounting</option>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.