Jump to content

Recommended Posts

To start, let me say that I'm new to both MySQL and PHP.  If fact, this is the first time I've tried to build anything from scratch with both.  I've worked with databases before and have a good understanding of how they are supposed to work, but I obviously have no idea how to use PHP to connect to one.

 

If my question has been answered in another post, please accept my apologies and direct me to said post.

 

My problem is that I have a database that I'm trying to add data into using a simple form.  When I fill in the form and hit my Submit button...nothing happens beyond the form fields clearing themselves.  After hitting Submit, I pull up the database in phpMyadmin and there is no new data to be seen anywhere.

 

Here's the code for the form page:

 

 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RMVD</title>
</head>

<body>
<form id="contacts" name="contacts" method="post" action"contacts_insert.php">
<p>Parent's First Name:
<input name="first" type="varchar" id="first" />
</p>
<p>Parent's Last Name:
<input name="last" type="varchar" id="last" />
</p>
<p>Second Parent's First Name:
<input name="first2" type="varchar" id="first2" />
</p>
<p>Parent's Last Name:
<input name="last2" type="varchar" id="last2" />
</p>
<p>Home Phone:
<input name="homephone" type="varchar" id="homephone" />
</p>
<p>Cell Phone:
<input name="cellphone" type="varchar" id="cellphone" />
</p>
<p>Work Phone:
<input name="workphone" type="varchar" id="workphone" />
</p>
<p>E-Mail Address:
<input name="email" type="varchar" id="email" />
</p>
<input type="submit" name="Submit" value="Submit" />
</form>


</body>
</html>

 

And the code for contacts_insert.php

 

 
<?php
$host="***removed***";
$user="***removed***";
$password="***removed***";
$database="contacts";

mysql_connect($host,$user,$password)or die("Can not connect DB");
@mysql_select_db($database) or die( "Unable to select database");

$first=$_POST['first'];
$last=$_POST['last'];
$first2=$_POST['first2'];
$last2=$_POST['last2'];
$homephone=$_POST['homephone'];
$cellphone=$_POST['cellphone'];
$workphone=$_POST['workphone'];
$email=$_POST['email'];
mysql_query("INSERT INTO contacts(first, last, first2, last2, homephone, cellphone, workphone, email) values('$first','$last','$first2','$last2','$homephone','$cellphone','$workphone','$email')");
mysql_close();
?>

 

Here is the SHOW CREATE TABLE information:

 

Table 	Create Table
contacts 	CREATE TABLE `contacts` (
`id` int(6) NOT NULL auto_increment,
`first` varchar(30) NOT NULL,
`last` varchar(30) NOT NULL,
`first2` varchar(30) NOT NULL,
`last2` varchar(30) NOT NULL,
`homephone` varchar(20) NOT NULL,
`cellphone` varchar(20) NOT NULL,
`workphone` varchar(20) NOT NULL,
`email` varchar(30) NOT NULL,
PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8

 

and the EXPLAIN data:

 

Generation Time: Apr 22, 2009 at 11:59 AM
Generated by: phpMyAdmin 2.11.9.4 / MySQL 5.0.67.d7-ourdelta-log
SQL query: EXPLAIN contacts ;
Rows: 9
Field 	Type 	Null 	Key 	Default 	Extra
id 	int(6) 	NO 	PRI 	NULL 	auto_increment
first 	varchar(30) 	NO 	  	NULL 	 
last 	varchar(30) 	NO 	  	NULL 	 
first2 	varchar(30) 	NO 	  	NULL 	 
last2 	varchar(30) 	NO 	  	NULL 	 
homephone 	varchar(20) 	NO 	  	NULL 	 
cellphone 	varchar(20) 	NO 	  	NULL 	 
workphone 	varchar(20) 	NO 	  	NULL 	 
email 	varchar(30) 	NO 	  	NULL 	 

I'm sure I missed something simple and will subsequently feel like an idiot when it has been pointed out to me...but I'm willing to risk it and would appreciate any help you could offer me.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.