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?

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

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`)

in your php file you have to write like

$con = mysql_connect("localhost","root","");
	if (!$con)
	  die('Could not connect: ' . mysql_error());
	 // 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]')";

your form structure like this

 <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" >

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?

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

use at top..so make easy for you..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.