So, I’ve successfully set up the columns and added the first few rows of test data into my database using phpMyAdmin on my web host. Now, the next step is to have the PHP properly set up to connect to the database. I’ve used the mysql_connect() and mysql_close() at the beginning and the end with the login credentials needed for my database entry- now, which method do I use to specify the table name? I see a pg_connect() for Postgre SQL (whatever that is). Then I need to know what PHP function do I use to write an SQL query inside of.
<?php
/*This is the scripting section for the e-mail collection box.*/
$email = " ";
$connection = mysql_connect("worldreviewgroupcom.fatcowmysql.com" , "username" , "password");
$dbconn = pg_connect("dbname=emailcollection");
if (!$connection){
die('Could not connect: ' . mysql_error());
}
function showWindowAndValidate()
{
echo'<div id="activeemailbox"><input type="checkbox" value="Yes, I would like to join the mailing list."><p>Enter the characters you see below.</p></div>' . generateRandom() . ;
}
if (isset($_POST["go"]){
$email = $_POST["go"];
if (isItAValidEmail($email)){
showWindowAndValidate();
//call a function to write the user to database
} else {
invalidEntry();
} else {
invalidEntry();
}
/*test the e-mail address submission for valid entry */
function Boolean isItAValidEmail($email){
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return false;
} else {
return true;
}
}
function invalidEntry()
{
return echo'<div id="activeemailbox"><p id="error">You didn\\'t enter a valid email, silly!</p><input type="submit" value="Go Back" onclick="goBack()"></div>';
}
function generateRandom()
{
}
function goBack()
{
header();
}
mysql_close($connection);
//end e-mail box scripting section
?>
Thank you very much for your guidance. It keeps me going.
Now, how would I move to PDO when my web host supports mySQL through phpMyAdmin? I am going to ask them now if it is possible, but I don’t see anything on any part of the web host’s site about either of these database query tools.
I see it stands for PHP Data Objects, and you can use it to create and manipulate databases completely in PHP. Now I’m out of a source of knowledge that teaches how to use it instead of MySQL.
PDO can still utilize MySQL, you just tell it to use the MySQL Driver, the reason why everyone suggests PDO, is it has security baked in, whereas the mysql functions do not.
For more information on how to convert your mysql functions to PDO, see this article (and I strongly recommend the Prepared Statements approach instead of using query())
Great resource. As I started reading, I came about this line:
On Windows, all of the PDO drivers are included in the ext folder that was created when you installed PHP from the pre-compiled binary’s archive. You only need to update your php.ini by adding or uncommenting the line:
1 extension=php_pdo_mysql.dll
The problem is that I never installed PHP, just a local testing environment, since most web hosts already have it installed.