Welcome Guest, Not a member yet? Register   Sign In
Form to database
#1

[eluser]grejsimojs[/eluser]
Hello,

I am new to this, and I'd really appreciate a little help.

I want to send the info filled in a form to a database that I'm currently working on. How exactly can I do this?

Here's a piece of the form (which lies in Views):

Code:
<form>
CSR Number: &lt;input type="text" name="csrnumber"&gt;&lt;br><br>
&lt;/form&gt;

&lt;form&gt;
Severity:
&lt;input type="radio" name="severity" value="high"&gt;High &nbsp;&nbsp;
&lt;input type="radio" name="severity" value="medium"&gt;Medium &nbsp;&nbsp;
&lt;input type="radio" name="severity" value="low"&gt;Low &nbsp;&nbsp;
&lt;input type="radio" name="severity" value="other"&gt;Other<br><br>
&lt;/form&gt;

They belong to the same form (the same page called createsticker.php). Have I done it the correct way in terms of making two &lt;form&gt;'s?

And to my main question: How do I put in the information filled in on this form to the database?

Thank you!
#2

[eluser]weblyan[/eluser]
No, only one form tag can be posted from one page to another. You need to put all the input tags in the same form tag.
Code:
&lt;form action="" method="post"&gt;
CSR Number: &lt;input type="text" name="csrnumber"&gt;&lt;br><br>

Severity:
&lt;input type="radio" name="severity" value="high"&gt;High &nbsp;&nbsp;
&lt;input type="radio" name="severity" value="medium"&gt;Medium &nbsp;&nbsp;
&lt;input type="radio" name="severity" value="low"&gt;Low &nbsp;&nbsp;
&lt;input type="radio" name="severity" value="other"&gt;Other<br><br>
&lt;/form&gt;

The action attribute in the form should be the target url, the url to where the form will be sent

Then in the controller or model, you will handle the data sent by the form.
If you are not using a framework then you would access the input data like this $severity = $_POST['severity'].
But in Codeigniter you will access the data using $severity = $this->input->post('severity');

To get the data into the database, look at this: http://ellislab.com/codeigniter/user-gui...index.html




Theme © iAndrew 2016 - Forum software by © MyBB