By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,397 Members | 2,515 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,397 IT Pros & Developers. It's quick & easy.

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

P: 4
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
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  3. <html>
  4. <head>
  5. <title>Register for an account on xxxx!</title>
  6. </head>
  7. <body>
  8. <form action="">
  9. Username:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  10. &nbsp;
  11. <input type="text" name="Username">
  12. <br />
  13. Full Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  14. &nbsp;
  15. <input type="text" name="Name">
  16. <br />
  17. Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  18. &nbsp;
  19. <input type="password" name="Password">
  20. <br />
  21. Confirm Password:
  22. <input type="password" name="Confirm Password">
  23. <br />
  24. E-mail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  25. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  26. <input type="text" name="E-mail">
  27. <br />
  28. Confirm E-mail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  29. <input type="text" name="Confirm E-mail">
  30. <br />
  31. Gender:<br />
  32. <input type="radio" name="Gender"> Male<br />
  33. <input type="radio" name="Gender"> Female<br />
  34. <input type="submit" name="Submit">
  35. </form>
  36. </body>
  37. </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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $link = mysql_connect ("", "myusername", "mypassword")
  3. or die('Could not connect ' . mysql_error());
  4. mysql_select_db ("myusername", $link) or die('Could not select database.');
  5. $Username = $_POST['Username'];
  6. $Password = $_POST['Password'];
  7. $Name = $_POST['Name'];
  8. $Email = $_POST['E-mail'];
  10. $sql="INSERT INTO Usernames and Passwords (Username, Password, E-mail, Name) VALUES ($Username,$Password,$Email,$Name)";
  11. if (!mysql_query($sql,$link))
  12.   {
  13.   die('Error: Couldn''t insert the data.' . mysql_error());
  14.   }
  15.     mysql_close($link);
  16.     ?>
Thanks for helping!
Jan 18 '09 #1
Share this Question
Share on Google+
8 Replies

Expert Mod 5K+
P: 8,639
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.
Jan 18 '09 #2

P: 4
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>
Jan 18 '09 #3

Expert Mod 5K+
P: 8,639
to me it looks more like a javascript error on IE....
Jan 18 '09 #4

P: 4
Then is there any way I can fix it so that it works with my browser?
Jan 18 '09 #5

Expert Mod 5K+
P: 8,639
I think so, but without knowing the javascript I cannot tell. maybe it helps if you disable javascript.
Jan 18 '09 #6

P: 4
It's just a bit odd. I've never had to do that on a registration before.
Jan 18 '09 #7

Expert 5K+
P: 5,821
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.
Jan 18 '09 #8

Expert 5K+
P: 5,058
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.
Jan 18 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.