Richard Korts
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:
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:
I echo the $qry, $tptot is null, so the insert fails.
How can I fix this?
Thank you.
sname = document.st.sel_name.value;
document.st.action = "sel_save.php?sname=" + sname + "&tptot=" + encodeURI(tptot);
return true;
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'] . "')";
I echo the $qry, $tptot is null, so the insert fails.
How can I fix this?
Thank you.
ASKER
It is? For me, that place is null, so of course, the Insert fails, etc.
I'll try again from the start.
Thanks
I'll try again from the start.
Thanks
ASKER
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
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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, Chris.
Clearly your responses were great, I was just stupid.
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 !
When I open your page link, it echoes out the SQL statement, and the value of $tptot is clearly showing as 12178.95.
Screengrab: