Jump to content

Sarkons

Members
  • Posts

    6
  • Joined

  • Last visited

Sarkons's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yeah i was unaware of the meaning "pseudo", thanks for filling me in! Anywho now everything is working well. Thank you Psycho and Barand much appreciated!
  2. Sorry about that Heres what i have if($execute){ $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $sthandre = $con->prepare("SELECT book.id, book.title, book.url, book.viewer, book.sub_id, subj.subject_id, subj.name FROM book LEFT JOIN subj ON(book.sub_id = subj.subject_id) WHERE book.username_id = :yourid ORDER BY subj.subject_id"); $sthandre->execute(array(':yourid'=>$userid)); while ($row = $sthandre->fetch()){ $bmid = ($row ['id']); $title = ($row ['title']); $url = ($row ['url']); $audience= ucfirst($row ['viewer']); $subid = ($row ['subject_id']); $subjectname = ($row ['name']); //somehow if the subject name is a duplicate echo it once and carry on with the other variables looping $prev = ''; while(next ($row)){ if ($subject != $prev) { $subjectoutput = $subject; $prev = $subject; } else $subjectoutput = ''; echo $subjectoutput; } } }
  3. Hi Barand, Thanks for the reply. I tried that and unfortuantly it did not work, the subjects still echo duplicates. Thanks!
  4. Hey Guys! I've been trying to figure out how to tackle a solution for this, on the site you have a combobox to select a subject and add other fields aswell. My problem is if the subjects are the same group them together and only echo the subject once but echo the other fields aswell. if($execute){ $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $sthandre = $con->prepare("SELECT book.id, book.title, book.url, book.viewer, book.sub_id, subj.subject_id, subj.name FROM book LEFT JOIN subj ON(book.sub_id = subj.subject_id) WHERE book.username_id = :yourid ORDER BY subj.subject_id"); $sthandre->execute(array(':yourid'=>$userid)); while ($row = $sthandre->fetch()){ $bmid = ($row ['id']); $title = ($row ['title']); $url = ($row ['url']); $audience= ucfirst($row ['viewer']); $subid = ($row ['subject_id']); $subjectname = ($row ['name']); //somehow if the subject name is a duplicate echo it once and carry on with the other variables looping echo "$subjectname,$title,$audience" } } the current output; Subject | Title |audience ------------------------------------------------------ |Classic | The Who | Everyone| |Classic | The End | Mature | |Classic | Happy | Teen | |Other | Last | Everyone | what im hoping it to be; Subject | Title |audience ------------------------------------------------------ |Classic | The Who | Everyone| | | The End | Mature | | | Happy | Teen | |Other | Last | Everyone | it will be in another format its just easier to explain in a grid format. Thanks i appreciate it!
  5. I have it on my user.php page which contains; <?php class Users { public $username = null; public $password = null; public $salt = "Zo4rU5Z1YyKJAASY0PT6EUg7BBYdlEhPaNLuxAwU8lqu1ElzHv0Ri7EM6irpx5w"; public $email = null; public $first = null; public $middle = null; public $last = null; public $question = null; public $answer = null; public function __construct( $data = array() ) { if( isset( $data['username'] ) ) $this->username = stripslashes( strip_tags( $data['username'] ) ); if( isset( $data['password'] ) ) $this->password = stripslashes( strip_tags( $data['password'] ) ); if( isset( $data['email'] ) ) $this->email = stripslashes( strip_tags( $data['email'] ) ); if( isset( $data['first'] ) ) $this->first = stripslashes( strip_tags( $data['first'] ) ); if( isset( $data['middle'] ) ) $this->middle = stripslashes( strip_tags( $data['middle'] ) ); if( isset( $data['last'] ) ) $this->last = stripslashes( strip_tags( $data['last'] ) ); if( isset( $data['question'] ) ) $this->question = stripslashes( strip_tags( $data['question'] ) ); if( isset( $data['answer'] ) ) $this->answer = stripslashes( strip_tags( $data['answer'] ) ); } public function storeFormValues( $params ) { //store the parameters $this->__construct( $params ); } public function userLogin() { $success = false; try{ $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "SELECT * FROM users WHERE username = :username AND password = :password LIMIT 1"; $stmt = $con->prepare( $sql ); $stmt->bindValue( "username", $this->username, PDO::PARAM_STR ); $stmt->bindValue( "password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR ); $stmt->execute(); $valid = $stmt->fetchColumn(); if( $valid ) { $success = true; } $con = null; return $success; }catch (PDOException $e) { echo $e->getMessage(); return $success; } } public function register() { $correct = false; try { $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "INSERT INTO users (username, password, email, first, middle, last, question, answer) VALUES(:username, :password, :email, :first, :middle, :last, :question, :answer)"; $stmt = $con->prepare( $sql ); $stmt->bindValue( "username", $this->username, PDO::PARAM_STR ); $stmt->bindValue( "password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR ); $stmt->bindValue( "email", $this->email, PDO::PARAM_STR ); $stmt->bindValue( "first", $this->first, PDO::PARAM_STR ); $stmt->bindValue( "middle", $this->middle, PDO::PARAM_STR ); $stmt->bindValue( "last", $this->last, PDO::PARAM_STR ); $stmt->bindValue( "question", $this->question, PDO::PARAM_STR ); $stmt->bindValue( "answer", $this->answer, PDO::PARAM_STR ); $stmt->execute(); return "Registration Successful <br/> <a href='index.php'>Login Now</a>"; }catch( PDOException $e ) { return $e->getMessage(); } } } ?>
  6. Hi There, I'm rather new to php so please bare with me! After many attempts i still have been unable to return success, even existing usernames still come up as free. this is the code i've been attempting to use; <?php }else{ $usr = new Users; $usr->storeFormValues( $_POST ); if( $_POST['password'] == $_POST['confpass'] ) { //passwords do match// } else { echo "Passwords do not match"; exit; } $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $stmt = $con->prepare("SELECT COUNT (*) FROM users WHERE username = :username"); if ($stmt->fetchColumn() > 0) { echo "username is taken"; }else{ echo "username is free"; } } Thanks, I Appreciate it!
×
×
  • 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.