Hendz Posted February 23, 2021 Share Posted February 23, 2021 i Have this Form <form action="action_page.php" method="POST"> <div class="form-group"> <label for="email">Email address:</label> <input type="email" class="form-control" id="email"> </div> <div class="form-group"> <label for="pwd">Password:</label> <input type="password" class="form-control" id="pwd"> </div> <div class="checkbox"> <label><input type="checkbox"> Remember me</label> </div> <button type="submit" class="btn btn-default">Submit</button> </form> And im trying to pass the information into a USER class and print out the result in a action_page.php. <?php class User { private $password; private $emailAddress; function __construct() { $this->emailAddress = isset($_POST['email']) ? $_POST['email'] : null; $this->password = isset($_POST['pwd']) ? $_POST['pwd'] : null; } function start() { if (empty($this->password) || empty($this->emailAddress)) { throw new Exception("Empty Post not allowed"); } else { echo " Registration Done"; } } } $register = new User(); if(!empty($_POST)) { $register->start(); } Then in my action page i try to refernence the Object with ?php include "User.php"; $user = new User(); try { $user->start(); } catch (Exception $e) { echo "Cannot Find account"; } but it never can do it ? Anyone any ideas ?? Quote Link to comment https://forums.phpfreaks.com/topic/312203-learning-php-java-dev-with-a-headache/ Share on other sites More sharing options...
gw1500se Posted February 23, 2021 Share Posted February 23, 2021 Use 'name' not 'id' on your input fields. Quote Link to comment https://forums.phpfreaks.com/topic/312203-learning-php-java-dev-with-a-headache/#findComment-1584726 Share on other sites More sharing options...
Solution Barand Posted February 23, 2021 Solution Share Posted February 23, 2021 You will actually need both the id and the name The label/for attributes use the id, POST variables use the name. Quote Link to comment https://forums.phpfreaks.com/topic/312203-learning-php-java-dev-with-a-headache/#findComment-1584727 Share on other sites More sharing options...
Hendz Posted February 23, 2021 Author Share Posted February 23, 2021 Thanks i added the name + id and it fixed my proble. enjoying php pretty similar to Java but just getting the hang of OOP and PDO a learning experience lol Quote Link to comment https://forums.phpfreaks.com/topic/312203-learning-php-java-dev-with-a-headache/#findComment-1584728 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.