Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6834547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:07:29+00:00 2026-05-26T23:07:29+00:00

I am noob in CI and I can’t insert a data in database, here

  • 0

I am noob in CI and I can’t insert a data in database, here is all I have done, it doesn’t show me an error but i don’t get a result,

admin.php (controller)

public function postnews(){

        $ip = $_SERVER['REMOTE_ADDR'];
            if ($ip == "my ip address"){

                session_start();

                if (!isset($_SESSION['admin'])){
                    $this->load->view('admin-login');
                    die(0);
                    }

                if ($_SESSION['admin'] != 'loged'){
                    $this->load->view('admin-login');
                    die(0);
                    }

                if ($_SESSION['admin'] == 'loged'){

                    if (isset($_POST['title'])and isset($_POST['main-poster']) and isset($_POST['type']) and isset($_POST['year']) and isset($_POST['language'])and isset($_POST['platform'])and isset($_POST['publisher'])and isset($_POST['size'])and isset($_POST['graphics'])and isset($_POST['little-info'])and isset($_POST['full-info'])and isset($_POST['posters'])and isset($_POST['screenshots'])and isset($_POST['trailers'])and isset($_POST['gameplays'])and isset($_POST['author'])){

                        $title = $_POST['title'];
                        $main_poster = $_POST['main-poster'];
                        $type = $_POST['type'];
                        $year = $_POST['year'];
                        $language = $_POST['language'];
                        $platform = $_POST['platform'];
                        $publisher = $_POST['publisher'];
                        $size = $_POST['size'];
                        $graphics = $_POST['graphics'];
                        $little_info = $_POST['little-info'];
                        $full_info = $_POST['full-info'];
                        $posters = $_POST['posters'];
                        $screenshots = $_POST['screenshots'];
                        $trailers = $_POST['trailers'];
                        $gameplays = $_POST['gameplays'];
                        $autor = $_POST['author'];
                        $date = date("d.m.Y");

                        $this->load->model('Gamesmodel');
                        echo $this->Gamesmodel->PostArticle($title, $main_poster, $type, $year, $language, $platform, $publisher, $size, $graphics, $little_info, $full_info, $posters, $screenshots, $trailers, $gameplays, $autor, $date);

                    }else{
                        $this->load->view('postnews');
                    }

                }

            } else {
                $this->load->view('404.htm');
                die(0);
            }

    }

gamemodel.php model

<?php
class Gamesmodel extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function PostArticle($title, $main_poster, $type, $year, $language, $platform, $publisher, $size, $graphics, $little_info, $full_info, $posters, $screenshots, $trailers, $gameplays, $autor, $date)
    {
        $sql = "INSERT INTO game-articles (id, title, type, year, language, platform, publisher, size, graphics, little-info, full-info, posters, screenshots, trailers, gameplays, date, author) VALUES ('' ,".$this->db->escape($title).",".$this->db->escape($main_poster).",".$this->db->escape($type).",".$this->db->escape($year).",".$this->db->escape($language).",".$this->db->escape($platform).",".$this->db->escape($publisher).",".$this->db->escape($size).",".$this->db->escape($graphics).",".$this->db->escape($little_info).",".$this->db->escape($full_info).",".$this->db->escape($posters).",".$this->db->escape($screenshots).",".$this->db->escape($trailers).",".$this->db->escape($gameplays).",".$this->db->escape($date).",".$this->db->escape($author).")";
        $this->db->query($sql);
        return $this->db->affected_rows();
    }
}

