Jump to content

Problems passing a variable


andik

Recommended Posts

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
Share on other sites

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