Welcome Guest, Not a member yet? Register   Sign In
Beginner needs help with form
#1

[eluser]Glowfox[/eluser]
Hi there guys! I am a beginner to CodeIgniter but I have years experience with PHP. I am honestly completely confused. I purchase a user login system from CodeCanyon called Uzy. It uses CodeIgniter as a framework. I was hoping it would help make my current PHP website more secure than before, but it has honestly been the biggest headache trying to re-write all my old PHP scripts to work with CodeIgniter because I have zero CodeIgniter experience. I am almost ready to switch back to my old system and just leave it at that.

I have tried watching tutorials and reading up on it, but because I used this premade user login system, everything looks different in the tutorials. I just cannot seem to wrap my head around how to make it work, but I know it is probably some really stupid mistake I made somewhere.

My current problem is I have been working on this form for a week now and I cannot get in touch with the person who created the user login system to ask them for help. I wonder if anyone could help me with this because I have tried everything I can possibly think of. I believe the issue is with my model page, but I cannot find the error because of my lack of experience.

The form is supposed to just add new data to a section in the database called "pets". Instead it is putting all the form data into the URL of the website when I hit the submit button. I also have some Javascript which is supposed to check to see if the pet's registered name is already taken. It is supposed to check if "rname" is already matched in the database. Instead when I hit the button it does nothing.

My thoughts are after playing with it to try to fix it is the system is not connecting to the "pets" section of the database at all for some reason. It connects to the "users" section on the same database fine though.

Any suggestions or help someone could give me would be great at this point. I am clueless as to what to do. If anyone has some tutorials I could read also that would hopefully make sense to me, that would great.

Here is the controller page called adopt.php:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Adopt extends CI_Controller
{

public function __construct()
{
  parent::__construct();
  $this->load->model("adopt_model");
  $this->load->model("ip_model");
  if (!$this->user->loggedin) {
   $this->template->error(
    lang("error_1")
   );
  }
}

public function index()
{
if ($this->settings->info->adopt) {
   $this->template->error(lang("error_87"));
  }
  $this->template->loadExternal(
   '[removed][removed]'
                        
  );
                
                  $this->template->loadExternal(
   '[removed][removed]'
                        
  );
                



  // IP Block check
  if ($this->ip_model->checkIpIsBlocked($_SERVER['REMOTE_ADDR'])) {
   $this->template->error(
    lang("error_11")
   );
  }
  
  

  $rname = "";
  $name = "";
  $gender = "";
  $breed = "";
  $color = "";
  $mark = "";
                $fail = "";

  if (isset($_POST['s'])) {
   $rname = $this->input->post("rname", true);
   $name = $this->common->nohtml(
    $this->input->post("name", true));
                 $gender = intval($this->input->post("gender", true));
   $breed = intval($this->input->post("breed", true));
   $color = intval($this->input->post("color", true));
                        $mark = intval($this->input->post("mark", true));
   $captcha = $this->input->post("captcha", true);
  


   if(strlen($rname) < 3) $fail = lang("ctn_113");

   if(!preg_match("/^[a-z0-9_]+$/i", $rname)) $fail = lang("ctn_114");

   if(!$this->adopt_model->check_rname_is_free($rname)) $fail = lang("ctn_115");

   if ($captcha != $_SESSION['sc']) {
    $fail = lang("error_2");
   }


   if (strlen($rname) > 200) {
    $fail = lang("error_50");
   }

   if (empty($rname)) $fail = lang("error_53");

   if (empty($name)) {
    $fail = lang("error_51");
   }
                        if (empty($fail)) {
    // Passed all checks
    
    $this->adopt_model->registerUser(
     $rname, $name, $gender, $breed, $color, $mark
    );
    $this->session->set_flashdata("globalmsg", lang("success_14"));
    redirect(base_url("kennel"));
   }
  }


  $this->load->helper("captcha");
  $rand = rand(4000,100000);
  $_SESSION['sc'] = $rand;
  $vals = array(
      'word' => $rand,
      'img_path' => './images/captcha/',
      'img_url' => base_url() . 'images/captcha/',
      'img_width' => 150,
      'img_height' => 30,
      'expiration' => 7200
      );

  $cap = create_captcha($vals);
  $this->template->loadContent("adopt/index.php", array(
   "cap" => $cap,
   "rname" => $rname,
   "name" => $name,
   "gender" => $gender,
   "breed" => $breed,
   "color" => $color,
   "mark" => $mark,
      'fail' => $fail));
    
}
}

Here is the model called adopt_model.php:

Code:
&lt;?php

class Adopt_Model extends CI_Model
{

public function registerUser($name, $rname, $gender, $breed, $color,
$mark
) {
  $this->db->insert("pets",
   array(
    "name" => $name,
    "rname" => $rname,
    "gender" => $gender,
    "breed" => $breed,
    "color" => $color,
    "mark" => $mark
    
   )
  );
}



public function check_rname_is_free($rname) {
  $s=$this->db->where("rname", $rname)->get("pets");
  if($s->num_rows() > 0) {
   return false;
  } else {
   return true;
  }
}

public function add_rname($userid, $rname) {
  $this->db->where("ownerid", $userid)->update("pets", array("rname" => $rname));
}

}

?&gt;



Messages In This Thread
Beginner needs help with form - by El Forum - 07-24-2014, 05:12 AM
Beginner needs help with form - by El Forum - 07-24-2014, 07:13 AM
Beginner needs help with form - by El Forum - 07-24-2014, 07:37 AM
Beginner needs help with form - by El Forum - 07-24-2014, 10:11 AM
Beginner needs help with form - by El Forum - 07-24-2014, 01:14 PM
Beginner needs help with form - by El Forum - 07-24-2014, 01:39 PM
Beginner needs help with form - by El Forum - 07-24-2014, 01:44 PM
Beginner needs help with form - by El Forum - 07-25-2014, 08:10 AM
Beginner needs help with form - by El Forum - 07-25-2014, 08:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB