PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old September 4th, 2004, 11:48 AM
Rand Dusing Rand Dusing is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 Rand Dusing User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 sec
Reputation Power: 0
PHP Insert to MySQL via Form

<html>
<head>
<title>Submit</title>
</head>

<body>
<?php

mysql_connect("localhost","admin","****") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("members") or die ("Unable to select requested database.");

//Assign contents of form to variables
$first = $_POST['first'];
$last = $_POST['last'];

mysql_query ( "INSERT INTO contacts (first, last) VALUES ('$first','$last');

echo mysql_error();
mysql_close();

?>

</body>
</html>


How do I make a form with the code above to send someones First and Last Name to the database?

Reply With Quote
  #2  
Old September 5th, 2004, 08:05 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 956 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 8 h 23 m 32 sec
Reputation Power: 4
Send a message via ICQ to Itsacon
Code:
<form action="script.php" method="post">
<input type="text" name="first" size="20" /> First name<br />
<input type="text" name="last" size="20" /> Last name<br />
<input type="submit" value="Store in database" /><input type="reset" value="Reset fields" />
</form>


However, to make sure you don't screw up your DB, I'd add length checks to the strings.
Hope this helps.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP Insert to MySQL via Form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway