Forms
Posted: Wed Dec 07, 2011 4:04 pm
how to store the inputs in the form into the database when the "submit" button is clicked ?
i am using the "id" as auto increment.
i am using the "id" as auto increment.
your form data gets stored in a $_POST array or a $_GET array depending on what method your form is using.kpkguru003 wrote:how to store the inputs in the form into the database when the "submit" button is clicked ?
i am using the "id" as auto increment.
<?php $value1 = $_POST['value1']; $value2 = $_POST['value2']; ?>
//action is where you send the user after pressing submit. leaving this blank redirects to the same page. //method is the method in which the form will store the data inserted into the field(s). You can choose either get or post. <form action="" method="post"> //the name value1 corresponds to $_POST['value1'] and value2 corresponds to $_POST['value2']. i.e whatever you name this is what you will have to put in $_POST['here']. <input type="text" name="value1" /> <input type="text" name="value2" /> <input type="submit" value="Submit" /> </form>after that you'll just have to write the query to insert it into your database.
$sql = "INSERT INTO `table`(`column1`, `column2`) VALUES('{$value1}','{$value2}')";and then you have to run the query.
mysql_query($sql);you might want to add some error handling in this, and also some security.
There is no need to do this if you are not doing anything to the $_POST variables ! $_POST could be used in the SQL directly.Temor wrote:all you have to do is retrieve the form data like this
<?php $value1 = $_POST['value1']; $value2 = $_POST['value2']; ?>
that is true. I only did that so that it would make more sense down the linejacek wrote:There is no need to do this if you are not doing anything to the $_POST variables ! $_POST could be used in the SQL directly.Temor wrote:all you have to do is retrieve the form data like this
<?php $value1 = $_POST['value1']; $value2 = $_POST['value2']; ?>
<?php $regno=$_POST['regno']; $name =$_POST['name']; $query = "INSERT INTO `cs09` values(' ','$regno','$name')"; $query_run = mysql_query($query); ?>Is this correct , the first field is "Id" which is auto increment , so i left it blank
Please put your code in syntax tagskpkguru003 wrote:<?php $regno=$_POST['regno']; $name =$_POST['name']; $query = "INSERT INTO `cs09` values(' ','$regno','$name')"; $query_run = mysql_query($query); ?>Is this correct , the first field is "Id" which is auto increment , so i left it blank
[syntax=php]Code goes here[/syntax]
$query = "INSERT INTO ´cs09(`regno`,`name`) VALUES ('{$regno}','{$name}')";you can choose which columns to insert into.