$_POST problem |
[eluser]lampard789[/eluser]
Hello, I am new to CI. I have a problem with $_POST. In my view I created a form Code: <form action="<?=base_url()?>/portal/search/" method="post" > And in my controller: Code: function search() { The result is an error as below: Quote:A PHP Error was encountered I tried this in my local environment and it worked well. But when I uploaded it into my hosting, this error pops up. I'm wondering what is going wrong there. Thanks!
[eluser]zimco[/eluser]
When you uploaded to your host did you remember to change the base_url in the config file? Code: $config['base_url'] = "http://yourhost.com/";
[eluser]Colin Williams[/eluser]
Perhaps your hosting does something weird and renames or disables the $_POST variable. Read through their docs. You can check in your code too: Code: if (isset($_POST)) Also, I recommend using CI's Input library and use $this->input->post()
[eluser]lampard789[/eluser]
[quote author="zimco" date="1215227904"]When you uploaded to your host did you remember to change the base_url in the config file? Code: $config['base_url'] = "http://yourhost.com/"; Yeah I changed it already. The rest of my script seems to work fine.
[eluser]lampard789[/eluser]
[quote author="Colin Williams" date="1215229152"]Perhaps your hosting does something weird and renames or disables the $_POST variable. Read through their docs. You can check in your code too: Code: if (isset($_POST)) Also, I recommend using CI's Input library and use $this->input->post()[/quote] I am not sure about my hosting, but when not using CI, all the POST vars work well. Only when using CI this error occurs. I tried your code and the output is: Code: Array Any idea what might be wrong?
[eluser]Carl_A[/eluser]
[quote author="lampard789" date="1215222780"] Code: <form action="<?=base_url()?>/portal/search/" method="post" > I tried this in my local environment and it worked well. But when I uploaded it into my hosting, this error pops up. I'm wondering what is going wrong there. Thanks![/quote] I had a similar problem.. it was because my hosting server didnt recognize the alternative php syntax.. Code: <form action="<?php echo base_url()?>/portal/search/" method="post" > You might want to try the CI way of doing it, with the form_helper. Makes these sort of errors disappear might work for you too..
[eluser]lampard789[/eluser]
[quote author="Carl_A" date="1215242874"] I had a similar problem.. it was because my hosting server didnt recognize the alternative php syntax.. Code: <form action="<?php echo base_url()?>/portal/search/" method="post" > You might want to try the CI way of doing it, with the form_helper. Makes these sort of errors disappear might work for you too..[/quote] Actually i tried both that way and the CI form-helper way. It still doesn't work. I really don't know what's wrong with my simple code :blank:
[eluser]charlie spider[/eluser]
let's see some more of your controller side note: if you have your base url written as such: $config['base_url'] = "http://yourhost.com/"; then you should remove a forward slash from this: <form action="<?php echo base_url()?>/portal/search/" method="post" > and make it this: <form action="<?php echo base_url()?>portal/search/" method="post" > otherwise your url will end up being: http://yourhost.com//portal/search/ shouldn't affect anything, but i just think it looks ugly :\
[eluser]lampard789[/eluser]
[quote author="charlie spider" date="1215257912"]let's see some more of your controller side note: if you have your base url written as such: $config['base_url'] = "http://yourhost.com/"; then you should remove a forward slash from this: <form action="<?php echo base_url()?>/portal/search/" method="post" > and make it this: <form action="<?php echo base_url()?>portal/search/" method="post" > otherwise your url will end up being: http://yourhost.com//portal/search/ shouldn't affect anything, but i just think it looks ugly :\[/quote] Ah yeah i should remove that slash! thx ;-) So here is my original controller (some are not yet completed): Code: class Portal extends Controller {
[eluser]Derek Jones[/eluser]
Do you have any .htaccess in play? If you are doing a rewrite that redirects or a regular redirect, you will lose POST data between page requests. |
Welcome Guest, Not a member yet? Register Sign In |