SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    drop down form to mysql help

    Please can someone see where i am going wrong with this code. When I click submit it does not update mysql database.

    The first 2 php codes are fine retrieving the names1 and name2 from the database. The problem is the drop down menu. When selected and click submit it does not insert to mysql. It is bugging me!

    Code:
    // Include database connection settings
    include('connect.inc');
    
    //SHOW NAMES FROM LOGIN
    $sql = "SELECT name1 FROM user WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "'";
    $result = mysql_query($sql) or die("Error in SQL: " . mysql_error());
    $row = mysql_fetch_array($result);
    echo $row['name1'];
    ?>
    &nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>  <?
    // Include database connection settings
    include('connect.inc');
    
    //SHOW SECOND NAME FROM LOGIN
    
    $sql = "SELECT name2 FROM user WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "'";
    $result = mysql_query($sql) or die("Error in SQL: " . mysql_error());
    $row = mysql_fetch_array($result);
    echo $row['name2'];
    ?>
    
    // THE PROBLEM IS THE FOLLOWING CODE:
    
    &nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><form action="$_POST['submit']" method="post">
          <label>sport
            <select name="sport" id="sport">
              <option>footy</option>
              <option>tennis</option>
              <option>rugby</option>
            </select>
          </label>
          <label>button
            <input type="submit" name="button" id="button" value="Submit">
          </label>
        </form>
    
        <?
       $sql = "UPDATE user SET sport = '" . mysql_real_escape_string($_POST['sport']) . "' WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "'";
    mysql_query($sql) or die("Error in SQL: " . mysql_error());  
    ?>
    
    </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><p>
        <p>            <p></p></td>
      </tr>
    </table>
    <p>&nbsp;</p>
    
    </body>
    n
    </html>
    thanks

  2. #2
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fixed

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by condy View Post
    fixed
    I'm glad you found the solution. Would you mind telling us how you fixed it?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •