For debugging this issue, in your code, after the mysql_query
call returns FALSE, use the mysql_error()
function to retrieve the MySQL error message.
For example:
} else {
echo 'Sorry, we could not register you at this time.';
// this is the problem.
// this message always returns when I attempt to register a new user.
// for debugging: echo mysql_error(); or
die('error: '. mysql_error());
The error message should indicate whether it's a syntax problem, whether the number of values you are inserting match the number of columns in the (implicit) column list, whether the rows violates a constraint, whether the user has insufficient privileges issue, etc.
With an INSERT statement, it's best practice to explicitly list the columns that are receiving the values, e.g.
INSERT INTO foo (fee, fi, fo, fum) VALUES ('e','i','o','u');
Then your statement won't be later "broken" if a new column is added, or if the order of the columns is changed.
If it's a permissions/privileges problem, then you'd need to GRANT
appropriate privileges to the mysql user you're connecting as. For example:
GRANT INSERT ON mydatabase.`Names` TO myser@myhost;
The privileges are stored in the mysql database, in the user
, db
and tables_privs
tables. Privileges can be granted globally, on all databases (... ON *.*
), at the database level (... ON mydatabase.*
) or at the individual table level (... ON mydatabase.mytable
)