I’m submitting a form and inserting the valuse into my mysql db.
One of the form elements it a select with option values like 11#120#12 (id#cost#months).
I perform the following:
$plan = explode("#", $_POST['symb']);
$plan = $plan[0];
$cost = $plan[1];
and then submit to my db
echo $insertSQL = sprintf("INSERT INTO users (username, plan, cost) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($plan, "text"),
GetSQLValueString($cost, "int"));
The problem is that $cost is getting the wrong value, instead of 120 it’s getting 1 as a value. Where’s the error? (the posted sql statement is only part of the actual query, for demonstration purposes only)
Don’t overwrite
$planwith a string value before you try to extract the$costfrom the array you originally stored in it.Either change the first
$planin$plan = $plan[0];(and change every reference to it later in the script) or move that line so it appears after$cost = $plan[1];.(I’d recommend the former option for clarity).`