Happy Holidays!

I have a one field form. Upon submission with the submit button, I wish to drive this field value into my SQL database table called MEMBERS and field called NAMES, thus adding a new record.

Can this be done with an OnSubmit() call to a function, in the HEAD of the HTML form page, which contains a series of statements opening the database, entering the data, and closing the database?

<tr>
	<td class="mystyle">Your Full Name:</td>
	<td><input type="text" name="Name" size="30"></td>
</tr>

Create table in mysql--

create database in mysql with name db_name

CREATE TABLE `table_user` (
  `user_id` int(2) NOT NULL auto_increment,
  `user_fname` varchar(10) NOT NULL,
  `user_lname` varchar(10) NOT NULL,
  
  PRIMARY KEY  (`user_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1123 ;

in your php file you have to write like

$con = mysql_connect("localhost","root","");
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	  }
	  else
	  {
	 // echo('Connected with Mysql');
	  }

@mysql_select_db("db_name", $con);// connect to database db_name


	if (isset($_POST['Submit']))
	{
$sql="INSERT INTO table_user (user_fname, user_lname)	VALUES('$_POST[user_fname]','$_POST[user_lname]')";
		@mysql_query($sql,$con);

your form structure like this

<table>
 <td width="141" align="left" valign="top" >First Name</td>
                          <td width="163" align="left" valign="top"><input name="user_fname" type="text" id="user_fname"></td>
<td align="left" valign="top" >Last Name</td>
                          <td colspan="4" align="left" valign="top"><input name="user_lname" type="text" id="user_lname">

<input name="Submit" type="submit" value="Submit" >
</table>

Thank! Great response. How would you define the 'root' or do I leave the word 'root' as is. Where do I define the url to the server?

Oh, also...where is the connection script placed? Is that PHP or Javascript or HTML? Can I place it anywhere in the code?
Thx

for localhost default user name and password
user name--root
password--"" (blank)

if you want run on server
create user name and password on server & use it

This article has been dead for over six months. Start a new discussion instead.