Jump to content

PHP dynamic forms


kippi

Recommended Posts

Hey,

 

I have this code working that creates a form from the database rows, see code http://pastebin.com/m4719cd4a, I have code that allows the user to add the information to the database. The problem I have is now the first form allows a users to add new rows to the database and it will be updated on the form but I can't work out how to make the php code that writes the data dynamic. I have this code, could someone point me in the direction on how to make this dynamic. Code I am using now is: http://pastebin.com/m34ea9024

 

Hope this makes sense if not add me on msn: [email protected]

 

Many Thanks

 

Chris.

Link to comment
https://forums.phpfreaks.com/topic/97872-php-dynamic-forms/
Share on other sites

Ok,

 

this is what I have put together and it is fetching all the fields, could someone point me in the direction on how to write the information to the database:

 

I know this is wrong, but maybe you guys will understand a bit more what I am trying to do.

 

<?php

 

include '/var/www/web7/web/network/db/mysql.php';

 

mysql_connect(localhost,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

 

 

$result = mysql_db_query ("tenant", "select * from extension")

 

    or die ("Query failed");

 

# get column metadata

 

$i = 0;

while ($i < mysql_num_fields ($result)) {

 

    $meta = mysql_fetch_field ($result);

 

    if (!$meta) {

 

        echo "No information available<BR>\n";

 

}

 

    $test=$_POST[$meta->name];

    echo " $test " ;

    $rows=$meta->name;

 

 

$i++;

 

 

}

 

mysql_free_result ($result);

 

mysql_select_db($database);

$query = "INSERT INTO tenant ($rows) VALUES ($test)";

 

echo $test ;

echo "<BR>";

echo $rows ;

                                                                                             

mysql_query($query) or die('Error, insert query failed');

 

?>

 

This code outputs all the information from the form but getting this error Error, insert query failed so its not building the mysql query correctly.

 

Many Thanks

Link to comment
https://forums.phpfreaks.com/topic/97872-php-dynamic-forms/#findComment-501700
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.