473,396 Members | 2,121 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,396 software developers and data experts.

Insert into MySQL database using html form and php

I am a big novice with MySQL and PHP. I need a script that enters
information from a html form into a MySQL database. Can anyone tell me
where I can find one that I can just replace the table and database
name? PLEASE I NEED IT ASAP!!!

Jul 17 '05 #1
2 12208
> I am a big novice with MySQL and PHP. I need a script that enters
information from a html form into a MySQL database. Can anyone tell me
where I can find one that I can just replace the table and database
name? PLEASE I NEED IT ASAP!!!

form.htm
<html><head><title>Your title</title></head><body>
<form name="form1" method="post" action="input.php">
<input type=text name=001>
<input type=text name=002>
<input type=text name=003>
etc. etc.
Submit button
</form>
</body></html>
end of form.htm

input.php
<?php
$db = mysql_connect("server","username","password") or die("Cannot connect
to server");
mysql_select_db("databasename",$db) or die("Cannot find database");
$sql = mysql_query("INSERT INTO tablenam (field1, field2, field3, the names
of your fields in the table) VALUES('$001', '$002', '$003', 'the names of
the input types you want to insert in the fields in your database')") or die
(mysql_error());

?>
end of input.php

Martijn
Jul 17 '05 #2
Astonishing! Dogs scampered and hid under sideboards, hamsters stopped
turning in their wheels, and silence fell as RotterdamStudents paused,
put down his Happy Meal, and blurted:
I am a big novice with MySQL and PHP. I need a script that enters
information from a html form into a MySQL database. Can anyone tell
me where I can find one that I can just replace the table and
database name? PLEASE I NEED IT ASAP!!!
form.htm
<html><head><title>Your title</title></head><body>
<form name="form1" method="post" action="input.php">
<input type=text name=001>
<input type=text name=002>
<input type=text name=003>
etc. etc.
Submit button
</form>
</body></html>
end of form.htm

input.php
<?php


You might want to put something like this here:

$001 = htmlspecialchars($_POST['001']);
$002 = htmlspecialchars($_POST['002']);
$003 = htmlspecialchars($_POST['003']);

$db = mysql_connect("server","username","password") or die("Cannot
connect
to server");
mysql_select_db("databasename",$db) or die("Cannot find database");
$sql = mysql_query("INSERT INTO tablenam (field1, field2, field3, the
names of your fields in the table) VALUES('$001', '$002', '$003', 'the
names of the input types you want to insert in the fields in your
database')") or die (mysql_error());

?>
end of input.php

Martijn


--

You read too far. You should stop the moment you see Von Heler." Archangel
"long lunged + acting 'interesting' = Von Heler" Football Commentator


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
1
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. ...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
5
by: Bonzol | last post by:
Hello, PHP n00b here. Using SQL just working off some examples, I have no problem selecting data, but I cant seem to be able to insert. If someone could see where im going wrong <!DOCTYPE...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
7
by: dongletran06 | last post by:
Hi, Please help me find out what wrong with my codes in inputting from my form to mysql database using drop down menu. Below is the codes I used. Only the drop down is not working but the "input...
3
by: ctrap | last post by:
Hi Everyone, Here's my situation: I'm making a website for an employment agency, there is a page where potential employees can visit and "pre-register". When the submit button is hit the...
2
by: adamace5o | last post by:
When i try to use post variables with php and mysql i can't get the insert into statement to accept varibles as values. If i use 'test' instead of $test it does work. I suspect it is something to do...
0
by: brianrpsgt1 | last post by:
I am attempting to insert data from a HTML form using a .psp script. I can not find how to link the data that is inserted into the form to the variables in the .psp script to then insert into the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.