php - using a selection list display data submitted to show columns from data -
using php & mysqli: trying use select list , when user hits submit button using php trying display colums data when user selects specific selection:
//database set information connect sqli:
$servername = "*******";
$username = "********";
$password = "******";
$dbname = "********";
`// create connection` `$conn = new mysqli($servername, $username, $password, $dbname);` `// check connection` `if ($conn->connect_error) {` `die("connection failed: " . $conn->connect_error); }` `//to value of selected option select tag: if(isset($_post['submit'])){ $selected_val = $_post['selection']; // storing selected value in variable echo " have selected :" .$selected_val; // displaying selected value }` `//a string submitted:` `$selection = $_post['selection'];` `$selection = intval($_post['selection']);` `//selecting data database:` `$sql = "select * teams teamname = '$selection'"; $sql = "select * teams city = '$selection'"; $sql = "select * teams bestplayer = '$selection'"; $sql = "select * teams yearformed = $selection"; $sql = "select * teams website = '$selection'";` `$conn->close(); ?>` `<form action=<?php echo htmlspecialchars($_server["php_self"]); ?> method="post"> <select name="selection"> <option value="teamname">team name</option> <option value="city">city</option> <option value="bestplayer">best player</option> <option value="yearformed">year formed</option> <option value="website">website</option> </select> <input type="submit" name="submit" value="get selected values" /> </form>`
Comments
Post a Comment