imimin Posted June 29, 2009 Share Posted June 29, 2009 I have the following code that I am trying to use to dynamically pull data from a database to fill my metatags. I have confirmed I have correctly connected to the DB. I am getting the following error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /homepages/27/d120150310/htdocs/poj/index.php on line 23 Which is line 8 below. The code I am using is: <?php $cat = $_GET['page']; $get_items = "SELECT * FROM head_data WHERE page='index.php'"; $get_items = mysql_query($get_items); while($item_row = mysql_fetch_array($get_items)){ $item_title = $item_row['title']; $item_desc = $item_row['desc']; $item_keywords = $item_row['keywords']; echo "<TITLE>$item_title</TITLE> <meta name="description" content="$item_desc"> <meta name="keywords" content="$item_keywords">"; } ?> I am not very good at this stuff yet, but am trying to learn. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/164046-help-with-pulling-data-from-database/ Share on other sites More sharing options...
haku Posted June 29, 2009 Share Posted June 29, 2009 Change this: echo "<TITLE>$item_title</TITLE> <meta name="description" content="$item_desc"> <meta name="keywords" content="$item_keywords">"; to this: echo '<TITLE>$item_title</TITLE> <meta name="description" content="$item_desc"> <meta name="keywords" content="$item_keywords">'; You were using double quotes to enclose the string, and using double quotes inside the string, which exits the double quotes. You need to use single quotes to enclose the string if you want to use double quotes inside it. Quote Link to comment https://forums.phpfreaks.com/topic/164046-help-with-pulling-data-from-database/#findComment-865378 Share on other sites More sharing options...
Philip Posted June 29, 2009 Share Posted June 29, 2009 @haku: Variables won't execute in single quotes. echo '<TITLE>',$item_title,'</TITLE> <meta name="description" content="',$item_desc,'"> <meta name="keywords" content="',$item_keywords,'">'; or: echo "<TITLE>$item_title</TITLE> <meta name=\"description\" content=\"$item_desc\"> <meta name=\"keywords\" content=\"$item_keywords\">"; Quote Link to comment https://forums.phpfreaks.com/topic/164046-help-with-pulling-data-from-database/#findComment-865397 Share on other sites More sharing options...
imimin Posted June 29, 2009 Author Share Posted June 29, 2009 Thanks, that did the trick. I am now longer getting the error and my web page is loading but my DB data is not being populated in my variable. When I look at the source of my web page I get this for the metatags: <TITLE>$item_title</TITLE> <meta name="description" content="$item_desc"> <meta name="keywords" content="$item_keywords"> Any additional help would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/164046-help-with-pulling-data-from-database/#findComment-865410 Share on other sites More sharing options...
cunoodle2 Posted June 29, 2009 Share Posted June 29, 2009 What is the exact code you are using in your "echo" statement in php? Quote Link to comment https://forums.phpfreaks.com/topic/164046-help-with-pulling-data-from-database/#findComment-865415 Share on other sites More sharing options...
Philip Posted June 29, 2009 Share Posted June 29, 2009 Variables won't execute in single quotes. echo '<TITLE>',$item_title,'</TITLE> <meta name="description" content="',$item_desc,'"> <meta name="keywords" content="',$item_keywords,'">'; or: echo "<TITLE>$item_title</TITLE> <meta name=\"description\" content=\"$item_desc\"> <meta name=\"keywords\" content=\"$item_keywords\">"; Quote Link to comment https://forums.phpfreaks.com/topic/164046-help-with-pulling-data-from-database/#findComment-865438 Share on other sites More sharing options...
imimin Posted June 29, 2009 Author Share Posted June 29, 2009 Thank you! That worked and I learned a big lesson :-) ! Quote Link to comment https://forums.phpfreaks.com/topic/164046-help-with-pulling-data-from-database/#findComment-865728 Share on other sites More sharing options...
haku Posted June 30, 2009 Share Posted June 30, 2009 Variables won't execute in single quotes. I didn't even notice they were there - which is the exact reason why I never use them without exiting my quotes! Easy to make mistakes like that. Quote Link to comment https://forums.phpfreaks.com/topic/164046-help-with-pulling-data-from-database/#findComment-866086 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.