How to get the following select statement to work

I am trying to get the following statement to work in my form but thought that both should work but I can only get the second one to work :slight_smile:

  1. if ($update_profile === $first_name) {
    echo ‘hello first name’;
    header(“Location: update_profile_firstname.php”);
    exit();

  2. if ($update_profile === ‘first_name’) {
    echo ‘hello first name’;
    header(“Location: update_profile_firstname.php”);
    exit();

This is my form code:

<form class="signup-form" action="update_profile_process.php" method="POST">
   <select name="update_profile">
      <option value="" selected="selected">Which information would you like to update?</option> 
      <option value="first_name">First Name</option>
      <option value="last_name">Last Name</option>
      <option value="username">Username</option>
      <option value="email">E-mail</option>
      <option value="password">Password</option>
     </select>
     <input type="hidden" name="csrf" value="<?php echo $csrf; ?>">
    <button type="submit" name="submit">Update Student's Information!</button>

I guess is it because I don’t have an option name attribute but just a select name attribute and that is why I can only use method 2?

what value is $first_name ?

$first_name = “firstname”;

1 Like

I think it doesn’t work because it is from the option value… not a name attribute…

When the browser submits a form, there is no way to tell from a script whether the input was a dropdown or a text field. It’s just a variable with a name and a value.

But like @anon19508339 said, it’s likely that $first_name does not have the string first_name as value.

I just think that because first_name is a value option and not a value name… maybe that is why it is not reliable at picking it up but I can still echo it though… I guess most examples do show it workiing with if ($subscription === ’ first_name’

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.