www.webdeveloper.com
Results 1 to 6 of 6

Thread: How to display DB values in textbox

Hybrid View

  1. #1
    Join Date
    Jul 2014
    Posts
    12

    Question How to display DB values in textbox

    Hi,

    i'm trying to display db(name,email,telephone no) values in textbox.please help me.

    ::HTML part::

    Code:
     
    <form class="form-signin" role="form" id="form1" action="post_user.php">
          
           <label class="">Name</label>
            <input type="text" class="form-control" placeholder="Your Name" value="" required name="yname" id="yname" autofocus ><br/>
             <label class="">Email</label>
                    <input type="text" class="form-control" name="email" id="email" placeholder="Email address" required > <br/>
                       
                
        
        <label class="">Telephone Number</label>
           <input type="text" class="form-control" pattern="\d+" placeholder="Telephone" name="telephone" required><br/>
     
    <div class="col-md-4 col-md-offset-4">
            <button class="btn btn-lg btn-primary btn-block" type="submit">Submit Ad</button>
            </div>
    </form>

    :ost_user.php::

    Code:
    <?php
     
    $con = mysql_connect("localhost","root","");
    if(!$con)
    {
    die('Could not connect:'.mysql_error());
    }
    mysql_select_db("biz",$con);
     
    $mail=$_POST['email'];
     
     
    $query = mysql_query("SELECT yname,mail,tp FROM reg WHERE mail = '$mail' ");
     
    while($row = mysql_fetch_array($query))
        {
       
     echo $row['yname'];     
      echo $row['mail'];   
       echo $row['tp'];                
        } 
    mysql_close($con);
    ?>

  2. #2
    Join Date
    Jul 2014
    Posts
    2
    html page:

    <form class="form-signin" role="form" id="form1" action="post_user.php">

    <label class="">Name</label>
    <input type="text" class="form-control" placeholder="Your Name" value="" required name="yname" id="yname" autofocus ><br/>

    <label class="">Email</label>
    <input type="text" class="form-control" name="email" id="email" placeholder="Email address" required > <br/>

    <label class="">Telephone Number</label>
    <input type="text" class="form-control" pattern="\d+" placeholder="Telephone" name="telephone" required><br/>

    <div class="col-md-4 col-md-offset-4">
    <button class="btn btn-lg btn-primary btn-block" type="submit">Submit Ad</button>
    </div>

    </form>

    post_user.php page:

    <?php

    $con = mysql_connect("localhost","root","");

    if(!$con){
    die('Could not connect:'.mysql_error());
    }

    mysql_select_db("biz",$con);

    $mail=$_POST['email'];
    $query = mysql_query("SELECT yname,mail,tp FROM reg WHERE mail = '".$mail."' ");

    while($row = mysql_fetch_object($query)){

    ?>

    Name: <?php echo $row->yname ?>
    Mail: <?php echo $row->mail ?>
    Telephone: <?php echo $row->tp ?>

    <?php

    }
    mysql_close($con);

    ?>
    You can replace "Name: " or "Mail" or "Tel. Number" in input type or else ... Like u want

  3. #3
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    731
    This looks great! So - what's the problem?

    It would help for you to do some error checking after you execute your query. It would also be mandatory fro you to turn on php error checking in every script in development so that you can catch other errors that may affect your processing.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  4. #4
    try this one may be helpful for you.
    HTML Code:
    Email: <input type="text" value="<?php echo $row['yname'];  ?>" />
    You can repeat this method with others field or values..

  5. #5
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    731
    So much coding of php tags for a simple task. When you want to combine lots of html with some php data use heredocs

    PHP Code:
    while($row mysql_fetch_object($query))
    {
     
    $name $row->yname;
     
    $mail $row->mail;
     
    $telephone  $row->tp;

    And in your html then use the new vars as:
    [php[
    $code=<<<heredocs
    Email: <input type='text' value="$mail">
    Name: <input type='text' value="$name">
    Telephone: <input type='text' value="$telephone">
    heredocs;
    echo $code;
    [/php]

    Much simpler to read and understand without the echo, <?php and ?> pieces.

    Obviously this trivial example works only because the query brings up only one record (hopefully. If there were rows of results and you were probably going to build an html table to display them, you would use the while loop to build a table row (<tr>) for each record after initializing a php var with the table begin tag, then concatenating each row of data in the loop to that var and after the loop ending the var with the table end tag. Then in the html just echo that var in the appropriate spot.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  6. #6
    Join Date
    Jul 2014
    Posts
    12
    Thanks.
    Email: <input type="text" value="<?php echo $row['yname']; ?>" />

    it's working

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles