jeudi 22 janvier 2015

PHP / MYSQL - define variables with IF, ELSE?

I am writing a simple web program with PHP / MYSQL (due to limitations, mysql queries must be used rather than mysqli or PDO). An HTML table must display different values from my MYSQL table based on user form input.


What is the best way to define several variables based on the user input?


I tried



<?php
$taxcode = $_POST['taxcode'];

$db_host = 'localhost';
$db_user = 'root';
$db_pwd = 'root';

$database = 'database';
$table = 'sampletable';

if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");

if (!mysql_select_db($database))
die("Can't select database");

if ($taxcode = '401(k)') {
$planquery = ("SELECT * FROM sampletable WHERE PT_401k = '401(k)'");
$orgmatchquery = ("SELECT * FROM sampletable WHERE Organization_match_participants_contribution = 'Employer Matching contribution (i.e., 50% of first 6% of pay)' AND PT_401k = '401(k)'");
} elseif ($taxcode = '403(b)') {
$planquery = ("SELECT * FROM sampletable WHERE PT_403b = '403(b)'");
$orgmatchquery = ("SELECT * FROM sampletable WHERE Organization_match_participants_contribution = 'Employer Matching contribution (i.e., 50% of first 6% of pay)' AND PT_403b = '403(b)'");
} elseif ($taxcode = '457') {
$planquery = ("SELECT * FROM sampletable WHERE PT_457 = '457'");
$orgmatchquery = ("SELECT * FROM sampletable WHERE Organization_match_participants_contribution = 'Employer Matching contribution (i.e., 50% of first 6% of pay)' AND PT_457 = '457'");
}

?>


but it's not changing the value based on the input. What am I doing wrong?


Aucun commentaire:

Enregistrer un commentaire