dangmnx's Profile User Rating: -----

Reputation: -1 Dishonored
Group:
Active Members
Active Posts:
429 (0.21 per day)
Joined:
10-April 09
Profile Views:
6,855
Last Active:
User is offline Jan 27 2014 05:18 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Chevrolet
Dream Kudos:
0

Latest Visitors

Icon   dangmnx PHP!

Posts I've Made

  1. In Topic: PDO user exists

    Posted 13 Jan 2014

    I've gotten rid of the errors, but it's still allowing me to insert a username as many times as I want.
    I tired using rowCount, to fetchColumn and etc. I don't know what else to do.

    Instead of setting the field username as unique, I would like to go a different route for users who try to enter the same username TWICE, I set a error message for that but for some reason, users are still able to enter the same username in the database twice. How can i code this part correctly to prevent that from happening?  
    
        function register(){
            $errors = array();
            
            if(isset($_POST['username'], $_POST['password'])){
                if(empty($_POST['username'])){
                    $errors[] = 'Username is required.';
                }
                if(empty($_POST['password'])){
                    $errors[] = 'Password is required.';
                }
                
                if(empty($errors)){
                    $query = "SELECT COUNT(`id`) FROM `users` WHERE `username` = :username";
                    $check = dbConnect()->prepare($query);
                    $check->bindValue(':username', $_POST['username']);
                    $check->execute();
            
                    if($check->rowCount() > 0){
                        $errors[] = 'The chosen username is already registered.';
                    }
                    
                    if(empty($errors)){
                        $query = "INSERT INTO `users` (username, password) VALUES (:username,:password)";
                        $query = dbConnect()->prepare($query);
                        $query->bindValue(':username', $_POST['username']);
                        $query->bindValue(':password', $_POST['password']);
                        
                        if(!$query->execute()){
                            $errors[] = 'Query failed to execute.';
                        } else {
                            header('Location: index.php');
                            die();
                        }
                    }
                }
            }
        }
    
    
  2. In Topic: PDO register system

    Posted 10 Jan 2014

    Thanks, saved me allot trouble!
  3. In Topic: PDO register system

    Posted 10 Jan 2014

    By making the username a unique field, would that be consider safe pratice?
  4. In Topic: <select> tag with PHP users

    Posted 4 Jan 2014

    Works fine now, except it's not submitting the data,

    <form action="process.php" method="post">
    <select name="loaders">
    <?php
    $query = dbConnect()->prepare("SELECT `firstname`, `lastname` FROM `loaders` ");
    $query->execute();
    
    foreach($query->fetchAll(PDO::FETCH_ASSOC) AS $rows){
    	echo '<option value="firstname">', $rows['firstname'], ' ', $rows['lastname'], '</option>';
    }
    ?>
    </select>
    
    


    Am I not allowed to include two $rows[] in one option value?


    Here is my process.php

    <?php
    	if(isset($_POST['firstname'], $_POST['lastname'], $_POST['notes'], $_POST['time'])){
    		require 'core/connect.php';
    
    		$query = dbConnect()->prepare("INSERT INTO `loaders` (firstname, lastname, notes, time) VALUES (:firstname, :lastname, :notes, :time)");
    		
    		$query->bindParam(':firstname', $_POST['firstname']);
    		$query->bindParam(':lastname', $_POST['lastname']);
    		$query->bindParam(':notes', $_POST['notes']);
    		$query->bindParam(':time', $_POST['time']);
    		
    		if($query->execute()){
    			header('Location: index.php');
    		} else {
    			echo 'There has been an error';
    		}
    	}
    ?>
    
    
  5. In Topic: Isset & Session issues

    Posted 21 Dec 2013

    Alright, I removed the session_start(); off connect.php and added it to profile.php

    <?php 
    session_start();
    
    if(isset($_SESSION['username'])){
    	include 'core/db/connect.php';
    
    	$username = $_SESSION['username'];
    
    	$query = dbConnect()->prepare("SELECT username FROM users WHERE username = :username");
    	$query->execute(array(':username' => $username));
    	$row = $query->fetch();
    
    	echo 'Logged in as: ', $row['username'];
    }
    
    ?>
    

My Information

Member Title:
D.I.C Regular
Age:
25 years old
Birthday:
November 27, 1988
Gender:
Location:
Dallas Tx
Interests:
PHP! i would like to be an expert at it one day!
Programming Languages:
HTML, and a bit of PHP,

Contact Information

E-mail:
Click here to e-mail me
AIM:
AIM  aiitexx
Website URL:
Website URL  http://www.starcraftx.com

Friends

Comments

dangmnx has no profile comments yet. Why not say hello?