Jump to content

error in php insert


duncan_cowan

Recommended Posts

when i run this script it always says "ERROR IN INSERT!!" what is wrong with it please?::

<?phprequire("protected/db_connect.php");$result = mysql_query("SELECT * FROM unactivated_users WHERE act_num = '".$_GET['act_num']."'");$row = mysql_fetch_array($result);$_POST['password'] = md5($_POST['password']);if ($row['password']==$_POST['password']) {mysql_query("INSERT  INTO users SELECT username, password, regdate, email, location, show_email, last_login, rank, army_species, game_rank, FROM unactivated_users WHERE act_num = '".$row['act_num']."'")or die("ERROR IN INSERT!!");mysql_query("DELETE FROM unactivated_users WHERE act_num = '".$row['act_num']."'")or die("ERROR IN DELETE");} else {die("ERROR!!");}header('Location: http://www.wasper-rocker.co.uk/activate.php?act=1')?>

Link to comment
Share on other sites

Well, because the insert statement is messed up.There's a hanging comma, that might be the only problem, but I haven't tried using a select statement in an insert statement. It might be possible, I'm not sure. Instead of just displaying some random text telling you there is an error, it is always much more helpful if you have it give you the error message. You can use the mysql_error() function to return it. or die (mysql_error());Also, it might be easier to have a field in your users table to say whether the user is active, instead of two tables. Just have an active field, start it as 0, and set it to 1 when the user gets activated.

Link to comment
Share on other sites

I think there is a problem in the quotations: try to put $row['act_num'] in another variable like $actand then write the query as follows:mysql_query("INSERT INTO users SELECT username, password, regdate, email, location, show_email, last_login, rank, army_species, game_rank, FROM unactivated_users WHERE act_num = '".$act."'")or die("ERROR IN INSERT!!");because you are using the simple quotation twice which may make a problem,i hope that it helps

Link to comment
Share on other sites

Well, because the insert statement is messed up.There's a hanging comma, that might be the only problem, but I haven't tried using a select statement in an insert statement. It might be possible, I'm not sure. Instead of just displaying some random text telling you there is an error, it is always much more helpful if you have it give you the error message. You can use the mysql_error() function to return it. or die (mysql_error());Also, it might be easier to have a field in your users table to say whether the user is active, instead of two tables. Just have an active field, start it as 0, and set it to 1 when the user gets activated.
i have taken your advice and just used 1 table for this the member logon is now working!!!
Link to comment
Share on other sites

I think there is a problem in the quotations: try to put $row['act_num'] in another variable like $actand then write the query as follows:mysql_query("INSERT INTO users SELECT username, password, regdate, email, location, show_email, last_login, rank, army_species, game_rank, FROM unactivated_users WHERE act_num = '".$act."'")or die("ERROR IN INSERT!!");because you are using the simple quotation twice which may make a problem,i hope that it helps
The quotes are fine, he was using them correctly. The SQL error was because of the comma after "game_rank".
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...