Jump to content

Add/remove input field & mysql


faces3

Recommended Posts

Hey! 

I work for add/remove input field and mysql.

But im newbie and little bit problems with it.

I want all field data save new row.

 

Here is script.

<html>
<head>
<title>Silmaring</title>
<meta name="description" content="Silmaring">
<meta name="author" content="Silmaring">
<STYLE type="text/css">
   #ained {
position:absolute;
margin-top:40px;
}
  #ope {
position:absolute;
margin-top:40px;
margin-left:200px;
}
#lisa {
position:absolute;
margin-top:500px;
}
 </STYLE>
</head>
<body>
	 <form action= "" method="post" enctype="multipart/form-data">
	 <H2>Registeeri uus kool</h2>
Koolinimi:
 <input type="text" name = "kool" size="15" /></br>

 <div id="ained">
Ained:</br>
<input type="text" name="aine" id="aine"><br>
<input type="text" name="aine" id="aine"><br>
</div>
<div id="ope">
Õpetajad:
<input type="text" name="ope" id="ope"><br>
<input type="text" name="ope" id="ope"><br>
</div>

<div id="lisa">
</br><input type="submit" value="Lisa kool" />
 </div>
</form>
</body>
</html>
<?php
error_reporting(E_ALL ^ E_NOTICE);
$kool = $_REQUEST['kool'];
$aine = $_REQUEST['aine'];
$ope = $_REQUEST['ope'];
// MySQL uhendus
$user="root";
$password="";
$database="silmaring";
$con="localhost";
mysql_connect($con,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
mysql_query("CREATE TABLE $kool(id int(6) NOT NULL auto_increment,aine varchar(50) NOT NULL,opetaja varchar(50) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))"); 
mysql_query("INSERT INTO $kool(aine,opetaja) VALUES ('$ope','$ope')");
mysql_query("INSERT INTO $kool(aine,opetaja) VALUES ('$ope','$ope')");
mysql_close();
?>

Link to comment
Share on other sites

That is better done with javascript. Just make new elements named aine[] and ope[] (not that one mistake you currently have already is that id's in html must be unique).

 

This will create an array of form fields which you can then simply loop through in php.

Link to comment
Share on other sites

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.