|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > PHP Insert to MySQL via Form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|