Nexus10 Posted July 4, 2010 Share Posted July 4, 2010 Empty database (Users_recover), no rows in it. user_name (varchar(20)) email (varchar(150)) key (varchar(150)) $query = "INSERT INTO Users_recover (user_name, email, key) VALUES ('$user_name', '$email', '$key')"; mysql_query($query) or die("Erro"); I echo'ed $user_name, $email and $key above the query and these are all fine. Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/ Share on other sites More sharing options...
kenrbnsn Posted July 4, 2010 Share Posted July 4, 2010 Are you getting an error message? Ken Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080905 Share on other sites More sharing options...
Nexus10 Posted July 4, 2010 Author Share Posted July 4, 2010 Only whatever error message I put inside the Die statement. No other error. Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080908 Share on other sites More sharing options...
dreamwest Posted July 4, 2010 Share Posted July 4, 2010 A simpler query method: $query = "INSERT INTO `Users_recover` SET `user_name`='{$user_name}' , `email`='{$email}' , `key`='{$key} "; mysql_query($query) or die("Erro"); Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080909 Share on other sites More sharing options...
kenrbnsn Posted July 4, 2010 Share Posted July 4, 2010 Change <?php mysql_query($query) or die("Erro"); ?> to <?php mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); ?> This will give you a much better error message. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080911 Share on other sites More sharing options...
Nexus10 Posted July 4, 2010 Author Share Posted July 4, 2010 $query = "INSERT INTO `Users_recover` SET `user_name`='{$user_name}' , `email`='{$email}' , `key`='{$key} "; mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); Problem with the query: INSERT INTO `Users_recover` SET `user_name`='admin' , `email`='test@gmail.com' , `key`='78bef654a197cdc4189342034a3c5c1b You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''78bef654a197cdc4189342034a3c5c1b' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080915 Share on other sites More sharing options...
kenrbnsn Posted July 4, 2010 Share Posted July 4, 2010 In this case you forgot the closing quote on the {$key} Change <?php $query = "INSERT INTO `Users_recover` SET `user_name`='{$user_name}' , `email`='{$email}' , `key`='{$key} "; ?> to <?php $query = "INSERT INTO `Users_recover` SET `user_name`='{$user_name}' , `email`='{$email}' , `key`='{$key}' "; ?> You don't really need all the "{ }" and back-ticks, so this should work fine: <?php $query = "INSERT INTO Users_recover SET user_name='$user_name' , email='$email' , `key`='$key' "; ?> You only need the back-ticks if your using a MySQL reserved word for a fieldname. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080916 Share on other sites More sharing options...
Nexus10 Posted July 4, 2010 Author Share Posted July 4, 2010 Ah, that works thanks. So what was wrong with my original syntax? Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080917 Share on other sites More sharing options...
kenrbnsn Posted July 4, 2010 Share Posted July 4, 2010 The work "key" is probably a reserved word in MySQL. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080918 Share on other sites More sharing options...
Nexus10 Posted July 4, 2010 Author Share Posted July 4, 2010 Okay, I'm having problems with another query now also related to the above: $query = "UPDATE Users_recover SET 'key' = '$key' WHERE user_name = '$user_name'"; mysql_query($query) or die("Error: Action could not be completed. Please email test@gmail.com about this.<br />" . mysql_error()); Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''key' = 'baea9f5fb6eea96384efae608716d819' WHERE user_name = 'admin'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080934 Share on other sites More sharing options...
Nexus10 Posted July 4, 2010 Author Share Posted July 4, 2010 Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080938 Share on other sites More sharing options...
dreamwest Posted July 4, 2010 Share Posted July 4, 2010 use a backtick to define the field it the key next to the 1 on your keyboard mysql_query("UPDATE `Users_recover` SET `key` = '{$key}' WHERE `user_name` = '{$user_name}' ") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/#findComment-1080942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.