Skip to main content
September 9, 2009
Question

PHP Insert

  • September 9, 2009
  • 1 reply
  • 613 views

I have been working on this function – the idea is to read the meta tags – find the description – then insert the description in a db table.

I got the first two parts working – but cannot get the description to insert.  I think I might need to do something to the array – i.e. addslashes or something – but, everything I try it does not seem to work.  The odd thing is that I can echo the description ($value) but cannot insert it.

function getSiteMeta($description){

   $tags = get_meta_tags($description);

  

   if(sizeof($tags)==0){

                        echo 'No Description Found';

   }

   foreach($tags as $key=>$value) {

                        if($key!=description) {

                        unset ($value);

                        }

                        else

                        {

                        mysql_query("INSERT INTO page (page_description) VALUES ($value)");

                        echo $value;

                        }

   }

}

Can someone provide a little guidance – please.

This topic has been closed for replies.

1 reply

September 10, 2009

Stumbled upon a solution - or more of a work around.  Not the prettiest of code but works great.

David_Powers
Inspiring
September 10, 2009

The obvious thing that's wrong with your original code is that $value needs to be in single quotes in the SQL query.

mysql_query("INSERT INTO page (page_description) VALUES ('$value')");

September 12, 2009

Thanks - yes, that was one (just one of many) of my problems.  Thanks for your help.