I want code for creating Mysql table, I dont want code for fix fields, I want to add any number of fields and with any name.
I mean I want to create it dynamically using textboxes and combo boxes.
Thank you
I want code for creating Mysql table, I dont want code for fix fields, I want to add any number of fields and with any name.
I mean I want to create it dynamically using textboxes and combo boxes.
Thank you
Not sure about the exact place/purpose you intend to use it, but the following should help you suffice your requirements :
Dealing with combo boxe in php is similar to the way you'd deal with text boxes. More-or-less similar steps are required to achieve the values.
HTML :
In the php script for which you'd POST the form data, the variables can be accesses using $_POST[variablename].Code:<form action="process.php" method="POST"> Name: <input type="text" name="name" /><br /> DOB : <input type="text" name="dob" /><br /> Gender : <select name="gender"> <option value="M">Male</option> <option value="F">Female</option> </select><br /> Country : <select name="country"> <option value="US">United States of America</option> <option value="AU">Australia</option> <option value="CA">Canada</option> <option value="XX">XXXXX</option> </select><br /> <input type="submit" value="Submit Info" /> </form>
These variables can be used in the query incase you intend to enter the information in MySQLCode:echo $_POST['name']; echo $_POST['dob']; echo $_POST['gender']; echo $_POST['country'];
This is most common type of going about it.Code:mysql_connect(mysql_server, username, password); mysql_select_db(db_name); mysql_query("INSERT INTO table_name (name, dob, gender, country) VALUES ('$_POST[name]', '$_POST[dob]', '$_POST[gender]', '$_POST[country]')");
this is how i would do it in php. suppose you want to create a table called categories:
of course, you would first need to connect to your database server but i think you know it already.PHP Code:<?php
$sql = ' CREATE TABLE categories ('
. ' categories_id int NOT NULL auto_increment,'
. ' categories_image varchar(64),'
. ' parent_id int DEFAULT \'0\' NOT NULL,'
. ' sort_order int(3),'
. ' date_added datetime,'
. ' last_modified datetime,'
. ' PRIMARY KEY (categories_id),'
. ' KEY idx_categories_parent_id (parent_id)'
. ' );';
mysql_query($sql);
?>
osc_osc
There are currently 1 users browsing this thread. (0 members and 1 guests)