How to insert data from _POST

#1
[eluser]jabga[/eluser]
Hi there.
This is my addnews.php
Code:
<?php

class Addnews extends Controller {

    function addnews()
    {
        parent::Controller();    
    }
    function index ()
    {
        $this->load->view('insertnews');        

    }

This is insertnews.php
Code:
<html>
<body>
<?php $sql="INSERT INTO news (title, content, category)
VALUES
('$_POST[title]','$_POST[content]','$_POST[category]')";
?>
<form action="" method="post">
Title: <input type="text" name="title" />
Content: <input type="text" name="content" />
Category: <input type="text" name="category" />
<input type="submit" />
</form>

</body>
</html>


There are following errors occuring when I click on the submit button
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: title

Filename: views/insertnews.php

Line Number: 7



Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: content

Filename: views/insertnews.php

Line Number: 7


Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: category

Filename: views/insertnews.php

Line Number: 7

How can I add news from insert form easily? Please tell me

#2
[eluser]jabga[/eluser]
Should I use helper or class or model ?
I am trying to create a small website for practice.

Here is my html design
http://download.idiotsheep.com/Dulaanurguu Static.zip





ok ok I hAve found it
http://www.phpeveryday.com/articles/Code...-P228.html

#3
[eluser]n0xie[/eluser]
You shouldn't put your sql in your view. It belongs in your model. Take a look at the CodeIgniter tutorials

#4
[eluser]jabga[/eluser]
Tnx, I have got it.
i have finished watching CI tutorial and also this tutorial is very useful
http://www.phpeveryday.com/articles/Code...-P228.html
Tnx

#5
[eluser]anyshpm[/eluser]
codeigniter tutorial is always helpful

#6
[eluser]Zack Kitzmiller[/eluser]
You were missing 's anyway.

$_POST['title']

#7
[eluser]richfearless[/eluser]
Try this

Code:
<?php $sql="INSERT INTO news (title, content, category)
VALUES
('".$_POST[title]."','".$_POST[content]."','".$_POST[category]')."";
?>

#8
[eluser]InsiteFX[/eluser]
Data access should be done in your model! Like n0xie stated above.

Enjoy
InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.