I keep getting my die message ("Couldn't execute query!") I've been tryin to debug for the past 3 days and i'm missing something here. Can someone else catch my problem? By the way, I have register_globals turned off. I'm including 2 php files here. Here's my code for creating the table.......
<?php
//create_tbl.php
$dbhost = 'localhost';
$dbusername = 'root';
$dbuserpassword = '******';
$default_dbname = 'mysql';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
function db_connect() {
global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
if(!link_id) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Connection failed to the host $dbhost.";
return 0;
}
else if(empty($dbname) && !mysql_select_db($default_dbname)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}
function sql_error() {
global $MYSQL_ERRNO, $MYSQL_ERROR;
if(empty($MYSQL_ERROR)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return "$MYSQL_ERRNO: $MYSQL_ERROR";
}
$dbname = "db_invi";
$user_tablename = 'user';
$user_table_def = "usernumber MEDIUMINT(10) DEFAULT '0' NOT NULL AUTO_INCREMENT,";
$user_table_def .= "useradmin TINYINT(2) DEFAULT '0' NOT NULL,";
$user_table_def .= "userpassword VARCHAR(20) BINARY NOT NULL,";
$user_table_def .= "userzip MEDIUMINT(10) NOT NULL,";
$user_table_def .= "usercountry VARCHAR(50) DEFAULT 'America' NOT NULL,";
$user_table_def .= "useremail VARCHAR(50) NOT NULL,";
$user_table_def .= "userbday INT(10) DEFAULT '0' NOT NULL,";
$user_table_def .= "registerdate INT(10) DEFAULT '0' NOT NULL,";
$user_table_def .= "lastaccesstime TIMESTAMP(14),";
$user_table_def .= "PRIMARY KEY (usernumber)";
$link_id = db_connect();
if(!link_id) die(sql_error());
if(!mysql_select_db($dbname)) die(sql_error());
if(!mysql_query("CREATE TABLE $user_tablename ($user_table_def)")) die(sql_error());
echo "Successfully created the $user_tablename table.";
?>
And here's my error checking and inserting values into database code.......
<html>
<head></head>
<body>
<font color="black"><b><u>INVISTATION - REGISTER</u></b></font>
<br>
<br>
<font size="+2" color="black" type="Arial,Helvetica">
<?php
$HTTP_POST_VARS['date'] = date("Ymd");
$date=$HTTP_POST_VARS['date'];
$fname=$HTTP_POST_VARS['fname'];
$lname=$HTTP_POST_VARS['lname'];
$email=$HTTP_POST_VARS['email'];
$zip=$HTTP_POST_VARS['zip'];
$pass=$HTTP_POST_VARS['pass'];
$pass2=$HTTP_POST_VARS['pass2'];
$month=$HTTP_POST_VARS['month'];
$day=$HTTP_POST_VARS['day'];
$year=$HTTP_POST_VARS['year'];
$warning="";
if (!(eregi("([[:alpha:]]|-|')+$", $fname))) {
$warning[] = "Please enter a valid first name.<br> ";
}
if (!(eregi("([[:alpha:]]|-|')+$", $lname))) {
$warning[] = "Please enter a valid last name.<br> ";
}
if (!(eregi("[a-z0-9-]+(.[a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)+$", $email))) {
$warning[] = "Enter a valid email account.<br> ";
}
if (!(eregi("[[:digit:]]{5}(-[[:digit:]]{4})?$", $zip))) {
$warning[] = "Please enter a correct zip code (either xxxxx or xxxxx-xxxx).<br> ";
}
if (!(eregi("[[:alnum:]]{6,8}$", $pass))) {
$warning[] = "Please enter a password between 6-8 characters.<br> ";
}
if (!(eregi("[[:alnum:]]{6,8}$", $pass2))) {
$warning[] = "Please re-enter password.<br> ";
}
if ($month =="--") {
$warning[] = "Please select the month of your birthdate.<br> ";
}
if ($day =="--") {
$warning[] = "Please select the day of your birthdate.<br> ";
}
if (!(eregi("[[:digit:]]{4})?$", $year))) {
$warning[] = "Please enter a valid 4-digit year for your birthdate.<br> ";
}
$password = crypt($pass); // Encrypt the password.
$bday = $year.$month.$day;
$dbhost = "localhost";
$dbusername = "root";
$dbuserpassword = "*****";
$dbname = "db_invi";
$connection = @mysql_connect($dbhost, $dbusername, $dbuserpassword) or die("Couldn't connect.");
$db = @mysql_select_db($dbname) or die("Couldn't select database.");
$result = @("INSERT INTO user(userpassword,userzip,useremail,userbday,registerdate) values ('$password','$zip','$email','$bday','$date')") or die("Couldn't execute query.");
if ($pass!=$pass2) {
$warning[] = "Passwords do not match.<br> ";
}
if (!($warning == "")) {
echo "<form action=\"register2.php\" method =\"post\">";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"75%\">";
while (list($counter) = each($warning)) {
echo "
<tr>
<td align=\"left\" height=\"15\">
<font color=\"red\"><i>$warning[$counter]</i></font>
</td>
</tr>
";
}
echo "</table><br>";
include("register.php");
}
if ($warning == "") {
echo "<h4>Thank you, $fname $lname for registering. We look forward to serving your needs.</h4> <br>";
include("register.php");
}
?>
</font>
</body>
</html>