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.
Forms
Re: Forms
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.
all you have to do is retrieve the form data like this
<?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.
this is just the pure basics.
If you need more help, feel free to post here or private message me.
Note: I hope I haven't missed anything crucial. I apologize in advance for any errors or typos.
Re: Forms
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']; ?>
Re: Forms
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']; ?>
-
- Posts: 14
- Joined: Fri Nov 11, 2011 12:32 pm
- Location: India
Re: Forms
<?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
Re: Forms
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]
yes, that works. But you do not have to put mysql_query in a variable. It will run on its own and since you're only inserting data, not retrieving any, the variable will never have a value.
what you can do is this:
$query = "INSERT INTO ´cs09(`regno`,`name`) VALUES ('{$regno}','{$name}')";you can choose which columns to insert into.
/Edit:
I didn't notice the space in your query ( where the ID field is ) without syntax tags. What you're doing now is actually inserting a space in the ID field.
at least I think so. I don't know if mysql takes a space as a valid character or if it treats it like null.
-
- Posts: 14
- Joined: Fri Nov 11, 2011 12:32 pm
- Location: India
Re: Forms
i got the output ,,,, thank you very much ...
$query = "INSERT INTO cs09 (id,regno) values(' ','$regno','$name');
$query = "INSERT INTO cs09 (id,regno) values(' ','$regno','$name');