bftwofreak Posted February 24, 2010 Share Posted February 24, 2010 I've been getting the following error since I implemented an xml file to hold certain variable values. Fatal error: Call to a member function getElementsByTagName() on a non-object in F:\Website\church\req\install\db_conn.php on line 12 This is the xml document: <?xml version="1.0" encoding="utf-8"?> <settings> <server>se.r.v.er</server> <login>root</login> <pass>password</pass> </settings> and this is the php file <?php if (isset($_SESSION['form']) && $_SESSION['form'] == $_POST['form']) { } else { $_SESSION['form'] = rand(0,100000000); echo '<td style="align: center; width: 100%;">'; if (DB_FILE_EXISTS) { echo '<u>Current Settings</u><br/>'; print_r('Server: ' . $mysql->getElementsByTagName('server') . '<br/>'); print_r('Login: ' . $mysql->getElementsByTagName('login') . '<br/>'); print_r('Password: ' . $mysql->getElementsByTagName('pass') . '<br/>'); } echo '<br/><br/>'; echo '<form method="post"><input type="hidden" name="form" value="' . $_SESSION['form'] . '">'; echo '<input type="text" name="server">'; echo '<input type="text" name="login">'; echo '<input type="password" name="pass">'; echo '<input type="submit" value="Submit"></form>'; } ?> There is another file that opens the xml document as a new DOM document. Any ideas as to why I'm getting this error? Line 12 is the linke trying to display the server value. Link to comment https://forums.phpfreaks.com/topic/193180-xml-dom-non-object-error-with-getelementsbytagname/ Share on other sites More sharing options...
jl5501 Posted February 24, 2010 Share Posted February 24, 2010 You are trying to call a member function in an object instance called $mysql. Your code does not show you ever instanciating this object instance, and the error message is saying that there is no object called $mysql so I would guess that you are not instanciating it anywhere. Link to comment https://forums.phpfreaks.com/topic/193180-xml-dom-non-object-error-with-getelementsbytagname/#findComment-1017271 Share on other sites More sharing options...
bftwofreak Posted February 24, 2010 Author Share Posted February 24, 2010 Well the mysql object is defined in another file that include()'s this php page. Should the member 'server' result in a string data type if it's from the XML file? Link to comment https://forums.phpfreaks.com/topic/193180-xml-dom-non-object-error-with-getelementsbytagname/#findComment-1017457 Share on other sites More sharing options...
jl5501 Posted February 24, 2010 Share Posted February 24, 2010 The point is, that when you call $mysql->getElementsByTagName('server'), the variable $mysql does not exist, at least not as an object. Link to comment https://forums.phpfreaks.com/topic/193180-xml-dom-non-object-error-with-getelementsbytagname/#findComment-1017461 Share on other sites More sharing options...
bftwofreak Posted February 24, 2010 Author Share Posted February 24, 2010 So how can I get it to become an object? Link to comment https://forums.phpfreaks.com/topic/193180-xml-dom-non-object-error-with-getelementsbytagname/#findComment-1017557 Share on other sites More sharing options...
jl5501 Posted February 24, 2010 Share Posted February 24, 2010 You will have a class called Something ( I do not know what in your case) And you will need to do $mysql = new Something() (replace with your class name) Link to comment https://forums.phpfreaks.com/topic/193180-xml-dom-non-object-error-with-getelementsbytagname/#findComment-1017573 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.