Hi all,

I have a pdo connection script to mysql, which works fine. What im a little stuck on is that when i "include" the file, its connected, but how do i call the table to which my query is related to?

The first snippet is the connection, and the second is the insert file.

Im not new to PHP, but i am to OO.


/*** mysql hostname ***/
$hostname = 'localhost';

/*** mysql username ***/
$username = 'root';

/*** mysql password ***/
$password = 'root';

try {
    $dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
    /*** echo a message saying we have connected ***/
    echo 'Connected to database';
catch(PDOException $e)
    echo $e->getMessage();




if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email']))


//Prevent SQL injections

$username = mysql_real_escape_string($_POST['username']);

$email = mysql_real_escape_string($_POST['email']);



//Get MD5 hash of password

$password = md5($_POST['password']);


//Check to see if username exists

$sql = mysql_query("SELECT username FROM user WHERE username = 'username'");

If (mysql_num_rows($sql = 0))

die ("Username taken.");


mysql_query("INSERT INTO users (username, password, email) VALUES ( '$username', '$password', '$email')") or die (mysql_error()); echo "Account created.";





<form action="newuser.php" method="post">

Username: <input name="username" type="text" />

Password: <input type="password" name="password" />
Email: <input name="email" type="text" />

<input type="submit" value="Submit" />


What do you mean by calling the table? Also, why're you using PDO for the connection then just completely ignoring it and using mysql_query anyway? http://php.net/pdo

i am an idiot. thank you for your help.....

im learning php5 oo and java at the same time. my head is a little mangled