whats the general code to insert data inside MySql data base

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

whats the general code to insert data inside MySql data base

Post by saumya »

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 »

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);
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

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 »

hey Everah,
that worked too and I think thats a better way.
thanks a lot. :lol:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

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 »

You are right. cheers
Good practices always help.
Post Reply