Welcome Guest, Not a member yet? Register   Sign In
How can insert this into the databse after checking with fopen
#1

[eluser]phantom-a[/eluser]
This is controller that handles a form submission with one field. a field called "url"
I use fopen to check if the url the person submitted is valid, then I want insert it into a table called "links" into a field called "submitted_url".

How can this be done? I have already the function working except missing the databse part where it inserts it into the table if its a valid url.

Code:
function submit()
    {
        // Get the submit url
        $submission_url = $this->input->post('url');
        //check if it a real url
        $check_url = @fopen($submission_url,'r');
        @fclose($check_url); //close it now
//was the url valid?
        if($check_url !== false){
        $data['message'] = "Success!";
    //missing function here to insert $submission_url into database    
        $this->load->view('message_form', $data);
    }else{
    //nice try
      $data['message'] = "That Url doesn't exist!";
      $this->load->view('message_form', $data);
     }
  }
#2

[eluser]Sumon[/eluser]
Use a model
Code:
class url_model extends Model{
function insert_links($url)
{
  $data = array('submitted_url' => $url);
  $this->db->insert('links', $data);
  return true;
}
}

and use this model in your controller

Code:
function submit()
    {
        // Get the submit url
        $submission_url = $this->input->post('url');
        //check if it a real url
        $check_url = @fopen($submission_url,'r');
        @fclose($check_url); //close it now
//was the url valid?
        if($check_url !== false){
        $data['message'] = "Success!";
        $this->load->model('url_model');
        $this->url_model->insert_links($submission_url);
        $this->load->view('message_form', $data);
    }else{
    //nice try
      $data['message'] = "That Url doesn't exist!";
      $this->load->view('message_form', $data);
     }
  }
#3

[eluser]phantom-a[/eluser]
That works! Thanks for example.
#4

[eluser]phantom-a[/eluser]
eh just a thought is there security risks with fopen? I know "r" on it means readonly, but still What if someone submitted

http://example.com/trojan.exe

would my server download a virus?




Theme © iAndrew 2016 - Forum software by © MyBB