andik Posted January 26, 2011 Share Posted January 26, 2011 Please forgive my limited knowledge of php. I am trying to pass a variable from 1 page to the next. I have SCRIPT A (I didn't write it) that parses an rss feed and then calls SCRIPT B to insert it into a database. Everything works great.. and all I'm trying to do is add a new piece of information. In my db, I added a column called 'city'. There are currently 25 different SCRIPT A's (25 different city names). I could create 25 SCRIPT Bs and call them individually, but I'm trying to use 1 SCRIPT B and just send the city name. I've read about POST and GET but still not sure on this? Can't I just hard code my city name into each SCRIPT A like this: $city = "miami"; And then put this at the top of SCRIPT B? $city = $_GET['city']; Well.. apparently, I can't because that doesn't work. Again.. sorry for the dumb question. It's my first time attempting anything with php. Thanks. Link to comment https://forums.phpfreaks.com/topic/225745-problems-passing-a-variable/ Share on other sites More sharing options...
Pikachu2000 Posted January 26, 2011 Share Posted January 26, 2011 When the first script ends, the $city variable is destroyed. You need to pass it to the next script that will need it. Maybe if you post your code with some sample data, and explain what you want it to do, we can help. Link to comment https://forums.phpfreaks.com/topic/225745-problems-passing-a-variable/#findComment-1165502 Share on other sites More sharing options...
andik Posted January 26, 2011 Author Share Posted January 26, 2011 one.php <? include 'config.php'; $url = 'http://somedomain.com/myfeed.rss'; require_once("process.php"); ?> process.php <?php A bunch of functions that clean the rss feed up are here mysql_query("INSERT IGNORE INTO feed (url, title, description, date, city) VALUES('".$link."', '".$title."', '".$description."', '".$date."', '".$city."' ) ") or die(mysql_error()); ?> So everything works except what I added, which is the $city variable. My workaround is to create individual pages for process and call like this: require_once("processMiami.php"); And then hard code miami in like below in processMiami.php <?php A bunch of functions that clean the rss feed up are here mysql_query("INSERT IGNORE INTO feed (url, title, description, date, city) VALUES('".$link."', '".$title."', '".$description."', '".$date."', 'miami' ) ") or die(mysql_error()); ?> I can ultimately do it this way but wanting to learn how this would normally be done. Hopefully I've posted enough. I removed a ton from a very long script but I think this is the meat of what you were asking for. Link to comment https://forums.phpfreaks.com/topic/225745-problems-passing-a-variable/#findComment-1165523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.