Fetch mysql data from PHP using radiobutton control

Comradeo

I would like to manipulate PHP code to search for specfic data in the sql database that matched.

For example, let's say I want to search for an IP matched by a username in the sql database, they're all in the same rows, I select 'IP' in the radiobutton, input the username in the text field - My PHP code searches all for what's in the user database, finds the usernames, outputs only the ip address ( not anything else ), in the row titled 'IP Address' for that specific input. How would I go about doing this?

I want the radiobuttons to be a case, so if I select IP, it'll search IP matched by username, if I select UID, it'll search for UID matched by username and output it, and etc, etc.

HTML:

    <form action="" method = "POST">
  <input type="radio" name="someName" value="ip"> IP<br>
  <input type="radio" name="someName" value="username"> Username<br>
  <input type="radio" name="someName" value="uid"> UID
</form>

PHP:

<?php
error_reporting(E_ALL);
    $con = new PDO('mysql:host='.$db_hostname.';dbname='.$db_database.';charset=utf8mb4', $db_termname,$db_password, array(PDO::ATTR_EMULATE_PREPARES => false,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
        if(array_key_exists('term',$_REQUEST)){
            $stm=$con->prepare('SELECT * FROM users WHERE username = ?');
            $stm->execute(array($_REQUEST['term']));
            while($row = $stm->fetch(PDO::FETCH_ASSOC)) {
                echo $row['ip'];  
        }   
    }
?>
Sanzeeb Aryal

Your form should be like:

 <form action="" method = "POST">
      <input type="radio" name="someName" value="ip"> IP<br>
      <input type="radio" name="someName" value="uid"> UID<br>
      Enter Name: <input type="text" name="name" > <br>
      <input type="submit" name="submit"> Submit<br>
    </form>

and your php file :

    <?php
            error_reporting(E_ALL);
            $submit=isset($_POST['submit']);
            if($submit)  
{
              $name=$_POST['somename'];
              $username=$_POST['username'];
              $con = new PDO('mysql:host='.$db_hostname.';dbname='.$db_database.';charset=utf8mb4', $db_termname,$db_password, array(PDO::ATTR_EMULATE_PREPARES => false,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
              $stm=$con->prepare('SELECT * FROM users WHERE username = ?');
              $stm->bind_param("s",$username);
              $stmt->execute();
              $row = $stm->fetch(PDO::FETCH_ASSOC);
              if($name=='ip')
        {                       echo $row['ip'];  
        }
               else if($name=='uid')  
          {
                    echo $row['uid];
           }
 }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to fetch data from mysql database using php

From Dev

PHP Fetch Present Week data From MySQL

From Dev

PHP script to fetch data from mysql to android

From Dev

fetch data error php from mysql

From Dev

How to fetch data from MySQL database into nested JSON array using php script?

From Dev

Fetch data from mysql

From Dev

Display data in a PHP table MySQL using mysqli_fetch_array

From Dev

Unable to fetch MySQL row data using PHP Program

From Dev

PHP code to fetch data from mysql server for mobile app

From Dev

PHP Fetch Data from MySql Table like Twitter Trend

From Dev

Fetch data from database mysql according to today's day? php

From Dev

Fetch data from mysql Foreign key table in php

From Dev

HTML Select Option and submit to fetch data from PHP PDO MySql

From Dev

php mysql fetch data from mulitiple table in json

From Dev

how to fetch a number of rows...from table in mysql using php

From Dev

How to count 365 days from current system date to past and future date and fetch the data accordingly using php and mysql

From Dev

fetch image from mysql php

From Dev

Fetch json data using PHP

From Dev

PHP : Sending data using fetch()

From Dev

Fetch data from database in php

From Dev

PHP Fetch Data From Database

From Dev

Clickable data displayed from mysql using PHP

From Dev

insert data from JSON into mysql using php

From Dev

Filter data from MySQL using WHERE or PHP?

From Dev

Extraction data from MySQL table using PHP

From Dev

Editing data from mysql table using php

From Dev

Using PHP, get data from MySQL and display it

From Dev

Sending data from Mysql with Json using PHP

From Dev

Extraction data from MySQL table using PHP

Related Related

HotTag

Archive