Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
saumya
Forum Contributor
Posts: 193 Joined: Sun Jan 30, 2005 10:21 pm
Post
by saumya » Fri Sep 15, 2006 11:44 am
Hi,
as of my code goes it puts the variables inside database not their values.Please help, here is the code
Code: Select all
$sql = "INSERT INTO `nt_activity` (`activity_name`, `activity_description`) VALUES (\'$name_activity\',\'$add_r\');";
mysql_query($sql);
thanking you
saumya
saumya
Forum Contributor
Posts: 193 Joined: Sun Jan 30, 2005 10:21 pm
Post
by saumya » Fri Sep 15, 2006 11:55 am
Sorry guys to disturb you.I got it to work.
Code: Select all
$sql = 'INSERT INTO `nt_activity` (`activity_name`, `activity_description`) VALUES (\''.$name_activity.'\',\''.$add_r.'\');';
mysql_query($sql);
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Sep 15, 2006 12:22 pm
Do this...
Code: Select all
$sql = "INSERT INTO `nt_activity` (`activity_name`, `activity_description`) VALUES ('$name_activity', '$add_r');";
saumya
Forum Contributor
Posts: 193 Joined: Sun Jan 30, 2005 10:21 pm
Post
by saumya » Fri Sep 15, 2006 12:26 pm
hey Everah,
that worked too and I think thats a better way.
thanks a lot.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Sep 15, 2006 12:29 pm
You're welcome. SQL intructions are the rare times I advocate wrapping strings in double quotes vs. single quotes. Mostly just because it makes the SQL readable for large queries.
saumya
Forum Contributor
Posts: 193 Joined: Sun Jan 30, 2005 10:21 pm
Post
by saumya » Fri Sep 15, 2006 12:37 pm
You are right. cheers
Good practices always help.