SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast epic1231's Avatar
    Join Date
    Sep 2003
    Location
    NJ
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Simple DB Info from Form

    Hey everyone, I have a form which a user generates a special username to whatever they want.. The username needs to be added to my db but for some reason it's not..

    Here is the code

    PHP Code:
    <?php

    require_once 'topwel.php';

    $username $_GET['username']; //this gets the value

    //now check if $newuser is empty or full in order to run the mysql query

    if($username != '') {

    //put the mysql query here

    } else {

    //nothing here
    }
          
    //  *************************************************************************
          //  INSERT Username
          //  

    $username mysql_query("INSERT INTO rxsix_fbi (username) VALUES('".$username."') WHERE UID = $user",$conn);

    ?>

    <div class=mainback>

    <form action="welcome.php" method="post" onsubmit="return checkForm(this);">

            <table align="center" border="0" cellpadding="2" cellspacing="5" width="90%">
              <tr>
                <td>
                  <br/>

                  <h3>Please Choose a Username</h3>

                  <p>FBI Agent 
                  <input id="uname" name="uname" type="text" size="50" value="<?php echo $username?>" /> <input type="submit" name="submit" value="Continue" /></p>
                  <br />

                </td>
              </tr>
            </table>
                               
          </form>


    <script>
        <!--

           function checkForm(form)
           {
                //  params is the array of <input /> tags passed by the form

                var params = form.serialize();
                var completed = true;
               
                if(params.username.length <= 0)
                {
                    colourRed(document.getElementById('username_p'));
                    completed = false;
                 
                }
               
                if(completed)
                {
                     return true;
                }
                else
                {
                     return false;
                }
           }

           function colourRed(obj)
           {
                var r = 255, b = 0, g = 0;
                var color = r+', '+g+', '+b;
                obj.setStyle('color', 'rgb('+color+')');
           }

       //-->
    </script>

    </div>
    Last edited by epic1231; Jul 23, 2009 at 13:08. Reason: fixing spelling mistake
    Cobra-Games.net -- Facebook Games

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    You have the query in the wrong place and are overwriting the $username variable.

    try:

    PHP Code:
    require_once 'topwel.php';

    $username $_GET['username']; //this gets the value

    if($username != '') {
        
    $sql mysql_query("INSERT INTO rxsix_fbi (username) VALUES('".$username."') WHERE UID = $user",$conn);

    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Enthusiast epic1231's Avatar
    Join Date
    Sep 2003
    Location
    NJ
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a way to debug something like this.. It's still not adding anything to the DB.. My table structure is setup like

    Table Name cu_users

    uid userid username ucash etc...

    Code:
    <?php
    require_once 'topwel.php';
    
    $username = $_GET['username']; //this gets the value
    
    if($username != '') {
        $sql = mysql_query("INSERT INTO rxsix_fbi (username) VALUES('".$username."') WHERE UID = $userID",$conn);
    } 
    ?>
    
    <div class=mainback>
    
    <form action="welcome.php" method="post" onsubmit="return checkForm(this);">
    
            <table align="center" border="0" cellpadding="2" cellspacing="5" width="90%">
              <tr>
                <td>
                  <br/>
    
                  <h3>Please Choose a Username</h3>
    
                  <p>FBI Agent 
                  <input id="username" name="username" type="text" size="50" value="<?php echo $username; ?>" /> <input type="submit" name="submit" value="Continue" /></p>
                  <br />
    
                </td>
              </tr>
            </table>
                               
          </form>
    
    
    <script>
        <!--
    
           function checkForm(form)
           {
                //  params is the array of <input /> tags passed by the form
    
                var params = form.serialize();
                var completed = true;
               
                if(params.username.length <= 0)
                {
                    colourRed(document.getElementById('username_p'));
                    completed = false;
                 
                }
               
                if(completed)
                {
                     return true;
                }
                else
                {
                     return false;
                }
           }
    
           function colourRed(obj)
           {
                var r = 255, b = 0, g = 0;
                var color = r+', '+g+', '+b;
                obj.setStyle('color', 'rgb('+color+')');
           }
    
       //-->
    </script>
    
    </div>
    Cobra-Games.net -- Facebook Games

  4. #4
    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)
    the form uses the method post, so try $_POST instead of $_GET


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
  •