habook2 Posted June 16, 2006 Share Posted June 16, 2006 How do I insert a variable's value into a table?Like:mysql_query ('INSERT INTO `users` (`username`, `password`, `userid`) VALUES (\'I WANT A VARIABLE HERE\', \'I WANT A VARIABLE HERE\', NULL);)When I just tried using the variables, they would actually add "$username" and "$pass" as the username and password. Quote Link to comment Share on other sites More sharing options...
joquius Posted June 16, 2006 Share Posted June 16, 2006 sql = "INSERT INTO `table` (`field_1`) VALUES ('$field_1')"; Quote Link to comment Share on other sites More sharing options...
trq Posted June 16, 2006 Share Posted June 16, 2006 Variables are only parsed when contained within double quotes, so...[code]mysql_query("INSERT INTO `users` (`username`, `password`, `userid`) VALUES ('$v1', '$v2', NULL);");[/code] Quote Link to comment Share on other sites More sharing options...
habook2 Posted June 16, 2006 Author Share Posted June 16, 2006 No, I mean the value of the variable. If, by a previous form, the variable $username had been set to "flamino", then how would I insert "flamingo" instead of "$username" ? Quote Link to comment Share on other sites More sharing options...
.josh Posted June 16, 2006 Share Posted June 16, 2006 problem is your quotes. do it like this:[code]mysql_query("insert into users (username,password,userid) values ('$username','$password','$userid')");[/code]or, if your userid is auto-generated by sql then don't include it in that list:[code]mysql_query("insert into users (username,password) values ('$username','$password')");[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted June 17, 2006 Share Posted June 17, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]No, I mean the value of the variable.[/quote]Just as I showed you! Quote Link to comment 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.