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.
<?php
/*** 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();
}
?>
and
<?php
require("includes/connectpdomysql.php");
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.";
}
?>
<html></html>
<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" />
</form>