Jump to content

adding results filed to database


mikejs

Recommended Posts

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

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 :)

Archived

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

×
×
  • Create New...

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.