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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.