I'm learning MySQL at this time and I want to create a newsletter subscribe/unsubscribe php script as my project for learning.
My web host provided me with the following that I have created.
host, username, password, and databasename.
They told me I need to create a table name with elements in it. In my case I would create a table called subscribers and the element that will be inserted will be the subscribers email address.
So basically the table should look like this.
something@domain.com
anything@domain.com
My problem is how do I create this stuff and how do I use it. Does anyone know a good MySQL book that works with PHP?
Also can you please help me out.. at least point me in the right direction to get me started.
I got the following information from a PHP book, but it doesn't explain what %s and %d are and so-on.
$host = "xxx.xxx.xxx.xxx";
$user = "admin";
$pass = "adminpass";
$dbname = "newsletter";
$tableName = "subscribers";
$stmt = "CREATE TABLE %s (EMAIL CHAR(255))";
if(!($link=mysql_connect($host,$user,$pass))) {
printError(sprintf("Error connecting to host %s, by user %s.", $host, $user));
exit;
}
if(!mysql_select_db($dbname, $link)) {
printError(sprintf("Error in selecting %s database.", $dbname));
printError(sprintf("Error: %d %s", mysql_errno($link), mysql_error($link)));
exit;
}
if(!mysql_query(sprintf($stmt,$tableName), $link)) {
printError(sprintf("Error in executing %s stmt", $stmt));
printError(sprintf("Error: %d %s", mysql_errno($link), $mysql_error($link)));
exit;
}
function printError($errorMesg) {
printf("<br> %s <br>\n", $errorMesg);
}
What do I do with this and what do I need to do after. I'm only collecting the email address and inserting it into a table.
Thanks a bunch!