0

Hi,

I want to create a dynamic form, relative with the table i'm working with.

I'm selecting the columns from a certain table:

<?php
    $tableColumns = $dbConnect->query("SHOW COLUMNS
                                       FROM projects 
                                       WHERE Field NOT IN ('ID');");
?>

Then i want to get each result's value (according to the ID selected) and put it in an array:
URL: localhost/index.php?page=form&action=update&id=1

<?php
    $values[]="";

    if($_GET['action']=='update')
    {
        $selectTableResult=$dbConnect->query("SELECT *
                                              FROM ".$table."
                                              WHERE `ID`=1");

        while($rowTable=$selectTableResult->fetch_assoc())
        {
            print_r($values[] = $rowTable);
        }
    }
?>

What i want to do is write something like this:

<div class="form-group">
    <label>Text Input</label>
    <input class="form-control" name="textBox" type="text" value="<?php echo $value[1] ?>">
</div>

Like this, if i want to update an Item, the value of the input is "Test" (or whatever) and if i want to add an Item the value is empty.

Can someone help me, please?

Thanks!

3
Contributors
2
Replies
18
Views
2 Years
Discussion Span
Last Post by jstfsklh211
0

You could let Ajax do this. You would then repeat certain PHP function over and over again, with space of around 2 seconds, wait until PHP finds something new in the database and produces output, and then create a new field (with JavaScript) and make it's content, the content that PHP has provided you.

Edited by Aeonix

2
<input name="textBox[<?php echo $myid; ?>]"

when you post this you'll get an array for each form element with key = id
$_POST['textBox'][$myid]

Edited by jstfsklh211

Votes + Comments
nice one
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.