mikejs Posted January 16, 2010 Share Posted January 16, 2010 Hi I am using the following code $num_rows = mysql_num_rows($q); ///check no of rows mysql_query("INSERT INTO tags(tag) VALUES('$query') ") or die(mysql_error()); if($num_rows>0){ echo " <b>Your search for the word<font color=blue> " .strtoupper($query). " </font>returned $num_rows results: -\n</b>"; I am stuck with what to put here so it adds the search term to the table VALUES('$query') ") the code above uses " .strtoupper($query). " and displays fine when I check the table its being updated with $query rather than the value anyone help please Link to comment https://forums.phpfreaks.com/topic/188650-adding-results-filed-to-database/ Share on other sites More sharing options...
PHP Monkeh Posted January 16, 2010 Share Posted January 16, 2010 You just need to end your quotes and concatenate the strings, like so: mysql_query("INSERT INTO tags(tag) VALUES('" . $query . "') ") or die(mysql_error()); Note that if $query contains quotes you're going to get errors, so it's best to use mysql_real_escape_string() around the value: mysql_query("INSERT INTO tags(tag) VALUES('" . mysql_real_escape_string($query) . "') ") or die(mysql_error()); I'd advise reading up a bit more about it though Link to comment https://forums.phpfreaks.com/topic/188650-adding-results-filed-to-database/#findComment-996060 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.