MDanz Posted February 6, 2010 Share Posted February 6, 2010 $tags = get_meta_tags($url); $keywords = $tags['keywords']; this get me the keywords for a website. Just say there are 5 keywords in that one variable. e.g. apple, banana, orange, pear and coconut. how do i insert these 5 keywords in that one variable($keywords) into seperate rows. So insert first keyword into one row second keyword into one row etc remember they are all in one variable. how can i do this?... example would help Link to comment https://forums.phpfreaks.com/topic/191126-help-on-insertphp/ Share on other sites More sharing options...
trq Posted February 6, 2010 Share Posted February 6, 2010 $keywords = "apple,banana,orange,pear,coconut"; foreach (explode(',' $keywords) as $keyword) { $sql = "INSERT INTO keywords (keyword) VALUES ('$keyword');"; // execute the above sql statement } Link to comment https://forums.phpfreaks.com/topic/191126-help-on-insertphp/#findComment-1007783 Share on other sites More sharing options...
MDanz Posted February 6, 2010 Author Share Posted February 6, 2010 thanks thorpe!! will that work if $keywords = $tags['keywords']; $tags['keywords']; are metatags keywords of a webpage Link to comment https://forums.phpfreaks.com/topic/191126-help-on-insertphp/#findComment-1007788 Share on other sites More sharing options...
MDanz Posted February 6, 2010 Author Share Posted February 6, 2010 i keep getting the Parse error: syntax error, unexpected T_VARIABLE on the line with foreach.. $radiobutton = $_POST['radiobutton']; $name = mysql_real_escape_string($_POST['name']); $url = mysql_real_escape_string($_POST['url']); $tags = get_meta_tags($url); $description = $tags['description']; $keywords = $tags['keywords']; $ip = $_SERVER['REMOTE_ADDR']; foreach (explode(',' $keywords) as $keyword) { if($radiobutton == 'on') { $sql = "INSERT INTO Stacks (`username`,`hyperlink`,`name`,`summary`,`info`,`keywords`,`ip`,`posted`,`adult`) VALUES('$username', '$url', '$name', '$description', '$description', '$keyword', '$ip', NOW(), '1')"; $query = mysql_query($sql); } else { $sql = "INSERT INTO Stacks (`username`,`hyperlink`,`name`,`summary`,`info`,`keywords`,`ip`,`posted`) VALUES('$username', '$url', '$name', '$description', '$description', '$keyword', '$ip', NOW())"; $query = mysql_query($sql); } if($query){ $name = mysql_real_escape_string($_POST['name']); $url = mysql_real_escape_string($_POST['url']); $query3= mysql_query("UPDATE Stacks SET `keywords`=CONCAT(`keywords`, ' ', '$name') WHERE hyperlink='$url'") or die (mysql_error()); $key = mysql_real_escape_string($_POST['key']); $url = mysql_real_escape_string($_POST['url']); $query2= mysql_query("UPDATE Stacks SET `keywords`=CONCAT(`keywords`, ' ', '$key') WHERE hyperlink='$url'") or die (mysql_error()); if(!empty($key)) { print "<br><font color=white>Your webpage has been stacked. <form><input type='button' value='Return' onClick='history.go(-1);return true;'> </form>"; } else { print "<br><font color=white>Your webpage has been stacked. <a href='menu.php'>Return to Stacker</a></font>"; } }} else { print "<br><font color=white>This webpage hasn't got meta tags set. <a href='menu.php'>Return to Stacker</a></font>"; } Link to comment https://forums.phpfreaks.com/topic/191126-help-on-insertphp/#findComment-1007791 Share on other sites More sharing options...
trq Posted February 6, 2010 Share Posted February 6, 2010 Should be.... foreach (explode(',', $keywords) as $keyword) { Link to comment https://forums.phpfreaks.com/topic/191126-help-on-insertphp/#findComment-1007793 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.