I have a problem with mysql storing a number value instead of the value I set in a form.
I can't find my problem or solution on the net.
A summary of code of what's happening.
HTML form code:
<td><input type="checkbox" name="load_ericsson" value="Ericsson"> Ericsson</td>
Connect.php code:
$load_ericsson = isset($_POST['load_ericsson']);
$sql = "INSERT INTO load_ericsson (contract) VALUES ('$load_ericsson')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
Result in phpmyadmin: It should say "Ericsson" as a value in the entry (because that is the value in the html form).
Instead the contract column in the load_ericsson table has a value of "1"
The vaue of isset($_POST['load_ericsson'])
will be true
or false
. Also it's better to use PDO and prepared statements to avoid SQL Injection and because mysql_*
functions are deprecated.
You need this:
if (isset($_POST['load_ericsson'])) {
$load_ericsson = $_POST['load_ericsson'];
//query with validation, sanitization, prepared statement here
}