Page 1 of 1
whats the general code to insert data inside MySql data base
Posted: Fri Sep 15, 2006 11:44 am
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
Posted: Fri Sep 15, 2006 11:55 am
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);
Posted: Fri Sep 15, 2006 12:22 pm
by RobertGonzalez
Do this...
Code: Select all
$sql = "INSERT INTO `nt_activity` (`activity_name`, `activity_description`) VALUES ('$name_activity', '$add_r');";
Posted: Fri Sep 15, 2006 12:26 pm
by saumya
hey Everah,
that worked too and I think thats a better way.
thanks a lot.

Posted: Fri Sep 15, 2006 12:29 pm
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.
Posted: Fri Sep 15, 2006 12:37 pm
by saumya
You are right. cheers
Good practices always help.