0

I have a Html Form with 3 Text Box 1 Search Box and a Button 2 Textbox to retrieve the search data from mySql

This is my HTML Form

  <form class="form" action="getData.php" method="post">
        <input type="text" name="search" placeholder="Username" >

        <button type="submit" name="submit" >Search</button>
    </form>

  <input type="text" name="UserID" placeholder="Username" >
        <input type="UserEmail" name="password" placeholder="Email">

Now my PHP Code

<?php
    $search=POST['search'];
    $dbhost = 'localhost:3036';
    $dbuser = 'root';
    $dbpass = 'rootpassword';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
       die('Could not connect: ' . mysql_error());
    }
    $sql = 'SELECT emp_id, emp_name, emp_salary FROM employee';

Now how do I pass the data to the Textbox in the HTML?

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Sree Aka
  • 29
  • 1
  • 5
  • 1
    If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 06 '15 at 17:24
  • Which data to which text box? And why are your 2 last input entities outside the form? – OIS Jul 06 '15 at 17:27

1 Answers1

0

I think this is what you are looking for... how to passes the queried data to the textboxes.

NOTE:

My query uses PDO and I did not include the connection nor the entire form code:

PHP

$id = ?; // id
    $selectqup = $db->prepare("SELECT 
        emp_id,
        emp_name,
        emp_salary

    FROM employee WHERE emp_id=:THEID LIMIT 1");

    $selectqup->bindValue(':THEID',$id,PDO::PARAM_INT); 
    $selectqup->execute(); $ct = $selectqup->rowCount();    

    while($row = $selectqup->fetch(PDO::FETCH_ASSOC)){
        $emp_id = $row['emp_id']; 
        $emp_name = $row['emp_name']; 
        $emp_salary = $row['emp_salary'];       
    }

HTML

// the text boxes
    <input type="text" name="emp_id" placeholder="Username"  value="<?php echo '.$emp_id.'; ?>">
    <input type="text" name="emp_name" placeholder="Username"  value="<?php echo '.$emp_name.'; ?>">
    <input type="text" name="emp_salary" placeholder="Username"  value="<?php echo '.$emp_salary.'; ?>">
petebolduc
  • 1,233
  • 1
  • 13
  • 20
  • Thanks but could you tell me how do you pass the search criteria from the 1st from to the PHP and the result is in another form so how do I get that in that form? – Sree Aka Jul 07 '15 at 04:11
  • Ok Let me reiterate my question, So it will be easier for the members, I have 2 Forms in the same page, One form which has the search and the other form where I want to show the results. So when I enter the data into the search Form input box and click on the Search Button , I would want the result on the Form 2. Please help , This is what I am looking for – Sree Aka Jul 07 '15 at 05:09
  • Please post your complete code so that we know what we are dealing with and what in your attempt is not working. This is not a site where you post your need and we write the code for you... this is a site where assistance is provided for those who make an attempt but for whatever reason their code does not work... those assisting and the inquirer work together to find the solution. – petebolduc Jul 07 '15 at 12:42