Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 02-06-2005, 05:09 AM   #1 (permalink)
plomon
Registered User
 
Join Date: Feb 2005
Posts: 5
plomon is on a distinguished road
Question How to insert HTML form data into mysql database ?

hi there,

In my website(built usind Dreamweaver), I created a form having certain fields. My site is being hosted by "www.freefronthost.com" website. A personal mySQL database is given to me by the host specified above. I know the commands of mySQL sufficiently. Please help me insert the form data into the mySQL database using PHP. I know nothing about PHP, but I know JSP, Javascripting and HTML coding. So, if anybody could provide me the HTML code embedded with PHP to insert the form details into mySQL, I will try grasp it, and it will be a great help for me.
plomon is offline   Reply With Quote
Old 02-06-2005, 07:05 AM   #2 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 285
technobard is on a distinguished road
There are a lot of tutorials out on the web that cover this pretty well. Check out http://webmonkey.wired.com/webmonkey...tutorial4.html
Lesson 2 covers forms.
__________________
It takes 2 points to draw a straight line, but at least 3 points to draw a conclusion.
technobard is offline   Reply With Quote
Old 02-06-2005, 07:39 AM   #3 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Just set the html form to post to itself or another PHP page.

in the php page, grab the post vars and run the necessary mysql commands.

PHP Code:
$id $_POST['id'];
$html_data $_POST['foo'];

// mysql connect /etc..

$sql "INSERT INTO table_name (id, data) VALUES ('{$id}', '{$html_data}');";
mysql_query($sql); 
Also, no need for 3 crossposts..

-r
idx is offline   Reply With Quote
Old 02-06-2005, 07:48 AM   #4 (permalink)
plomon
Registered User
 
Join Date: Feb 2005
Posts: 5
plomon is on a distinguished road
hello idx,

Can you give me the complete script of posting(say) three fields namely "name","age","email" into a mySQL database located at a remote server(not localhost) using PHP coding.

Another doubt, since, I built the "form" in Dreamweaver as a HTML page, so, by introducing php script in between the HTML tags using <? ... >, will the page be saved as .php page or .html page on clicking the save button.
plomon is offline   Reply With Quote
Old 02-06-2005, 08:21 AM   #5 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
You just need to specify the remote host in your mysql_connect() command.

PHP Code:
mysql_connect('remote_host_or_ip''username''password'); 
Then from there construct a similar SQL statement to my example above. Just grab the different var name from $_POST such as $_POST['email'] (if that is your html field name), $_POST['age'], etc..


As far as dreamweaver, it will probably be saved as .html unless it's smart enough to see the php tags and rename. One problem with that is that [typically] the webserver isn't setup to parse .htm/.html files with the PHP processor. So you'll need to rename the html file yourself..

-r
idx is offline   Reply With Quote
Old 02-06-2005, 08:23 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
hey plomon, the concept is a lot like jsp. one thing not showed is the connect to mysql. just fill in the information in the mysql_connect string here. if it is a remote server, just put in the ip.
PHP Code:
<?
if (!$dbcnx mysql_connect("server""user""password"))
  die(
"Could not connect to MySQL DB: " mysql_error());
?>
this should probably be at the top of the page. now, idx gave you a good example, and if you know jsp, then i assume you may also have a grasp on the sql language ( so i wont' go into details on your sql insert )

$id = $_POST['id']; is exactly the same thing as you using: String id = request.getParameter("id"); in jsp.

if you needed to access the variable 'age' from your form, then you would use $_POST['age']

let us know how it goes.
__________________
Mike
sde is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't see MySql database records in Mozilla monicao PHP 3 05-02-2004 05:19 PM
dotnet Data Access reader vs adapter, and MySQL APIs vs SQL2k sde MS Technologies ( ASP, VB, C#, .NET ) 3 12-04-2003 06:45 AM
MYSQL - insert jimmyoctane PHP 7 09-15-2003 01:15 PM
HTML form preview then INSERT using PHP & MySQL SteveSoler PHP 5 07-07-2002 09:54 AM
Passing form data to PHP with Javascript bdl PHP 5 07-03-2002 10:18 AM


All times are GMT -8. The time now is 02:24 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting