Hi,
I'm getting an SQL error 1136 with the following code.
The weird thing is that when i cut and paste the INSERT line from my php code into
phpMyadmin and run it, the SQL statement WORKS!
I've spent many hours trying to figure this out, but to no avail. If anyone can help, it would be greatly appreciated.
Thanks,
Justin.
PHP registration form code:
<?php
//register.php
include "./common_db.inc";
$link_id = db_connect();
mysql_select_db("register");
$country_array = enum_options('usercountry', $link_id);
mysql_close($link_id);
function register_form() {
global $username, $usercountry, $useremail, $userprofile, $country_array;
global $PHP_SELF;
?>
<CENTER><H3>Create your account!</H3></CENTER>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="register">
<DIV ALIGN="CENTER"><CENTER><TABLE BORDER="1" WIDTH="90%">
<TR>
<TR>
<TH WIDTH="30%" NOWRAP>Full Name</TH>
<TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="username"
VALUE="<?php echo $username ?>" SIZE="20"></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Country</TH>
<TD WIDTH="70%"><SELECT NAME="usercountry" SIZE="1">
<?php
for($i=0; $i < count($country_array); $i++) {
if(!isset($usercountry) && $i == 0) {
echo "<OPTION SELECTED VALUE=\"". $country_array[$i] .
"\">" . $country_array[$i] . "</OPTION>\n";
}
else if($usercountry == $country_array[$i]) {
echo "<OPTION SELECTED VALUE=\"". $country_array[$i] . "\">" .
$country_array[$i] . "</OPTION>\n";
}
else {
echo "<OPTION VALUE=\"". $country_array[$i] . "\">" .
$country_array[$i] . "</OPTION>\n";
}
}
?>
</SELECT></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Email</TH>
<TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="useremail" SIZE="20"
VALUE="<?php echo $useremail ?>"></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Profile</TH>
<TD WIDTH="70%"><TEXTAREA ROWS="5" COLS="40"
NAME="userprofile"></TEXTAREA></TD>
</TR>
<TR>
<TH WIDTH="30%" COLSPAN="2" NOWRAP>
<INPUT TYPE="SUBMIT" VALUE="Submit">
<INPUT TYPE="RESET" VALUE="Reset"></TH>
</TR>
</TABLE>
</CENTER></DIV>
</FORM>
<?php
}
function create_account() {
global $username, $usercountry, $useremail, $userprofile,$todays_date;
global $default_dbname, $user_tablename;
if(empty($username)) error_message("Enter your full name!");
if(empty($useremail)) error_message("Enter your email address!");
if(empty($userprofile)) $userprofile = "No Comment.";
$link_id = db_connect($default_dbname);
$todays_date = date("mdy");
$query = "INSERT INTO user VALUES(15, '$username', '$usercountry', '$useremail', '$userprofile', '$todays_date')";
echo $query;
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$usernumber = mysql_insert_id($link_id);
html_header();
?>
<CENTER><H3>
<?php echo $username ?>, thank you for registering with us!
</H3></CENTER>
<DIV ALIGN="CENTER"><CENTER><TABLE BORDER="1" WIDTH="90%">
<TR>
<TH WIDTH="30%" NOWRAP>User Number</TH>
<TD WIDTH="70%"><?php echo $usernumber ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Full Name</TH>
<TD WIDTH="70%"><?php echo $username ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Country</TH>
<TD WIDTH="70%"><?php echo $usercountry ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Email</TH>
<TD WIDTH="70%"><?php echo $useremail ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Profile</TH>
<TD WIDTH="70%"><?php echo htmlspecialchars($userprofile) ?></TD>
</TR>
</TABLE>
</CENTER></DIV>
<?php
html_footer();
}
switch($action) {
case "register":
create_account();
break;
default:
html_header();
register_form();
html_footer();
break;
}
?>
Database structure:
CREATE TABLE user (
usernumber mediumint(10) DEFAULT '0' NOT NULL auto_increment,
username varchar(30) NOT NULL,
usercountry enum('Austria','Belgium','France','Holland','Denmark','Sweden','Finland','Norway','UK','Luxembourg','Switzerland','Spain','Portugal','Germany','Italy','Greece','Poland','Czech republic','Slovakia','Estonia','Latvia','Lithuania','Ukraine','Russia','Belarus','Moldova','Romania','Bulgaria','Slovenia','Bosnia','Croatia','Serbia','Montenegro','Macedonia','Albania') DEFAULT 'UK',
useremail varchar(50) NOT NULL,
userprofile text NOT NULL,
registerdate varchar(15) NOT NULL,
UNIQUE usernumber (usernumber)
);