when I press submit..I'll get this message with my form
Warning: Supplied argument is not a valid MySQL result resource in /usr/local/apache/htdocs/phpgroupware/finaltest.php on line 46
mySQL error: Error saving information to database.
could anyone one out there tell me why?
the original code is
<head>
<title>database testing</title>
</head>
<body>
<?php
function print_error($var)
{
if (isset($var)) echo " *" . $var;
}
$db = mysql_connect( "localhost", "root");
mysql_select_db( "phpgroupware", $db);
$id_result = mysql_db_query($db, "select account_lid from accounts where account_lid='".$HTTP_POST_VARS[ "loginid"]. "'");
if (isset($HTTP_POST_VARS[ "submit"]))
{
if (empty($HTTP_POST_VARS[ "firstname"]))
$errors[ "firstname"] = "Please enter your first name!";
elseif (strlen($HTTP_POST_VARS[ "firstname"]) > 32)
$errors[ "firstname"] = "Firstname must be less than 32 characters long!";
if (empty($HTTP_POST_VARS[ "lastname"]))
$errors[ "lastname"] = "Please enter your last name!";
elseif (strlen($HTTP_POST_VARS[ "lastname"]) > 32)
$errors[ "lastname"] = "Lastname must be less than 32 characters long!";
if (empty($HTTP_POST_VARS[ "address"]))
$errors[ "address"] = "Please enter your address!";
if (empty($HTTP_POST_VARS[ "town"]))
$errors[ "town"] = "Please enter town!";
if (empty($HTTP_POST_VARS[ "state"]))
$errors[ "state"] = "Please enter state!";
if (empty($HTTP_POST_VARS[ "country"]))
$errors[ "country"] = "Please enter country!";
if (empty($HTTP_POST_VARS[ "postcode"]))
$errors[ "postcode"] = "Please enter country!";
if (empty($HTTP_POST_VARS[ "telephone"]))
$errors[ "telephone"] = "Please enter telephone!";
if (empty($HTTP_POST_VARS[ "loginid"]))
$errors[ "loginid"] = "Please enter a userid!";
elseif (strlen($HTTP_POST_VARS[ "loginid"]) < 4)
$errors[ "loginid"] = "LoginID must be greater than 4 characters!";
elseif (strlen($HTTP_POST_VARS[ "loginid"]) > 10)
$errors[ "loginid"] = "LoginID must be less than 11 characters!";
elseif (mysql_num_rows($id_result) > 0)
$errors[ "loginid"] = "LoginID already used, please choose another ID!";
if (empty($HTTP_POST_VARS[ "password"]))
$errors[ "password"] = "Please enter password!";
elseif (strlen($HTTP_POST_VARS[ "password"]) < 4)
$errors[ "password"] = "Password must be greater than 4 characters!";
if (empty($HTTP_POST_VARS[ "password"]))
$errors[ "password2"] = "Please enter password!";
elseif (strlen($HTTP_POST_VARS[ "password"]) < 4)
$errors[ "password2"] = "Password must be greater than 4 characters!";
if ($HTTP_POST_VARS[ "password"] != $HTTP_POST_VARS[ "password2"])
$errors[ "password2"] = "Not the same password";
}
if ((empty($errors)) && (isset($HTTP_POST_VARS[ "submit"])))
{
if (!mysql_db_query($db, "insert into accounts (account_lid,account_pwd,account_password,account_firstname,account_lastname,account_address,account_town,account_state,account_country,account_postcode,account_telephone) values ('$loginid','$password','$password2','$firstname','$lastname','$address','$town','$state','$country','$postcode','$telephone')"))
die( "mySQL error: Error saving information to database.");
echo "Thank you! Information saved.\n";
} else {
?>
<form method="post" action=" <?php echo $PHP_SELF?>" name="frm1">
Login ID<br><input type="Text" name="loginid"> <?php print_error($errors[ "loginid"]); ?><br><br>
Password<br><input type="password" name="password"> <?php print_error($errors[ "password"]); ?><br><br>
Re-enter Password<br><input type="password" name="password2"> <?php print_error($errors[ "password2"]); ?><br><br>
First Name<br><input type="Text" name="firstname"> <?php print_error($errors[ "firstname"]); ?><br><br>
Last Name<br><input type="Text" name="lastname"> <?php print_error($errors[ "lastname"]); ?><br><br>
Address<br><input type="Text" name="address"> <?php print_error($errors[ "address"]); ?><br><br>
Town/City<br><input type="Text" name="town"> <?php print_error($errors[ "town"]); ?><br><br>
State<br><input type="Text" name="state"> <?php print_error($errors[ "state"]); ?><br><br>
Country<br><input type="Text" name="country"> <?php print_error($errors[ "country"]); ?><br><br>
Postcode<br><input type="Text" name="postcode"> <?php print_error($errors[ "postcode"]); ?><br><br>
Telephone<br><input type="Text" name="telephone"> <?php print_error($errors[ "telephone"]); ?><br><br>
<input type="submit" name="submit" value="Register">
</form>
<?php
}
mysql_close($db);
?>
</body>
Thank You