|
| |||||||
![]() | Welcome to iWEBTOOL Talk, where you talk about
webmaster-related stuff.
1 Register
2 Browse the board
3 Discuss whatever may interest you! | |||||||||||||
![]() |
| | Thread Tools | Search this Thread | Display Modes |
| | #1 |
| Newcomer Join Date: Oct 2006
Posts: 2
![]() | I have made a website for an athletics club and currently have to add in manually a table in dreamweaver and type in each new record that the athletes achieve each week. I wish to make it dynamic so that they can add in all the records themselves without having to email them to me to put in manually. It's difficult to do because each week there is a new set of records that i have to add in, therefore i would have to add in a new MySQL table for each week with the appripriate fields. I am using PHP, how can I set it up so that there is a page where you can insert a new TABLE into the database via the web browser, just by typing the name into a field and clicking insert, and it adds that table into the database with the fields already set up for it. Then the next page I want to be able to add in each row of records that the athletes have and then display them all on a page. Here's an example of what i mean http://www.forestlakeslac.com/docs/records.html Here you can see what I mean, how would i go about making it dynamic? HUGE HUGE thanks to whoever can solve this, and your a legend if u can ![]() |
| |
|
| |||||||
| | #2 |
| Junior Member Join Date: Oct 2006
Posts: 32
![]() | If I am understanding you correctly, this would be fairly easy to do. Create a form with fields for the table name and each field for that table. The user submits that page and the mysql table and fields are created. The user can then pull up that table and enter the data themselves. To do this I would post the data to a script that will look something like this: $query = 'CREATE TABLE $tablename( '. '$field1 INT NOT NULL AUTO_INCREMENT, '. '$field2 VARCHAR(20) NOT NULL, '. '$field3 VARCHAR(50) NOT NULL, '. '$field4 VARCHAR(30) NOT NULL, '. '$field5 TEXT NOT NULL, '; I did not include all of the php required as you seem to have some knowledge of it. You will want to be careful about security or add a user login as you don't want anyone just being able to create tables at random and want to avoid mysql injection. PM me for further help if needed. I could probably write this for you in a day but right now I am very busy but I will help all I can find time for. PS> That webserver you are hosting that on seems very slow. |
| |
| | #3 |
| Newcomer Join Date: Oct 2006
Posts: 2
![]() | Thanks for that, you seem to understand my situation. I cant PM you because it says i need to have more than 10 posts and ive only made 1. This is what i have so far: A page called addtable.php, it contains only a form and no php code. The text field name is "tablename" which is posted to the next page. <form id="form1" name="form1" method="post" action="stuff.php"> <p>Table Name: <input name="tablename" type="text" id="tablename" /> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> The page that the form action is set to is called stuff.php It contains the connection and the code to create the new table. <?php require_once('Connections/conn.php'); ?> <?php $tablename = $_POST['tablename']; $sql = 'DROP TABLE IF EXISTS `zonessss`'; mysql_query( $sql, $conn ); $sql = 'CREATE TABLE $tablename ( `zid` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT, `zdesc` VARCHAR( 150 ) NOT NULL, `zwidth` SMALLINT( 3 ) DEFAULT 0 NOT NULL, `zheight` SMALLINT( 3 ) DEFAULT 0 NOT NULL, `zmax` MEDIUMINT(7) unsigned NOT NULL default 12288, PRIMARY KEY ( `zid` ) )'; echo "Creating table: $tablename"; mysql_query( $sql, $conn ); ?> This doesnt yet work though, whenever I run it, the new table doesnt get added to the database. I was playing around with it before and somehow got it to work and it added the new table in, unfortunately i cant remember how i did it. But also, it did not name that table to the name that i entered into the text field on 'addtable.php', instead the name of the database was the variable name that i assiged it to '$tablename'. So the table was there with all the correct fields in but its name was $tablename. Any suggestions?? PS> Sorry for the slow host speed, that site is hosted on my own home server running off my ADSL connection with a 256k upload. Will upgrade eventually. |
| |
| | #4 |
| Junior Member Join Date: Oct 2006
Posts: 32
![]() | Try this, it worked for me. <?php require_once('Connections/conn.php'); ?> <?php $tablename = $_POST['tablename']; $sql = 'DROP TABLE IF EXISTS `zonessss`'; $qry=mysql_query($sql)or die(mysql_error()); $sql = "CREATE TABLE $tablename ( `zid` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT, `zdesc` VARCHAR( 150 ) NOT NULL, `zwidth` SMALLINT( 3 ) DEFAULT 0 NOT NULL, `zheight` SMALLINT( 3 ) DEFAULT 0 NOT NULL, `zmax` MEDIUMINT(7) unsigned NOT NULL default 12288, PRIMARY KEY ( `zid` ) )"; echo "Creating table: $tablename"; $qry=mysql_query($sql)or die(mysql_error()); ?> Email me instead. I can't PM either yet. FYI, adding this or die(mysql_error()); to your queries can really help debug things, in case you didn't know. Remove them before putting them live as showing the errors can give hackers an insight to your mysql structure. |
| |
(Threads which have no activity for more than 30 days are automatically closed.) |
| Quick Reply | ||
|
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is your Professional? | dreamsubmitting | General Talk | 4 | 10-04-2006 11:20 PM |
| How to Be Professional Online | compuXP | Web Development | 5 | 10-01-2006 05:27 PM |
| Does my site look professional? | Albert Tai | Website Reviews | 8 | 06-14-2006 02:20 AM |