![]() |
referencing a $_POST in the controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: referencing a $_POST in the controller (/showthread.php?tid=4463) |
referencing a $_POST in the controller - El Forum - 11-26-2007 [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 referencing a $_POST in the controller - El Forum - 11-26-2007 [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. referencing a $_POST in the controller - El Forum - 11-26-2007 [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>'; referencing a $_POST in the controller - El Forum - 11-26-2007 [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'"; |