Jump to content

Hendz

New Members
  • Posts

    6
  • Joined

  • Last visited

Hendz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi Guys ive given this a go and im continuing to learn php. I want to check from a login section to see does the username exist in the database. Ive gotten this far but i feel like im miles away. Any suggestions would be appreciated. <?php require "config.php"; try { $pdo = new PDO("mysql:host=$host", $username, $password, $options); echo 'DB connected'; } catch (PDOException $e) { throw new PDOException($e->getMessage(), (int)$e->getCode()); } $stmt = $pdo->query('SELECT username FROM databasetest.login WHERE username = !null'); while ($row = $stmt->fetch()) { echo "\n" . PHP_EOL; echo "<br>" . PHP_EOL; echo $row['username']; }
  2. @requinix I created a new pdo Object, and fed in details of db like in config file. It doesnt throw the error anymore but then again when i run it it doesnt add given data lol. Sorry, Im php noob. im normally a java dev just learning this is stressful. class UserQuery { public function Adduser($id,$username,$email,$password){ $dsn = "mysql:dbname=test;host=127.0.0.1:3306"; $user = "root"; $passwd = "2194"; $pdo = new PDO($dsn, $user, $passwd); $sql =("INSERT INTO test.user (id, username, email, password) VALUES ('$id', '$username', '$email',$password)"); $pdo->exec($sql); } }
  3. Yeah, i understand it needs to exist but ive read so much and cant figure it out. any hints to guide me in the right direction to solve this problem ?
  4. <?php class UserQuery { public function Adduser($id,$username,$email,$password) { $conn = new Config(); $sql =("INSERT INTO test.user (id, username, email, password) VALUES ('$id', '$username', '$email',$password)"); $conn->exec($sql); } } getting an "exec doesnt exist " error, saying exec doesnt exist in my db file. it doesnt need to exist does it ? anyone any idea why ?
  5. 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
  6. 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 ??
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.