Jump to content

Archived

This topic is now archived and is closed to further replies.

habook2

I can guarantee this is a stupid question, but...

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Variables are only parsed when contained within double quotes, so...
[code]
mysql_query("INSERT INTO `users` (`username`, `password`, `userid`) VALUES ('$v1', '$v2', NULL);");
[/code]

Share this post


Link to post
Share on other sites
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" ?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]No, I mean the value of the variable.[/quote]
Just as I showed you!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.