Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Cannot pass a floating point number in a $_GET string

I am trying to pass a number with a decimal point as a part of a query string with this Javascript:

sname = document.st.sel_name.value;
			document.st.action = "sel_save.php?sname=" + sname + "&tptot=" + encodeURI(tptot);
			return true;

Open in new window


Here is what the url looks like:

https://www.lakoshvac.com/devdev/sel_save.php?sname=It%20better%20do%20it%20this%20time&tptot=12178.95

It seems obvious to me that the . in the number is screwing things up.

In save_sel.php, I do this: $tptot = urldecode($_GET['tptot']);

Later on, I am trying to insert a record (row) into a MySQL table, like this:

$qry = "INSERT into selections (ruid, sel_name, date, cltype, length, width, depth, flow, sspct, pgroup, access, flevel, model, purge_method, tpurge, voltage, pepump, pumprepair, valve_kit, dec_contact, multi, repl_bags,strainer, net_price, ssgroup) VALUES(" . $_SESSION['ruid'] . ", '" . $sel_name . "', '" . date('Y-m-d') . "', '" . $_SESSION['cltype'] . "', " . $length . ", " . $width . ", " . intval($depth) . ", " . intval($flow) . ", " . intval($sspct) . ", '" . strtolower(substr($_SESSION['model'],0,3)) . "', '" . $_SESSION['access'] . "', " . intval($_SESSION['flevel']) . ", '" . $_SESSION['model'] . "', '" . $_SESSION['purge_method'] . "', '" . $_SESSION['purge'] . "', '" . $_SESSION['voltage'] . "', '" . $_SESSION['pepump'] . "', '" . $_SESSION['pumprepair'] . "', '" . $_SESSION['valve_kit'] . "', '" . $_SESSION['DEC'] . "', '" . $_SESSION['multi'] . "', " . $replbags . ", '" . $_SESSION['strainer'] . "', " . $tptot . ", '" . $_SESSION['group'] . "')";

Open in new window


I echo the $qry, $tptot is null, so the insert fails.

How can I fix this?

Thank you.
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Hey Richard,

When I open your page link, it echoes out the SQL statement, and the value of $tptot is clearly showing as 12178.95.

Screengrab:

User generated image
Avatar of Richard Korts

ASKER

It is? For me, that place is null, so of course, the Insert fails, etc.

I'll try again from the start.

Thanks
Chris,

I get this, in chrome:

select selection = SELECT * from selections where ruid = 867 and sel_name = 'Try to save as selection in Chrome'
insert into selections qry = INSERT into selections (ruid, sel_name, date, cltype, length, width, depth, flow, sspct, pgroup, access, flevel, model, purge_method, tpurge, voltage, pepump, pumprepair, valve_kit, dec_contact, multi, repl_bags,strainer, net_price, ssgroup) VALUES(867, 'Try to save as selection in Chrome', '2019-04-03', 'F', 0, 0, 0, 786, 15, 'eht', 'A', 44, 'eHTX-0420', 'Purge to Drain', 'ABV', '', '', '', '', '', '', 0, '', , 'sep')

Notice the null as the next to last value; that is a floating point in the database, so of course it fails.

The url is:

https://www.lakoshvac.com/devdev/sel_save.php?sname=Try%20to%20save%20as%20selection%20in%20Chrome&tptot=11439.75
Hi Richard,

Now when I open that page, it is indeed empty.

You seem to have an echo statement that says "tptot via post = ". That seems to suggest that you're trying to retrieve the value from POST, but the value is being passed as part of the querystring, so you'd need to retrieve it from GET:

$_POST['tptot']; // WRONG!
$_GET['tptot']; // CORRECT!
ASKER CERTIFIED SOLUTION
Avatar of Richard Korts
Richard Korts
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Chris.

Clearly your responses were great, I was just stupid.
Haha. Glad you got it sort - and don't worry - we all have Homer Simpson moments from time to time. Doh !