Welcome Guest, Not a member yet? Register   Sign In
referencing a $_POST in the controller
#1

[eluser]dgriffter[/eluser]
Hi,

I?m getting an error of undefined index when I try to select from my database using a $_POST variable.

The code in the controller is:

function search(){
$reference = $this->session->userdata($_POST['reference']);
$data['session_id']=$reference ;
$data['query4']= $this->db->query('SELECT * FROM product WHERE idreference="'.$reference.'"');
$this->load->view('search', $data);
}

My code in the form in the view file is:

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" name="reference" value="">
<input type="submit" name="Search" value="Search" />
</form>


Can someone please tell me where I'm going wrong, it's been driving me wild for ages...

Many thanks in advance...

Dgriffter
#2

[eluser]Michael Wales[/eluser]
Try using the input class and see if you get a value

I know when the validation class is used the $_POST array repopulated with the filtered and validated data - not sure when the validation class is not used.
#3

[eluser]wakextreme[/eluser]
[quote author="dgriffter" date="1196136425"]Hi,

I?m getting an error of undefined index when I try to select from my database using a $_POST variable.

The code in the controller is:

function search(){
$reference = $this->session->userdata($_POST['reference']);
$data['session_id']=$reference ;
$data['query4']= $this->db->query('SELECT * FROM product WHERE idreference="'.$reference.'"');
$this->load->view('search', $data);
}

My code in the form in the view file is:

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" name="reference" value="">
<input type="submit" name="Search" value="Search" />
</form>


Can someone please tell me where I'm going wrong, it's been driving me wild for ages...

Many thanks in advance...

Dgriffter[/quote]

I would try dumping out the contents of $_POST to ensure your data is coming through as expected and if it is then test the value of $reference.

Code:
echo '<pre>'; print_r($_POST); echo '</pre>';
#4

[eluser]Rick Jolly[/eluser]
Double quotes around $reference in your sql is invalid. Query bindings or active record is more elegant and safe. Or do this:
Code:
"SELECT * FROM product WHERE idreference='$reference'";




Theme © iAndrew 2016 - Forum software by © MyBB