postnews.php view

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Post News</title>
</head>
<body style="background-color:black;">
    <div style="margin:auto auto auto auto; width:800px; background-color:white; padding-top:20px; padding-bottom:20px; text-align:center;">
        <form action="http://www.gameslib.net/admin/postnews" method="post"><br />
            <input type="text" placeholder="title" name="title" style="width:300px;" /><br />
            <input type="text" placeholder="main poster" name="main-poster" style="width:300px;" /><br />
            <input type="text" placeholder="type" name="type" style="width:300px;" /><br />
            <input type="text" placeholder="year" name="year"/><br />
            <input type="text" placeholder="language" name="language" style="width:300px;" /><br />
            <input type="text" placeholder="platform" name="platform" style="width:300px;" /><br />
            <input type="text" placeholder="publisher" name="publisher" style="width:300px;" /><br />
            <input type="text" placeholder="size" name="size"/><br />
            <input type="text" placeholder="graphics" name="graphics" style="width:300px;" /><br />
            <textarea name="little-info" placeholder="little-info" style="width:600px; height:100px;" ></textarea><br />
            <textarea name="full-info" placeholder="full-info" style="width:600px; height:200px;" ></textarea><br />
            <textarea name="posters" placeholder="posters" style="width:600px; height:50px;" ></textarea><br />
            <textarea name="screenshots" placeholder="screenshots" style="width:600px; height:50px;" ></textarea><br />
            <textarea name="trailes" placeholder="trailes" style="width:600px; height:50px;" ></textarea><br />
            <textarea name="gameplays" placeholder="gameplays" style="width:600px; height:50px;" ></textarea><br />
            <input type="text" placeholder="author" name="author" /><br />
            <input type="submit" value="P O S T"/><br />
            <input type="reset" value="reset"/><br />
        </form>
    </div>
</body>
</html>

please help me, I copied allmost everything to be shure I am not ignoring something,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:07:30+00:00Added an answer on May 26, 2026 at 11:07 pm

    Ok, lets start by clearing up your code. Instead of having to create each independent variable in your if ($_SESSION['admin'] == 'loged') method, you can use the function extract();. The extract() method creates a variable for each key in the provided array. Say you have the key name in the array $_POST, the extract method will create a variable named name for you. To retrieve the value, all you need to do is access the variable $name.

    if ($_SESSION['admin'] == 'loged'){
    
        extract($_POST);
    
    }
    

    Secondly, you don’t use the word and if you want to check more than one thing in an if statement, you use the following operand ‘&&’.

    if (isset($_POST['title']) && isset($_POST['main-poster']) && isset($_POST['type']) && isset($_POST['year']) && isset($_POST['language']) && isset($_POST['platform']) && isset($_POST['publisher']) && isset($_POST['size']) && isset($_POST['graphics']) && isset($_POST['little-info']) && isset($_POST['full-info']) && isset($_POST['posters']) && isset($_POST['screenshots']) && isset($_POST['trailers']) && isset($_POST['gameplays']) && isset($_POST['author']))
    

    Instead of manually checking to see if each object has been set in the $_POST array, you can just iterate through $_POST.

    Create an array of the variables that you need to be set:

    $req_fields = array(
    
        'title', 
        'main-poster', 
        'type', 
        'year', 
        'language', 
        'platform', 
        'publisher', 
        'size', 
        'graphics', 
        'little-info', 
        'full-info', 
        'posters', 
        'screenshots', 
        'trailers', 
        'gameplays', 
        'author'
    
    );
    

    Then create an array for the elements that haven’t been set:

    $notset = array();
    

    Finally, iterate through $_POST checking to see if each value is set. If not, add it to the array.

    foreach ($req_fields as $key) {
    
        if (!isset($_POST[$key]) {
    
            $notset[] = $key;
    
        }
    }
    

    Then check to see if any values have not been set and redirect the user, else, load the model and echo the post:

    if (count($notset) > 0) {
    
        $this->load->view('postnews');
    
    }
    else {
    
        $this->load->model('Gamesmodel');
        echo $this->Gamesmodel->PostArticle($title, $main_poster, $type, $year, $language, $platform, $publisher, $size, $graphics, $little_info, $full_info, $posters, $screenshots, $trailers, $gameplays, $autor, $date);
    
    }
    

    Presumably the actual reason behind the insert not working is because it isn’t actually called. The reason behind this would be that some of the keys were not actually set.

    Iterate through the $notset array to see if this is the case:

    foreach ($notset as $unsetField) {
    
        echo "Field {$unsetField} is not set. <br />";
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a noob question, but can't find an answer anywhere. I have
Stupid nHibernate noob question, but I can't find the answer anywhere ... I have
I have this (noob?) question, but i just can't figure it out for many
Please enlighten this flex noob. I have a remoteobject within my main.mxml. I can
Noob dumb question, no doubt -- but here it is: Trying to tutorialize myself
This should be simple but I'm a noob and I can't for the life
I have a noob question =P How can I programatically add a canvas to
Being a noob ... I can't quite figure out what isn't working here ....
This is probably a noob question, but I can't seem to find the answer.
I've been searching for a while now, but php-noob as I am, can't get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.