Page 1 of 1

Newbie help

Posted: Fri Feb 17, 2012 12:52 pm
by skylers
Hi-
I'm fairly new to php specifically and I'm having a problem referencing object functions. My html has this:

Code: Select all

<?php
    $db = new DB();
?>
Then my form has this:

Code: Select all

<form name='loginForm' method='post' action='<? $db->login(); ?>' onSubmit='validateForm();'>
And my DB object looks generally like this:

Code: Select all

<?php
    Class DB {
        private $dbUsername;
        private $dbPassword;
        private $dbServer;

        function login() {
            [do db interactions]
        }
}
When I run all this, the content where my form is and anything after doesn't show up at all on the page. Whats wrong? I really appreciate the help!

Re: Newbie help

Posted: Fri Feb 17, 2012 2:08 pm
by xtiano77
The action property of the form tag needs the name or target file that is going to process the form submission. You can leave the code the way it is as long as the method returns the name of the target script that will process the form.

Re: Newbie help

Posted: Fri Feb 17, 2012 2:15 pm
by skylers
How would that look?

Code: Select all

<form method='post' action='../path/to/file/DB.php<? $db->login() ?>'>
or am I way off base there?

or are you talking about at the end of my javascript validation? Or do I need a helper method in this file that redirects to the actual DB.php file?

Thanks again for your reply!

Sky

Re: Newbie help

Posted: Sun Feb 19, 2012 7:21 pm
by xtiano77
Your HTML form:

<form method='post' action='../path/to/file/DB.php' onSubmit='validateForm( );'>

Your action file (“DB.php”):

Code: Select all

<?php
     // your code here...
     $db = new DB( );
     $db -> login( );
     // your code here...
?>