Forum Moderators: coopster

Message Too Old, No Replies

trying to get data from url

         

Ray_Ward

7:58 pm on May 7, 2011 (gmt 0)

10+ Year Member



Hello
I'm trying to capture the dynamic data that comes in with the URL and put them into variables and then store them in my database.
Following line is the Url with the data.
[#*$!#*$!x.net...]

The data is:
'lat' value = 36.3 (this will be stored in a varchar(10) field in the database. (field is for latitude)
'long' value = -115.2625 (this will be stored in a varchar(10) field in the database. (field is for longitude)

The form is working fine all other data on formis stored to the DB but I can't seem to capture the data from the url.
I have searched the web and I'm starting to go crazy and was hoping you could help.

I have listed below my 'index.php' file with my mods all marked with //custom so you could see what I was trying to do.

Any help that you could give me would really be appreciated.

Looking forward to your reply

Thank you

Ray Ward

?php
# ----------------------------------------------------
# -----
# ----- This script was generated by php form magic 1.1 on 5/5/2011 at 7:49:06 PM
# -----
# ----- [websitedatabases.com...]
# -----
# ----------------------------------------------------


// Receiving variables
@$name = addslashes($_POST['name']);
@$event = addslashes($_POST['event']);
@$date_created = addslashes($_POST['date_created']);
@$date_updated = addslashes($_POST['date_updated']);
@$id = addslashes($_POST['id']);
@$visits = addslashes($_POST['visits']);
@$email = addslashes($_POST['email']);
@$long = addslashes($_POST['long']);
//@$did = addslashes($_POST['did']); // custom not used at this time
@$lat = addslashes($_POST['lat']);
@$phone = addslashes($_POST['phone']);

//custom ray added This is the disguised incoming url I am trying to get the data from = [#*$!#*$!.net...]
//custom - following don't work? all other custom additions worked great
$lat = $_GET['lat'];
$long = $_GET['long'];


//custom following rem'd by ray for test
//if (isset($_GET['lat'])) {
//$lat = $_GET['lat'];
//}
//if (isset($_GET['long'])) {
//$long = $_GET['long'];
//}

//print $id; //custom for testing only
//print $name;
//print $email;
//print $visits;
//print $lat;
//print $long;




// Validation
if (strlen($name) == 0 )
{
die("<p align=\"center\"><font face=\"Vrinda\" size=\"4\"color=\"#FF0000\">name is empty </font></p>");
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
die("<p align='center'><b><font face='Arial' size='7' color='#FF0000'>Please enter a valid email</font></b></p>");
}

if (strlen($email) == 0 )
{
die("<p align=\"center\"><font face=\"Vrinda\" size=\"4\"color=\"#FF0000\">email is empty </font></p>");
}
// custom ray next line makes $username uppercase
@$name = strtoupper($name);

//saving record to MySQL database
//Custom ray set date to pdst next 3 lines -- because server is in Boston & we need las vegas time pdst
date_default_timezone_set("Etc/GMT+7");
@$date_created = date("Y-m-d H:i:s");
@$date_updated = date("Y-m-d");
@$date_updated = Date('y:m:d', strtotime("+1 days")); //custom ray this line sets 'date_updated' field to next day (just change + how many days)

$lat = $_GET['lat'];
$long = $_GET['long'];
//changing date formats custom removed


@$pfw_strQuery = "INSERT INTO `shucks`(`name`,`event`,`date_created`,`date_updated`,`id`,`visits`,`email`,`long`,`did`,`lat`,`phone`)VALUES (\"$name\",\"$event\",\"$date_created\",\"$date_updated\",\"$id\",\"$visits\",\"$email\",\"$long\",\"$did\",\"$lat\",\"$phone\")" ;
//custom ray next 4 lines change for correct online info (disguised)
@$pfw_host = "#*$!#*$!#*$!xx.#*$!#*$!#*$!xx.com";
@$pfw_user = "#*$!#*$!";
@$pfw_pw = "#*$!#*$!";
@$pfw_db = "bus1";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);

if (!$pfw_link) {
die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}

$pfw_result = mysql_query($pfw_strQuery);

if (!$pfw_result)

{echo("<p align='center'><b><font face='Arial' size='18' color='#FF0000'><br><br><br><br><br>You are already Entered<br><br>for Today<br><br>Thank You</font></b></p>");
die;

}
mysql_close($pfw_link);

echo("<p align='center'><b><font face='Arial' size='7' color='#FF0000'><br><br><br>SUCCESS !<br><br>Thank You <br>for<br>Entering Our Event<br><br>GOOD LUCK !</font></b></p>");
?>

rainborick

2:48 pm on May 8, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your additions are relying on $_GET, but the rest of the script uses $_POST. One of those is wrong. They should both use the same HTTP request method variable.

g1smd

4:45 pm on May 8, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do save yourself a whole bunch of hassle by using a fixed URL format without parameters, a URL rewrite with strict RegEx patterns to accept valid URL formats, and simplify your code.

Ray_Ward

8:25 am on May 9, 2011 (gmt 0)

10+ Year Member



I changed all my 'post' functions to 'get'
And changed my HTM file to 'get' also

the 'lat' & 'long' variables are still empty when passed to the index.php

I'm still lost
Any more ideas?
Thank you
Ray Ward