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. Link to comment https://forums.phpfreaks.com/topic/12211-i-can-guarantee-this-is-a-stupid-question-but/ 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')"; Link to comment https://forums.phpfreaks.com/topic/12211-i-can-guarantee-this-is-a-stupid-question-but/#findComment-46531 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] Link to comment https://forums.phpfreaks.com/topic/12211-i-can-guarantee-this-is-a-stupid-question-but/#findComment-46532 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" ? Link to comment https://forums.phpfreaks.com/topic/12211-i-can-guarantee-this-is-a-stupid-question-but/#findComment-46533 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] Link to comment https://forums.phpfreaks.com/topic/12211-i-can-guarantee-this-is-a-stupid-question-but/#findComment-46534 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! Link to comment https://forums.phpfreaks.com/topic/12211-i-can-guarantee-this-is-a-stupid-question-but/#findComment-46541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.