tammyhart
01-21-2005, 01:52 PM
Can anyone point me in the right direction to learn how to add info to a MySQL database with a web based form?
![]() | View Full Version : form to MySQL tammyhart 01-21-2005, 01:52 PM Can anyone point me in the right direction to learn how to add info to a MySQL database with a web based form? EXOWorks 01-21-2005, 02:24 PM A programming language needs to be involved. Learn PHP! Find some tutorials and get learning php.. tammyhart 01-21-2005, 06:25 PM *sigh* the guy's hosting doesn't supposrt ASP or perl... I'm guess he does PHP since he has MySQL. Is that the only way that he can have a form on his site and anytime someone submits a form it'll catalog the information, or are there any other ways, maybe something online that he can subscribe to? sonic10 01-21-2005, 07:31 PM Here is a Simple Contacts Example database using php to add data~ Insert a form like so in the web page: <form action="insert.php" method="post"> First Name: <input type="text" name="first"><br> Last Name: <input type="text" name="last"><br> Phone: <input type="text" name="phone"><br> Mobile: <input type="text" name="mobile"><br> Fax: <input type="text" name="fax"><br> E-mail: <input type="text" name="email"><br> Web: <input type="text" name="web"><br> <input type="Submit"> </form> Modify these two files to use your info and upload to web server Filename: dbinfo.inc.php <? $username="your_username"; $password="your_password"; $database="your_database_name"; ?> Filename: insert.php <? include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')"; mysql_query($query); mysql_close(); ?> If this guy's host does not support cgi or perl scripts it may be time to recommend a better host.... tammyhart 01-22-2005, 01:14 AM Originally posted by sonic10 If this guy's host does not support cgi or perl scripts it may be time to recommend a better host.... [/B] OH yeah, my thoughts exactly. It's some kind of home insurance company.. in the dark ages, probably. Thanx for the help, I'll check it out when my brain checks back in, it's been a busy day. DealMerchant 01-22-2005, 02:00 AM Looking at sonic10's code post, you might want to make a small change: When submitting your form information via POST, you need to retrieve the values from the server. This can be done by using the following: $first = $_POST["first"]; This will retrieve the value entered in the form for the first name. Also, you may want to add some sort of verification to your mysql query, so that you know if it was added to the database correctly. $result = mysql_query($query); if(! $result) die("Failed to add to database."); This will display an error message if there is some sort of error in your mysql query. Hope this helps. |