Can't use PHP with MySQL... get an 'object expected' error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gladi8r
    New Member
    • Jan 2009
    • 4

    Can't use PHP with MySQL... get an 'object expected' error

    Hi,
    This probably has an extremely stupid answer, but I'm just beginning to learn PHP in an attempt to have a working registration program for my website. I have made the HTML and PHP the way that several tutorials online have showed me, and I want to make it so that when you register under a username, password, etc, that data goes into my MySQL database so that it can remember you the next time you log in.

    The problem is, when I run the HTML and it calls the PHP, I get an error in line 39, char 2, which doesn't even exist in my PHP file. Code 0, 'object expected'. I wish they could try to be a little more specific as to what went wrong...
    If it helps, here's my HTML code
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    <title>Register for an account on xxxx!</title>
    </head>
    <body>
    <form action="http://subdomain.mywebsite.com/submitinfo.php">
    Username:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;
    <input type="text" name="Username">
    <br />
    Full Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;
    <input type="text" name="Name">
    <br />
    Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;
    <input type="password" name="Password">
    <br />
    Confirm Password:
    <input type="password" name="Confirm Password">
    <br />
    E-mail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="E-mail">
    <br />
    Confirm E-mail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="Confirm E-mail">
    <br />
    Gender:<br />
    <input type="radio" name="Gender"> Male<br />
    <input type="radio" name="Gender"> Female<br />
    <input type="submit" name="Submit">
    </form>
    </body>
    </html>
    And the PHP code is just down to its bare bones and not transmitting everything yet, but I wanted to see if it would work first to transmit data to my database:
    Code:
    <?php
    $link = mysql_connect ("xx.x.xxx.xxx", "myusername", "mypassword")
    or die('Could not connect ' . mysql_error());
    mysql_select_db ("myusername", $link) or die('Could not select database.');
    $Username = $_POST['Username'];
    $Password = $_POST['Password'];
    $Name = $_POST['Name'];
    $Email = $_POST['E-mail'];
    
    $sql="INSERT INTO Usernames and Passwords (Username, Password, E-mail, Name) VALUES ($Username,$Password,$Email,$Name)";
    if (!mysql_query($sql,$link))
      {
      die('Error: Couldn''t insert the data.' . mysql_error());
      }
    	mysql_close($link);
    	?>
    Thanks for helping!
    --Gladi8r
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    can't make any sense of the error message either, maybe copy and post the error message directly from the browser...

    nevertheless, you are trying to access a variable you don't have. the error lies within the HTML code. in the <form> tag you don't specify the transfer method (get or post) which then defaults to "get". thus you have no $_POST data.

    furthermore, your SQL looks weird. if I read the manual right, you have to specify one table, not sure if "Usernames and Passwords" conforms to the SQL naming scheme here.

    Comment

    • gladi8r
      New Member
      • Jan 2009
      • 4

      #3
      I had made a table called Usernames and Passwords for user data earlier on my database. I inserted some data from the manager, and it didn't seem to care.
      When I changed my method to "post" in my HTML, it came back with the exact same error:
      Line: 39
      Char: 2
      Error: Object expected
      Code: 0
      URL: <Url removed - just lead to an advertising page>
      Last edited by Markus; Jan 18 '09, 01:49 PM. Reason: Edit url

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        to me it looks more like a javascript error on IE....

        Comment

        • gladi8r
          New Member
          • Jan 2009
          • 4

          #5
          Then is there any way I can fix it so that it works with my browser?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            I think so, but without knowing the javascript I cannot tell. maybe it helps if you disable javascript.

            Comment

            • gladi8r
              New Member
              • Jan 2009
              • 4

              #7
              It's just a bit odd. I've never had to do that on a registration before.

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Heya, gladi8r.

                You've probably got some spyware or malware on your computer that's causing the JS error. Try running a spyware/malware removal tool and seeing if the problem goes away.

                Alternatively, try accessing the PHP script on a different computer.

                Comment

                • Atli
                  Recognized Expert Expert
                  • Nov 2006
                  • 5062

                  #9
                  Hey, I get it now... IE's poor JavaScript support is a security mechanism :]

                  You could try installing Firefox and viewing the page in that.
                  If the error still shows up, Firefox should give you a better idea as to why and where it is happening.

                  If it doesn't, pbmods is probably right (which he usually is) and you have a spyware/malware/virus problem going on.

                  Comment

                  Working...