Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts

    Value in textbox is row

    I am trying to do it so the value in the text box is the current value that is in the database so I do not have to retype, and instead edit it or add on to it.

    PHP Code:
    <html>
    <body>
    <?php
    if (isset ($_POST['submit'])) // if the form was submitted, display their name
    {
    require_once (
    'inc/config.php');
    $firstname mysql_real_escape_string ($_POST['firstname']);
    $lastname mysql_real_escape_string ($_POST['lastname']);
    $middlenamemysql_real_escape_string ($_POST['middlename']);
    $id 2;  
    $sql mysql_query ("
       UPDATE `testing` SET 
          `FirstName` = '"
    .$firstname."', 
          `LastName` = '"
    .$lastname."',
          `MiddleName` = '"
    .$middlename."' 
       WHERE `id` = '"
    .$id."'
    "
    )
    OR die (
    mysql_error());
    echo 
    "hello";
    }
    //form hasent been submitted
    {

    ?>


    <form action="<?php echo $_SERVER['PHP_SELF'?>" method="post">
    Firstname: <input type="text" value="<?php echo $row['FirstName'];?>" name="firstname" /><br>
    Lastname: <input type="text" value="<?php echo $row['LastName'];?>" name="lastname" /><br>
    middlename: <input type="text" value="<?php echo $row['MiddleName'];?>" name="middlename" /><br>
    <input type="submit" id="submit" name="submit" value="Submit!">
    </form>
    <?php
    }
    ?>


    </body>
    </html>
    Basicly the value isnt showing up.
    PHP Code:
    <input type="text" value="<?php echo $row['MiddleName'];?>" name="middlename" />
    How do I fix that?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Where has $row been defined?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Hm... I thought of adding this:
    PHP Code:


    <html>
    <body>
    <?php
    if (isset ($_POST['submit'])) // if the form was submitted, display their name
    {
    require_once (
    'inc/config.php');
    $firstname mysql_real_escape_string ($_POST['firstname']);
    $lastname mysql_real_escape_string ($_POST['lastname']);
    $middlenamemysql_real_escape_string ($_POST['middlename']);
    $id 2;  
    $sql mysql_query ("
       UPDATE `testing` SET 
          `FirstName` = '"
    .$firstname."', 
          `LastName` = '"
    .$lastname."',
          `MiddleName` = '"
    .$middlename."' 
       WHERE `id` = '"
    .$id."'
    "
    )
    OR die (
    mysql_error());
    echo 
    "hello";
    }

    require_once (
    'inc/config.php');
    $query "SELECT * FROM testing";
    $result mysql_query($query) or die(mysql_error());
    while (
    $row mysql_fetch_array ($result))
    {
    ?>


    <form action="<?php echo $_SERVER['PHP_SELF'?>" method="post">
    Firstname: <input type="text" value="<?php echo $row['FirstName'];?>" name="firstname" /><br>
    Lastname: <input type="text" value="<?php echo $row['LastName'];?>" name="lastname" /><br>
    middlename: <input type="text" value="<?php echo $row['MiddleName'];?>" name="middlename" /><br>
    <input type="submit" id="submit" name="submit" value="Submit!">
    </form>
    <?php
    }
    ?>

    </body>
    </html>
    It worked...

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    yes, but that won't work quite as expected. Foreach record you have you'll create an entire form, so you cannot access multiple forms and treat them as a single form. Although I don't know what you're use is for this exactly, I'd suspect this is what you want (to pass each name parts as an array):
    PHP Code:
    <?php
    // ...
    $query "SELECT * FROM testing"
    $result mysql_query($query) or die(mysql_error()); 
    printf('<form action="%s" method="post">'$_SERVER['SCRIPT_NAME']);
    while (
    $row mysql_fetch_array ($result)) 

    ?> 

    Firstname: <input type="text" value="<?php echo $row['FirstName'];?>" name="firstname[]" /><br> 
    Lastname: <input type="text" value="<?php echo $row['LastName'];?>" name="lastname[]" /><br> 
    middlename: <input type="text" value="<?php echo $row['MiddleName'];?>" name="middlename[]" /><br> 
    <input type="submit" id="submit" name="submit" value="Submit!"> 
    <?php 


    print 
    '</form>';
    Unless its changed, PHP_SELF is XSS exploitable. Avoid using it when you can.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Thanks here is my final code:

    PHP Code:
    <html>
    <body>
    <?php
    if (isset ($_POST['submit'])) // if the form was submitted, display their name
    {
    require_once (
    'inc/config.php');
    $firstname mysql_real_escape_string ($_POST['firstname']);
    $lastname mysql_real_escape_string ($_POST['lastname']);
    $middlenamemysql_real_escape_string ($_POST['middlename']);
    $id 2;  
    $sql mysql_query ("
       UPDATE `testing` SET 
          `FirstName` = '"
    .$firstname."', 
          `LastName` = '"
    .$lastname."',
          `MiddleName` = '"
    .$middlename."' 
       WHERE `id` = '"
    .$id."'
    "
    )
    OR die (
    mysql_error());
    echo 
    "hello";
    }

    require_once (
    'inc/config.php');
    $query "SELECT * FROM testing";
    $result mysql_query($query) or die(mysql_error());
    while (
    $row mysql_fetch_array ($result))
    {
    ?>



    <form action="<?php echo $_SERVER['PHP_SELF'?>" method="post">
    Firstname: <input type="text" value="<?php echo $row['FirstName'];?>" name="firstname" /><br>
    Lastname: <input type="text" value="<?php echo $row['LastName'];?>" name="lastname" /><br>
    middlename: <input type="text" value="<?php echo $row['MiddleName'];?>" name="middlename" /><br>
    <input type="submit" id="submit" name="submit" value="Submit!">
    </form>
    <?php
    }
    ?>

    </body>
    </html>
    Now I have a new problem:

    I want to echo what is currently in the database but it wont show up
    PHP Code:
    <?php
    // show errors if any
    error_reporting(E_ALL);
    ini_set('display_errors''1');

    // require a file
    require_once ('inc/config.php');

    // select row from table
    $query "SELECT * FROM testing";

    // check if is valid if it is then show results if not then die
    $result mysql_query($query) or die(mysql_error()); 
    while (
    $row mysql_fetch_array ($result)) 
    {
    ?>
    First Name:
    <?php $row['FirstName']; ?>
    <br>Last Name:
    <?php $row['LastName']; ?>
    <br>Middle Name:
    <?php $row['MiddleName']; ?>
    <?
    }
    ?>

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You're not printing the values to the screen.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    ini_set('display_errors''1');

    require_once (
    'inc/config.php');
    $query "SELECT * FROM testing";
    $result mysql_query($query) or die(mysql_error()); 
    while (
    $row mysql_fetch_array ($result)) 
    {
    ?>
    First Name:
    <?php echo $row['FirstName']; ?>
    <br>Last Name:
    <?php echo  $row['LastName']; ?>
    <br>Middle Name:
    <?php echo $row['MiddleName']; ?>
    <?
    }
    ?>
    Fixed I just had to add echo to it,.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by bucket View Post
    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    ini_set('display_errors''1');

    require_once (
    'inc/config.php');
    $query "SELECT * FROM testing";
    $result mysql_query($query) or die(mysql_error()); 
    while (
    $row mysql_fetch_array ($result)) 
    {
    ?>
    First Name:
    <?php echo $row['FirstName']; ?>
    <br>Last Name:
    <?php echo  $row['LastName']; ?>
    <br>Middle Name:
    <?php echo $row['MiddleName']; ?>
    <?
    }
    ?>
    Fixed I just had to add echo to it,.
    Yes, thats pretty much exactly what I said:
    Quote Originally Posted by Fou-Lu View Post
    You're not printing the values to the screen.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #9
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    I know Thanks mate.


  •  

    Posting Permissions

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