473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Creating a table in mysql using a php form?

Well I am trying to make an admin section to allow my other admins of my site able to add content to my mysql database without giving them phpmyadmin access and without teaching them out to use it as well. So I am trying to make a form that they can use to fill in a few simple fields and then it create the tables in the database and then insert a row in a seperate table that is already made.

Here is how I want it to work...
Name:
Filename:
Category:
Header Image:

"Name" would be used for the print output saying that "NameHere has been added to the database" and also be used in inserting a value in a table that has already been created called "pageheaders".

The Filename will be used many times...this will be the from portion of the names of the tables as well as part of the insert into pageheaders.

Category will just be part of the insert into pageheaders.
Header Image is also just part of the insert.

Here is the form portion of what I am trying to do...the action is calling to another page where the sql stuff is because that is the only way I knew to do it but if you know a better way to have them in the same file then I am more than happy to use that.

Form Code:
Expand|Select|Wrap|Line Numbers
  1. <form action="tablesandinsert.php" method="post">
  2. Name: <input type="text" name="name"><br>
  3. Filename: <input type="text" name="filename"><br>
  4. Category: <input type="text" name="category"><br>
  5. Header Image: <input type="text" name="headerimage"><br>
  6. <input type="submit" value="Submit">
  7. </form>
And here is the sql code that is used for inserting and creating sql stuff...it doesnt actually insert anything or create the tables so I obviously did something wrong.

SQL Stuff:
Expand|Select|Wrap|Line Numbers
  1. $name=$_POST['name'];
  2. $filename=$_POST['filename'];
  3. $category=$_POST['category'];
  4. $headerimage=$_POST['headerimage'];
  5.  
  6. $query="CREATE TABLE `$filename_fins` (
  7.   `gif_id` mediumint(9) NOT NULL auto_increment,
  8.   `fingifurl` text NOT NULL,
  9.   PRIMARY KEY  (`gif_id`)
  10. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  11.  
  12. CREATE TABLE `$filename_trons` (
  13.   `gif_id` mediumint(9) NOT NULL auto_increment,
  14.   `trongifurl` text NOT NULL,
  15.   PRIMARY KEY  (`gif_id`)
  16. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  17.  
  18. CREATE TABLE `$filename_misc` (
  19.   `gif_id` mediumint(9) NOT NULL auto_increment,
  20.   `miscgifurl` text NOT NULL,
  21.   PRIMARY KEY  (`gif_id`)
  22. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  23.  
  24. INSERT INTO `pageheaders` VALUES ('$name', '$filename', '$headerimage', '$category/$filename/index');";
  25. $result=mysql_query($query);
  26. Print "$name has been successfully added to the database.";
  27. ?>
so any help on where I went wrong?
Aug 10 '06 #1
2 3807
Niheel
2,460 Expert Mod 2GB
Your insert needs to be assiged to the variable $query

ex:
[PHP]
$query = "INSERT INTO 'pageheaders' . . . ";
$result = mysql_query($query);
if($query){
print "your output hoes here";
}
[/PHP]
Aug 11 '06 #2
First connect with the mysql database.
Then select your Database.
then select your table into which the datas should be stored.
Everything in php code.

get the variables using post method

$f1=$_POST['fieldname1']
$f2=$_POST['fieldname2']

insert into `table_name`(`fieldname1`,`fieldname2`....)values( '$f1','$f2'.....);
Aug 12 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: gonzalo briceno | last post by:
I have been using phplib for a while and I really like the framework except for form creation. Maybe it is me but I in my opinion there isn't a good way to create forms or should I say, everything...
11
by: Joshua Beall | last post by:
Hi All, I am working on a registration system, and one of the things I am going to need to be able to do it setup the database tables for each event that I have registration for. Normally I...
0
by: Michael Iatauro | last post by:
I've been having a little trouble creating users cross-platform. I have a little script that works just fine on Solaris 8 using this command: eval "/path/to/mysql --user=root --password=*****...
2
by: Matthew Clubb | last post by:
Hi, I need help developing an expanding form I've decided that a use of PHP, Mysql and Javascript is the best platform for creating a selection of database interfaces which I'm trying to build...
2
by: phpuser32423 | last post by:
Hi everyone Is it by any chance possible to use mysql and php to auto create the content for drop-down lists on forms by retrieving the values from a database? The reason i ask is that on a site...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
4
by: Bob | last post by:
Hi all, I've got a table that I've imported and it has junk at the top of the table, so after import I run a delete query to remove the junk lines then I'm left with the field names I want for...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
2
by: divyac | last post by:
I have developed an address book using php and mysql.I have all the contacts list in a table with check boxes.Now that i want to create mailing labels for the checked contacts...i.e.,the arrangements...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.